mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-20 23:40:38 +01:00
fix: translator path traversal
This commit is contained in:
@@ -13,7 +13,11 @@ const files = fs.readdirSync(path.join(paths.nodeModules, '/timeago/locales'));
|
|||||||
Languages.timeagoCodes = files.filter(f => f.startsWith('jquery.timeago')).map(f => f.split('.')[2]);
|
Languages.timeagoCodes = files.filter(f => f.startsWith('jquery.timeago')).map(f => f.split('.')[2]);
|
||||||
|
|
||||||
Languages.get = async function (language, namespace) {
|
Languages.get = async function (language, namespace) {
|
||||||
const data = await fs.promises.readFile(path.join(languagesPath, language, `${namespace}.json`), 'utf8');
|
const pathToLanguageFile = path.join(languagesPath, language, `${namespace}.json`);
|
||||||
|
if (!pathToLanguageFile.startsWith(languagesPath)) {
|
||||||
|
throw new Error('[[error:invalid-path]]');
|
||||||
|
}
|
||||||
|
const data = await fs.promises.readFile(pathToLanguageFile, 'utf8');
|
||||||
const parsed = JSON.parse(data) || {};
|
const parsed = JSON.parse(data) || {};
|
||||||
const result = await plugins.hooks.fire('filter:languages.get', {
|
const result = await plugins.hooks.fire('filter:languages.get', {
|
||||||
language,
|
language,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ describe('Translator shim', () => {
|
|||||||
const translated = await shim.translate('', 'en-GB');
|
const translated = await shim.translate('', 'en-GB');
|
||||||
assert.strictEqual(translated, '');
|
assert.strictEqual(translated, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not allow path traversal', async () => {
|
||||||
|
const t = await shim.translate('[[../../../../config:secret]]');
|
||||||
|
assert.strictEqual(t, 'secret');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user