Skip to content

Commit 2cc1eb3

Browse files
code ref fix / simplified transversal check
1 parent 8c62a42 commit 2cc1eb3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

danger/dangerfile.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,13 @@ async function CheckFromExternalChecks() {
193193
console.log(`::debug:: Checking from external checks: ${extraDangerFilePath}`);
194194
if (extraDangerFilePath) {
195195
try {
196-
const workspaceDir = '/github/workspace';
197-
const path = require('path');
198-
const customPath = path.join('/github/workspace', extraDangerFilePath);
199-
200-
if (!customPath.startsWith(workspaceDir)) {
196+
if (extraDangerFilePath.contains(workspaceDir)) {
201197
fail(`Invalid dangerfile path: ${customPath}. Path traversal is not allowed.`);
202198
return;
203199
}
200+
201+
const workspaceDir = '/github/workspace';
202+
const customPath = `${workspaceDir}${extraDangerFilePath}`;
204203

205204
const extraModule = require(customPath);
206205
if (typeof extraModule !== 'function') {
@@ -216,7 +215,7 @@ async function CheckFromExternalChecks() {
216215
});
217216
} catch (err) {
218217
if (err.message && err.message.includes('Cannot use import statement outside a module')) {
219-
warn(`External dangerfile uses ES6 imports. Please convert to CommonJS syntax (require/module.exports) or use .mjs extension with proper module configuration.\nFile: ${customPath}`);
218+
warn(`External dangerfile uses ES6 imports. Please convert to CommonJS syntax (require/module.exports) or use .mjs extension with proper module configuration.\nFile: ${extraDangerFilePath}`);
220219
} else {
221220
warn(`Could not load custom Dangerfile: ${extraDangerFilePath}\n${err}`);
222221
}

0 commit comments

Comments
 (0)