File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55// detects which backends a project uses and renders an instructional HTML report.
66import fs from 'fs' ;
77import path from 'path' ;
8+ import { safeResolveInside } from './pathSafety.js' ;
89
910function escapeHtml ( value ) {
1011 return String ( value ?? '' )
@@ -292,8 +293,11 @@ ${cards}
292293
293294function 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 || { } ) ,
Original file line number Diff line number Diff 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/**
You can’t perform that action at this time.
0 commit comments