fix(core): Do not allow arbitrary path traversal in the credential-translation endpoint (#5522)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-02-21 11:21:04 +01:00
committed by GitHub
parent 26a20ed47e
commit f0f8d59fee
6 changed files with 103 additions and 59 deletions

View File

@@ -57,7 +57,6 @@ import history from 'connect-history-api-fallback';
import config from '@/config';
import * as Queue from '@/Queue';
import { InternalHooksManager } from '@/InternalHooksManager';
import { getCredentialTranslationPath } from '@/TranslationHelpers';
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
import { nodesController } from '@/api/nodes.api';
@@ -88,6 +87,7 @@ import {
MeController,
OwnerController,
PasswordResetController,
TranslationController,
UsersController,
} from '@/controllers';
@@ -366,6 +366,7 @@ class Server extends AbstractServer {
new OwnerController({ config, internalHooks, repositories, logger }),
new MeController({ externalHooks, internalHooks, repositories, logger }),
new PasswordResetController({ config, externalHooks, internalHooks, repositories, logger }),
new TranslationController(config, this.credentialTypes),
new UsersController({
config,
mailer,
@@ -606,48 +607,6 @@ class Server extends AbstractServer {
),
);
this.app.get(
`/${this.restEndpoint}/credential-translation`,
ResponseHelper.send(
async (
req: express.Request & { query: { credentialType: string } },
res: express.Response,
): Promise<object | null> => {
const translationPath = getCredentialTranslationPath({
locale: this.frontendSettings.defaultLocale,
credentialType: req.query.credentialType,
});
try {
return require(translationPath);
} catch (error) {
return null;
}
},
),
);
// Returns node information based on node names and versions
const headersPath = pathJoin(NODES_BASE_DIR, 'dist', 'nodes', 'headers');
this.app.get(
`/${this.restEndpoint}/node-translation-headers`,
ResponseHelper.send(
async (req: express.Request, res: express.Response): Promise<object | void> => {
try {
await fsAccess(`${headersPath}.js`);
} catch (_) {
return; // no headers available
}
try {
return require(headersPath);
} catch (error) {
res.status(500).send('Failed to load headers file');
}
},
),
);
// ----------------------------------------
// Node-Types
// ----------------------------------------