[IMPROVE] Webdav methods sanitization (#23924)
parent
9160ba13c2
commit
160619d2ac
@ -1,32 +1,34 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { settings } from '../../../settings'; |
||||
import { settings } from '../../../settings/server'; |
||||
import { getWebdavCredentials } from './getWebdavCredentials'; |
||||
import { WebdavAccounts } from '../../../models/server/raw'; |
||||
import { WebdavClientAdapter } from '../lib/webdavClientAdapter'; |
||||
|
||||
Meteor.methods({ |
||||
async getFileFromWebdav(accountId, file) { |
||||
if (!Meteor.userId()) { |
||||
const userId = Meteor.userId(); |
||||
|
||||
if (!userId) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid User', { method: 'getFileFromWebdav' }); |
||||
} |
||||
if (!settings.get('Webdav_Integration_Enabled')) { |
||||
throw new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', { method: 'getFileFromWebdav' }); |
||||
} |
||||
|
||||
const account = await WebdavAccounts.findOneByIdAndUserId(accountId, Meteor.userId()); |
||||
const account = await WebdavAccounts.findOneByIdAndUserId(accountId, userId, {}); |
||||
if (!account) { |
||||
throw new Meteor.Error('error-invalid-account', 'Invalid WebDAV Account', { method: 'getFileFromWebdav' }); |
||||
} |
||||
|
||||
try { |
||||
const cred = getWebdavCredentials(account); |
||||
const client = new WebdavClientAdapter(account.server_url, cred); |
||||
const client = new WebdavClientAdapter(account.serverURL, cred); |
||||
const fileContent = await client.getFileContents(file.filename); |
||||
const data = new Uint8Array(fileContent); |
||||
return { success: true, data }; |
||||
} catch (error) { |
||||
throw new Meteor.Error('unable-to-get-file', { method: 'getFileFromWebdav' }); |
||||
throw new Meteor.Error('unable-to-get-file', 'Unable to get file', { method: 'getFileFromWebdav' }); |
||||
} |
||||
}, |
||||
}); |
@ -1,9 +1,11 @@ |
||||
import { IRocketChatRecord } from './IRocketChatRecord'; |
||||
|
||||
export interface IWebdavAccount extends IRocketChatRecord { |
||||
user_id: string; |
||||
server_url: string; |
||||
userId: string; |
||||
serverURL: string; |
||||
username: string; |
||||
password: string; |
||||
name: string; |
||||
} |
||||
|
||||
export type IWebdavAccountPayload = Omit<IWebdavAccount, 'userId' | '_id' | '_updatedAt'> |
||||
|
@ -0,0 +1,10 @@ |
||||
import { addMigration } from '../../lib/migrations'; |
||||
import { WebdavAccounts } from '../../../app/models/server/raw'; |
||||
|
||||
addMigration({ |
||||
version: 251, |
||||
async up() { |
||||
// eslint-disable-next-line quote-props
|
||||
await WebdavAccounts.updateMany({}, { $rename: { 'user_id': 'userId', 'server_url': 'serverURL' } }); |
||||
}, |
||||
}); |
Loading…
Reference in new issue