Skip to content

Commit ef8e8e3

Browse files
authored
Merge pull request #14 from decksoftware/fix/clear-semgrep-warnings
fix(security): clear 2 Semgrep code-scanning warnings on csreview's own source
2 parents 6c3aec0 + c65c321 commit ef8e8e3

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

csreview/src/dumpGuide.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// detects which backends a project uses and renders an instructional HTML report.
66
import fs from 'fs';
77
import path from 'path';
8+
import { safeResolveInside } from './pathSafety.js';
89

910
function escapeHtml(value) {
1011
return String(value ?? '')
@@ -292,8 +293,11 @@ ${cards}
292293

293294
function readPackageDeps(rootDir) {
294295
try {
295-
const pkgPath = path.join(rootDir, 'package.json');
296-
if (!fs.existsSync(pkgPath)) return [];
296+
// Contained resolution (rejects traversal / absolute escapes) instead of a
297+
// raw path.join — the joined component is a constant, but this keeps the
298+
// codebase's read-only safe-path invariant and clears the scanner warning.
299+
const pkgPath = safeResolveInside(rootDir, 'package.json');
300+
if (!pkgPath || !fs.existsSync(pkgPath)) return [];
297301
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
298302
return Object.keys({
299303
...(pkg.dependencies || {}),

csreview/src/ignore.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ export function patternToMatcher(rawPattern) {
9898
const body = translateGlob(pattern);
9999
const prefix = anchored || hasSlash ? '^' : '(?:^|.*/)';
100100
const suffix = dirOnly ? '(?:/.*)?$' : '$';
101-
return { negate, re: new RegExp(prefix + body + suffix) };
101+
// ReDoS-hardened dynamic RegExp: globstar runs are collapsed and patterns with
102+
// >100 wildcards are refused above; the input is a sanitized glob from the
103+
// user's own .csreview-ignore or built-in defaults (a local dev tool), and the
104+
// behaviour is unit-tested (ignore.test.js "ReDoS H1"). The dynamic RegExp is
105+
// intrinsic to a glob matcher, so this audit finding is suppressed inline.
106+
return { negate, re: new RegExp(prefix + body + suffix) }; // nosemgrep: javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp
102107
}
103108

104109
/**

0 commit comments

Comments
 (0)