circle-ir 4.18.1 → 4.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analysis/advisories.d.ts +21 -3
- package/dist/analysis/advisories.d.ts.map +1 -1
- package/dist/analysis/advisories.js +26 -8
- package/dist/analysis/advisories.js.map +1 -1
- package/dist/analysis/arg-executing-programs.d.ts +16 -0
- package/dist/analysis/arg-executing-programs.d.ts.map +1 -0
- package/dist/analysis/arg-executing-programs.js +24 -0
- package/dist/analysis/arg-executing-programs.js.map +1 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +32 -23
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-caller-gate.d.ts +3 -1
- package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
- package/dist/analysis/constant-caller-gate.js +108 -1
- package/dist/analysis/constant-caller-gate.js.map +1 -1
- package/dist/analysis/constant-propagation/index.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/index.js +1 -1
- package/dist/analysis/constant-propagation/index.js.map +1 -1
- package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/patterns.js +5 -0
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +15 -1
- package/dist/analysis/constant-propagation/propagator.js.map +1 -1
- package/dist/analysis/constant-propagation/types.d.ts +2 -0
- package/dist/analysis/constant-propagation/types.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.d.ts +33 -0
- package/dist/analysis/dependency-versions.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.js +70 -0
- package/dist/analysis/dependency-versions.js.map +1 -1
- package/dist/analysis/interprocedural.d.ts +6 -0
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +53 -6
- package/dist/analysis/interprocedural.js.map +1 -1
- package/dist/analysis/js-helper-return.d.ts +12 -0
- package/dist/analysis/js-helper-return.d.ts.map +1 -0
- package/dist/analysis/js-helper-return.js +64 -0
- package/dist/analysis/js-helper-return.js.map +1 -0
- package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.js +1 -0
- package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cross-file-pass.js +61 -0
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js +60 -3
- package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts +15 -0
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js +60 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts +23 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +148 -6
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +150 -7
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.js +20 -4
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +229 -8
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts +7 -3
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +176 -15
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.d.ts.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.js +50 -6
- package/dist/analysis/passes/xml-entity-expansion-pass.js.map +1 -1
- package/dist/analysis/pep440-version.d.ts +40 -0
- package/dist/analysis/pep440-version.d.ts.map +1 -0
- package/dist/analysis/pep440-version.js +149 -0
- package/dist/analysis/pep440-version.js.map +1 -0
- package/dist/analysis/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +6 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +43 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +265 -33
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +107 -5
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analyzer.d.ts +6 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +27 -1
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +3379 -101
- package/dist/core/circle-ir-core.cjs +218 -35
- package/dist/core/circle-ir-core.js +218 -35
- package/dist/core/extractors/dfg.js +46 -7
- package/dist/core/extractors/dfg.js.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.d.ts +8 -0
- package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.js +22 -0
- package/dist/core/extractors/ts-declaration-detail.js.map +1 -1
- package/dist/facts/arrow.d.ts +106 -0
- package/dist/facts/arrow.d.ts.map +1 -0
- package/dist/facts/arrow.js +196 -0
- package/dist/facts/arrow.js.map +1 -0
- package/dist/facts/facts2.d.ts +59 -0
- package/dist/facts/facts2.d.ts.map +1 -0
- package/dist/facts/facts2.js +362 -0
- package/dist/facts/facts2.js.map +1 -0
- package/dist/facts/index.d.ts +20 -0
- package/dist/facts/index.d.ts.map +1 -0
- package/dist/facts/index.js +14 -0
- package/dist/facts/index.js.map +1 -0
- package/dist/facts/java-facts.d.ts +56 -0
- package/dist/facts/java-facts.d.ts.map +1 -0
- package/dist/facts/java-facts.js +250 -0
- package/dist/facts/java-facts.js.map +1 -0
- package/dist/facts/order.d.ts +39 -0
- package/dist/facts/order.d.ts.map +1 -0
- package/dist/facts/order.js +120 -0
- package/dist/facts/order.js.map +1 -0
- package/dist/facts/schema.d.ts +60 -0
- package/dist/facts/schema.d.ts.map +1 -0
- package/dist/facts/schema.js +126 -0
- package/dist/facts/schema.js.map +1 -0
- package/dist/facts/schema2.d.ts +47 -0
- package/dist/facts/schema2.d.ts.map +1 -0
- package/dist/facts/schema2.js +194 -0
- package/dist/facts/schema2.js.map +1 -0
- package/dist/facts/table.d.ts +80 -0
- package/dist/facts/table.d.ts.map +1 -0
- package/dist/facts/table.js +548 -0
- package/dist/facts/table.js.map +1 -0
- package/dist/graph-facts/dead-code.d.ts +2 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -1
- package/dist/graph-facts/dead-code.js +1 -1
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/reach.d.ts +24 -6
- package/dist/graph-facts/reach.d.ts.map +1 -1
- package/dist/graph-facts/reach.js +52 -12
- package/dist/graph-facts/reach.js.map +1 -1
- package/dist/graph-facts/removal-reach.d.ts +2 -0
- package/dist/graph-facts/removal-reach.d.ts.map +1 -1
- package/dist/graph-facts/removal-reach.js +1 -1
- package/dist/graph-facts/removal-reach.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/navigation/java-graph.d.ts +23 -0
- package/dist/navigation/java-graph.d.ts.map +1 -1
- package/dist/navigation/java-graph.js +222 -8
- package/dist/navigation/java-graph.js.map +1 -1
- package/dist/navigation/navigation-index.d.ts +9 -0
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +25 -0
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +9 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/resolution/cross-file.d.ts +46 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +281 -13
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/files.d.ts +22 -0
- package/dist/stable-ids/files.d.ts.map +1 -0
- package/dist/stable-ids/files.js +28 -0
- package/dist/stable-ids/files.js.map +1 -0
- package/dist/stable-ids/hash.d.ts +16 -4
- package/dist/stable-ids/hash.d.ts.map +1 -1
- package/dist/stable-ids/hash.js +266 -80
- package/dist/stable-ids/hash.js.map +1 -1
- package/dist/stable-ids/index.d.ts +3 -2
- package/dist/stable-ids/index.d.ts.map +1 -1
- package/dist/stable-ids/index.js +3 -2
- package/dist/stable-ids/index.js.map +1 -1
- package/dist/stable-ids/nodes.d.ts +45 -1
- package/dist/stable-ids/nodes.d.ts.map +1 -1
- package/dist/stable-ids/nodes.js +118 -15
- package/dist/stable-ids/nodes.js.map +1 -1
- package/dist/stable-ids/ts-parse-errors.d.ts +5 -1
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
- package/dist/stable-ids/ts-parse-errors.js +35 -2
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/package.json +8 -4
- package/schemas/facts@1.json +134 -0
- package/schemas/facts@2.json +216 -0
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Depends on: taint-matcher, constant-propagation
|
|
15
15
|
*/
|
|
16
|
+
import { runsArgvAsCommand } from '../arg-executing-programs.js';
|
|
16
17
|
import { DOM_ASSIGNMENT_SINK_METHODS, isProvablyLiteralExpression, } from '../literal-expression.js';
|
|
17
18
|
import { attachSourceLineCode } from '../taint-matcher.js';
|
|
18
19
|
import { javaReplaceCrLfCoverage } from '../java-crlf-strip.js';
|
|
@@ -21,6 +22,7 @@ import { findGoStringsReplacerSanitizers } from '../go-strings-replacer.js';
|
|
|
21
22
|
import { findRustLiteralEqualityGuardSanitizers } from '../rust-literal-guard.js';
|
|
22
23
|
import { constLookupTables, isConstTableLookup } from '../const-table-lookup.js';
|
|
23
24
|
import { jsReplaceChainVerdict } from '../js-crlf-strip.js';
|
|
25
|
+
import { jsHelperReturnsNoParam } from '../js-helper-return.js';
|
|
24
26
|
// ---------------------------------------------------------------------------
|
|
25
27
|
// Pattern tables (moved from analyzer.ts)
|
|
26
28
|
// ---------------------------------------------------------------------------
|
|
@@ -490,6 +492,8 @@ export class LanguageSourcesPass {
|
|
|
490
492
|
additionalSanitizers.push(...findJsParameterizedSqlSanitizers(code));
|
|
491
493
|
// #223 REG-144-20: JS path.resolve/join + startsWith(root) guard.
|
|
492
494
|
additionalSanitizers.push(...findJsPathResolveStartsWithGuardSanitizers(code));
|
|
495
|
+
// cognium-dev#1146: same-file helper returns path.resolve after allow-list guard.
|
|
496
|
+
additionalSanitizers.push(...findJsPathAllowlistHelperSanitizers(code));
|
|
493
497
|
// #223 REG-144-17/18/19: JS/TS command allowlist guard
|
|
494
498
|
// (Set.has / Array.includes / indexOf) before execFile/spawn.
|
|
495
499
|
additionalSanitizers.push(...findJsCommandAllowlistGuardSanitizers(code));
|
|
@@ -2132,6 +2136,37 @@ function classifyCSharpLambdaParam(raw) {
|
|
|
2132
2136
|
return { type: 'http_param', name, via: 'string param' };
|
|
2133
2137
|
return null;
|
|
2134
2138
|
}
|
|
2139
|
+
/**
|
|
2140
|
+
* cognium-dev#1049 — an Express handler that destructures the request
|
|
2141
|
+
* (`({ query }: Request, res: Response) => { … query.to … }`, OWASP Juice Shop
|
|
2142
|
+
* `routes/redirect.ts`) reads `query.to`, which no `req.query` pattern matches.
|
|
2143
|
+
* When a parameter object pattern is typed `Request` (optionally
|
|
2144
|
+
* `express.Request`), each request field it binds — `query`, `params`, `body`,
|
|
2145
|
+
* `headers`, `cookies`, under its own name or a rename (`query: q`) — becomes a
|
|
2146
|
+
* source pattern for that binding.
|
|
2147
|
+
*/
|
|
2148
|
+
const REQUEST_FIELD_TYPES = {
|
|
2149
|
+
query: 'http_param', params: 'http_param', body: 'http_body', headers: 'http_header', cookies: 'http_cookie',
|
|
2150
|
+
};
|
|
2151
|
+
function destructuredRequestPatterns(sourceCode) {
|
|
2152
|
+
const out = [];
|
|
2153
|
+
const seen = new Set();
|
|
2154
|
+
for (const m of sourceCode.matchAll(/[(,]\s*\{([^{}]*)\}\s*:\s*(?:express\.)?Request\b/g)) {
|
|
2155
|
+
for (const part of m[1].split(',')) {
|
|
2156
|
+
const bind = /^\s*(\w+)\s*(?::\s*(\w+))?\s*(?:=[^,]*)?$/.exec(part);
|
|
2157
|
+
if (!bind)
|
|
2158
|
+
continue;
|
|
2159
|
+
const field = bind[1];
|
|
2160
|
+
const local = bind[2] ?? bind[1];
|
|
2161
|
+
const type = REQUEST_FIELD_TYPES[field];
|
|
2162
|
+
if (!type || seen.has(local))
|
|
2163
|
+
continue;
|
|
2164
|
+
seen.add(local);
|
|
2165
|
+
out.push({ pattern: new RegExp(`(?<![\\w.])${local}\\s*[.[]`), type });
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
return out;
|
|
2169
|
+
}
|
|
2135
2170
|
function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
2136
2171
|
if (!['javascript', 'typescript'].includes(language))
|
|
2137
2172
|
return [];
|
|
@@ -2147,7 +2182,8 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
|
2147
2182
|
&& /\{[^}]*\bparams\b[^}]*\}/.test(sourceCode);
|
|
2148
2183
|
const patterns = isRouteHandler
|
|
2149
2184
|
? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: 'http_path' }]
|
|
2150
|
-
: JS_TAINTED_PATTERNS;
|
|
2185
|
+
: [...JS_TAINTED_PATTERNS];
|
|
2186
|
+
patterns.push(...destructuredRequestPatterns(sourceCode));
|
|
2151
2187
|
// #667: `REGISTRY[req.query.mod]` on a constant table yields a value the
|
|
2152
2188
|
// program wrote, not request data.
|
|
2153
2189
|
const lookupTables = constLookupTables(sourceCode, language);
|
|
@@ -2182,6 +2218,12 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
|
2182
2218
|
}
|
|
2183
2219
|
if (isConstTableLookup(rhs, lookupTables))
|
|
2184
2220
|
continue;
|
|
2221
|
+
// #992: `v = pick(req.query.x)` where the same-file `pick` returns no
|
|
2222
|
+
// parameter (a literal, or a literal slot of a local array) — the request
|
|
2223
|
+
// value goes in but never comes out.
|
|
2224
|
+
const wholeCall = /^\s*([A-Za-z_$][\w$]*)\s*\(.*\)\s*;?\s*$/.exec(rhs);
|
|
2225
|
+
if (wholeCall && jsHelperReturnsNoParam(sourceCode, wholeCall[1]))
|
|
2226
|
+
continue;
|
|
2185
2227
|
for (const { pattern, type } of patterns) {
|
|
2186
2228
|
if (pattern.test(rhs)) {
|
|
2187
2229
|
const alreadyExists = sources.some(s => s.line === lineNumber && s.type === type && s.variable === varName);
|
|
@@ -4264,11 +4306,12 @@ options) {
|
|
|
4264
4306
|
const derived = new Map();
|
|
4265
4307
|
const knownTainted = new Set(seedVars);
|
|
4266
4308
|
const trackSlots = options?.trackSlots === true;
|
|
4267
|
-
//
|
|
4268
|
-
//
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4309
|
+
// Read `x = list.get(0); // note` as the statement it is: the assignment
|
|
4310
|
+
// patterns below are anchored at `;`. Every mode strips, not only slot mode
|
|
4311
|
+
// (#1105): a trailing comment hid the list read in OWASP BenchmarkTest00575.
|
|
4312
|
+
// Precision for safe slots (`get(1)` after `remove(0)`) still comes from
|
|
4313
|
+
// const-prop's list model, which vetoes the derived alias downstream.
|
|
4314
|
+
const lines = sourceCode.split('\n').map(stripJavaTrailingLineComment);
|
|
4272
4315
|
const dead = deadBranchLines ?? new Set();
|
|
4273
4316
|
/** list var → element slots: the added identifier, or `null` for a literal. */
|
|
4274
4317
|
const listElems = new Map();
|
|
@@ -7372,7 +7415,9 @@ function findJsSsrfAllowlistGuardSanitizers(code) {
|
|
|
7372
7415
|
* cannot smuggle shell metacharacters into a separate command.
|
|
7373
7416
|
*
|
|
7374
7417
|
* The shell-via-argv form `execFile('sh', ['-c', tainted])` is excluded
|
|
7375
|
-
* since `-c` re-enables shell parsing of the subsequent argv slot
|
|
7418
|
+
* since `-c` re-enables shell parsing of the subsequent argv slot, and so is
|
|
7419
|
+
* a program that runs its argv as a command (`ssh`, `sudo`, `docker`, …;
|
|
7420
|
+
* cognium-dev#1066). A
|
|
7376
7421
|
* tainted-program slot `execFile(prog, [arg])` is NOT matched (TP-2
|
|
7377
7422
|
* control), nor is the single-string `exec("cmd " + arg)` form (TP-1
|
|
7378
7423
|
* control — `exec` itself spawns a shell regardless).
|
|
@@ -7395,6 +7440,10 @@ function findJsArgvFormExecSanitizers(code) {
|
|
|
7395
7440
|
continue;
|
|
7396
7441
|
if (shellArgvRe.test(text))
|
|
7397
7442
|
continue;
|
|
7443
|
+
// #1066: ssh / sudo / docker / xargs / … run their argv as a command.
|
|
7444
|
+
const prog = /\b(?:execFile|spawn)(?:Sync)?\s*\(\s*(['"`])([^'"`]*)\1/.exec(text);
|
|
7445
|
+
if (prog && runsArgvAsCommand(prog[2]))
|
|
7446
|
+
continue;
|
|
7398
7447
|
sanitizers.push({
|
|
7399
7448
|
type: 'js_argv_form_exec',
|
|
7400
7449
|
method: 'execFile',
|
|
@@ -7545,6 +7594,100 @@ function findJsPathResolveStartsWithGuardSanitizers(code) {
|
|
|
7545
7594
|
}
|
|
7546
7595
|
return sanitizers;
|
|
7547
7596
|
}
|
|
7597
|
+
/** Lines of one `{ ... }` block starting at `startLineIdx` (inclusive). */
|
|
7598
|
+
function jsBracedBlockLines(lines, startLineIdx) {
|
|
7599
|
+
let depth = 0;
|
|
7600
|
+
let started = false;
|
|
7601
|
+
const out = [];
|
|
7602
|
+
for (let i = startLineIdx; i < lines.length; i++) {
|
|
7603
|
+
const l = lines[i];
|
|
7604
|
+
for (const c of l) {
|
|
7605
|
+
if (c === '{') {
|
|
7606
|
+
depth++;
|
|
7607
|
+
started = true;
|
|
7608
|
+
}
|
|
7609
|
+
else if (c === '}') {
|
|
7610
|
+
depth--;
|
|
7611
|
+
}
|
|
7612
|
+
}
|
|
7613
|
+
out.push(l);
|
|
7614
|
+
if (started && depth === 0)
|
|
7615
|
+
return out;
|
|
7616
|
+
}
|
|
7617
|
+
return null;
|
|
7618
|
+
}
|
|
7619
|
+
/**
|
|
7620
|
+
* True when `bodyLines` contains a rejecting allow-list guard on canonical path
|
|
7621
|
+
* variable `canon` (single-root startsWith or multi-root `.some` equality/prefix).
|
|
7622
|
+
*/
|
|
7623
|
+
function jsPathCanonicalAllowlistGuardRejects(bodyLines, canon, terminatorRe) {
|
|
7624
|
+
const esc = canon.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
7625
|
+
const singleRoot = new RegExp(`if\\s*\\(\\s*!\\s*${esc}\\s*\\.\\s*startsWith\\s*\\(`);
|
|
7626
|
+
const multiRootLine = (line) => /if\s*\(\s*!\s*[A-Za-z_\w]*\.some\s*\(/.test(line) &&
|
|
7627
|
+
new RegExp(`\\b${esc}\\b\\s*===\\s*\\w+\\s*\\|\\|\\s*\\b${esc}\\b\\.startsWith\\s*\\(`).test(line);
|
|
7628
|
+
for (let j = 0; j < bodyLines.length; j++) {
|
|
7629
|
+
const line = bodyLines[j];
|
|
7630
|
+
if (!singleRoot.test(line) && !multiRootLine(line))
|
|
7631
|
+
continue;
|
|
7632
|
+
if (guardRejects(bodyLines, j, terminatorRe, 2))
|
|
7633
|
+
return true;
|
|
7634
|
+
}
|
|
7635
|
+
return false;
|
|
7636
|
+
}
|
|
7637
|
+
/**
|
|
7638
|
+
* JS/TS: a helper returns `path.resolve(param)` only after a constant-root
|
|
7639
|
+
* allow-list guard (startsWith or ROOTS.some equality/prefix) with throw/return
|
|
7640
|
+
* on failure (cognium-dev#1146).
|
|
7641
|
+
*/
|
|
7642
|
+
function findJsPathAllowlistHelperSanitizers(code) {
|
|
7643
|
+
const sanitizers = [];
|
|
7644
|
+
const lines = code.split('\n');
|
|
7645
|
+
const terminatorRe = /\b(?:throw|return)\b/;
|
|
7646
|
+
const qualified = new Set();
|
|
7647
|
+
for (let i = 0; i < lines.length; i++) {
|
|
7648
|
+
const fnStart = lines[i].match(/\bfunction\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)\s*\{/);
|
|
7649
|
+
if (!fnStart)
|
|
7650
|
+
continue;
|
|
7651
|
+
const fnName = fnStart[1];
|
|
7652
|
+
const param = fnStart[2];
|
|
7653
|
+
const bodyLines = jsBracedBlockLines(lines, i);
|
|
7654
|
+
if (!bodyLines)
|
|
7655
|
+
continue;
|
|
7656
|
+
const bodyText = bodyLines.join('\n');
|
|
7657
|
+
const resolveRe = new RegExp(`\\b(?:const|let|var)\\s+([A-Za-z_\\w]*)\\s*=\\s*(?:(?:node:)?path|nodePath|Path)\\s*\\.\\s*(?:resolve|normalize)\\s*\\(\\s*${param}\\s*\\)`);
|
|
7658
|
+
const resolveM = resolveRe.exec(bodyText);
|
|
7659
|
+
if (!resolveM)
|
|
7660
|
+
continue;
|
|
7661
|
+
const canon = resolveM[1];
|
|
7662
|
+
if (!jsPathCanonicalAllowlistGuardRejects(bodyLines, canon, terminatorRe))
|
|
7663
|
+
continue;
|
|
7664
|
+
if (!new RegExp(`\\breturn\\s+${canon}\\b`).test(bodyText))
|
|
7665
|
+
continue;
|
|
7666
|
+
qualified.add(fnName);
|
|
7667
|
+
}
|
|
7668
|
+
for (const fnName of qualified) {
|
|
7669
|
+
const escFn = fnName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
7670
|
+
const callAssign = new RegExp(`\\b(?:const|let|var)\\s+([A-Za-z_\\w]*)\\s*=\\s*${escFn}\\s*\\(`);
|
|
7671
|
+
for (let i = 0; i < lines.length; i++) {
|
|
7672
|
+
const m = callAssign.exec(lines[i]);
|
|
7673
|
+
if (!m)
|
|
7674
|
+
continue;
|
|
7675
|
+
const outVar = m[1];
|
|
7676
|
+
const varRef = new RegExp(`\\b${outVar}\\b`);
|
|
7677
|
+
for (let l = i; l < lines.length; l++) {
|
|
7678
|
+
if (!varRef.test(lines[l]))
|
|
7679
|
+
continue;
|
|
7680
|
+
sanitizers.push({
|
|
7681
|
+
type: 'js_path_allowlist_helper',
|
|
7682
|
+
method: fnName,
|
|
7683
|
+
line: l + 1,
|
|
7684
|
+
sanitizes: ['path_traversal', 'external_taint_escape'],
|
|
7685
|
+
});
|
|
7686
|
+
}
|
|
7687
|
+
}
|
|
7688
|
+
}
|
|
7689
|
+
return sanitizers;
|
|
7690
|
+
}
|
|
7548
7691
|
/**
|
|
7549
7692
|
* JS/TS: bounded-command allowlist guard sanitizer (cognium-dev #223
|
|
7550
7693
|
* REG-144-17/18/19).
|