Skip to content

Commit 3b57951

Browse files
applied code suggestions
1 parent 0a9ab78 commit 3b57951

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

danger/dangerfile.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,17 @@ 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 fs = require('fs');
200+
const customPath = path.join(workspaceDir, extraDangerFilePath);
201+
// Ensure the resolved path is within workspace
202+
const resolvedPath = fs.realpathSync(customPath);
203+
if (!resolvedPath.startsWith(workspaceDir)) {
204+
fail(`Invalid dangerfile path: ${extraDangerFilePath}. Must be within workspace.`);
201205
return;
202206
}
203-
207+
204208
const extraModule = require(customPath);
205209
if (typeof extraModule !== 'function') {
206210
warn(`EXTRA_DANGERFILE must export a function at ${customPath}`);

0 commit comments

Comments
 (0)