Skip to content

Commit cee33c8

Browse files
apply code suggestoin
1 parent 0a9ab78 commit cee33c8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

danger/dangerfile.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,16 @@ async function checkFromExternalChecks() {
194194
if (extraDangerFilePath) {
195195
try {
196196
const workspaceDir = '/github/workspace';
197-
const customPath = `${workspaceDir}/${extraDangerFilePath}`;
198197

199-
if (extraDangerFilePath.indexOf('..') !== -1) {
200-
fail(`Invalid dangerfile path: ${customPath}. Path traversal is not allowed.`);
198+
const path = require('path');
199+
const customPath = path.join(workspaceDir, extraDangerFilePath);
200+
// Ensure the resolved path is within workspace
201+
const resolvedPath = fs.realpathSync(customPath);
202+
if (!resolvedPath.startsWith(workspaceDir)) {
203+
fail(`Invalid dangerfile path: ${extraDangerFilePath}. Must be within workspace.`);
201204
return;
202205
}
203-
206+
204207
const extraModule = require(customPath);
205208
if (typeof extraModule !== 'function') {
206209
warn(`EXTRA_DANGERFILE must export a function at ${customPath}`);

0 commit comments

Comments
 (0)