circle-ir 4.17.0 → 4.19.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 +186 -0
- package/dist/analysis/advisories.d.ts.map +1 -0
- package/dist/analysis/advisories.js +391 -0
- package/dist/analysis/advisories.js.map +1 -0
- package/dist/analysis/comment-lines.d.ts +14 -0
- package/dist/analysis/comment-lines.d.ts.map +1 -0
- package/dist/analysis/comment-lines.js +34 -0
- package/dist/analysis/comment-lines.js.map +1 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +81 -27
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-caller-gate.d.ts +2 -2
- package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
- package/dist/analysis/constant-caller-gate.js +205 -29
- package/dist/analysis/constant-caller-gate.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +4 -0
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +99 -0
- package/dist/analysis/constant-propagation/propagator.js.map +1 -1
- package/dist/analysis/entry-point-detection.d.ts.map +1 -1
- package/dist/analysis/entry-point-detection.js +72 -0
- package/dist/analysis/entry-point-detection.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 +124 -10
- 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/maven-declared.d.ts +72 -0
- package/dist/analysis/maven-declared.d.ts.map +1 -0
- package/dist/analysis/maven-declared.js +216 -0
- package/dist/analysis/maven-declared.js.map +1 -0
- package/dist/analysis/maven-version.d.ts +28 -0
- package/dist/analysis/maven-version.d.ts.map +1 -0
- package/dist/analysis/maven-version.js +172 -0
- package/dist/analysis/maven-version.js.map +1 -0
- package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.js +29 -1
- 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 +81 -1
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts +7 -0
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js +44 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
- package/dist/analysis/passes/insecure-cookie-pass.d.ts +2 -0
- package/dist/analysis/passes/insecure-cookie-pass.d.ts.map +1 -1
- package/dist/analysis/passes/insecure-cookie-pass.js +25 -3
- package/dist/analysis/passes/insecure-cookie-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts +11 -14
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +564 -0
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +18 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +1097 -15
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js +66 -3
- package/dist/analysis/passes/param-source-flow-gate-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 +5 -1
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts +44 -2
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +728 -13
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +133 -10
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/tls-verify-disabled-pass.d.ts +18 -0
- package/dist/analysis/passes/tls-verify-disabled-pass.d.ts.map +1 -1
- package/dist/analysis/passes/tls-verify-disabled-pass.js +161 -0
- package/dist/analysis/passes/tls-verify-disabled-pass.js.map +1 -1
- package/dist/analysis/passes/weak-random-pass.d.ts +6 -0
- package/dist/analysis/passes/weak-random-pass.d.ts.map +1 -1
- package/dist/analysis/passes/weak-random-pass.js +29 -0
- package/dist/analysis/passes/weak-random-pass.js.map +1 -1
- package/dist/analysis/promote-cross-file-flows.d.ts +17 -0
- package/dist/analysis/promote-cross-file-flows.d.ts.map +1 -0
- package/dist/analysis/promote-cross-file-flows.js +32 -0
- package/dist/analysis/promote-cross-file-flows.js.map +1 -0
- package/dist/analysis/sbom.d.ts +100 -0
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +514 -3
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/semver-version.d.ts +30 -0
- package/dist/analysis/semver-version.d.ts.map +1 -0
- package/dist/analysis/semver-version.js +76 -0
- package/dist/analysis/semver-version.js.map +1 -0
- package/dist/analysis/taint-matcher.d.ts +5 -0
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +293 -6
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analyzer.d.ts +57 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +69 -6
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +3156 -323
- package/dist/core/circle-ir-core.cjs +951 -409
- package/dist/core/circle-ir-core.js +951 -409
- package/dist/core/extractors/dfg.js +244 -2
- package/dist/core/extractors/dfg.js.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.d.ts +39 -0
- package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -0
- package/dist/core/extractors/ts-declaration-detail.js +266 -0
- package/dist/core/extractors/ts-declaration-detail.js.map +1 -0
- package/dist/graph/analysis-pass.d.ts +4 -1
- package/dist/graph/analysis-pass.d.ts.map +1 -1
- package/dist/graph/analysis-pass.js +4 -1
- package/dist/graph/analysis-pass.js.map +1 -1
- package/dist/graph-facts/dead-code.d.ts +62 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -0
- package/dist/graph-facts/dead-code.js +90 -0
- package/dist/graph-facts/dead-code.js.map +1 -0
- package/dist/graph-facts/dependency-calls.d.ts +86 -0
- package/dist/graph-facts/dependency-calls.d.ts.map +1 -0
- package/dist/graph-facts/dependency-calls.js +93 -0
- package/dist/graph-facts/dependency-calls.js.map +1 -0
- package/dist/graph-facts/index.d.ts +10 -0
- package/dist/graph-facts/index.d.ts.map +1 -0
- package/dist/graph-facts/index.js +10 -0
- package/dist/graph-facts/index.js.map +1 -0
- package/dist/graph-facts/maven-packages.d.ts +42 -0
- package/dist/graph-facts/maven-packages.d.ts.map +1 -0
- package/dist/graph-facts/maven-packages.js +133 -0
- package/dist/graph-facts/maven-packages.js.map +1 -0
- package/dist/graph-facts/reach.d.ts +203 -0
- package/dist/graph-facts/reach.d.ts.map +1 -0
- package/dist/graph-facts/reach.js +219 -0
- package/dist/graph-facts/reach.js.map +1 -0
- package/dist/graph-facts/removal-reach.d.ts +73 -0
- package/dist/graph-facts/removal-reach.d.ts.map +1 -0
- package/dist/graph-facts/removal-reach.js +64 -0
- package/dist/graph-facts/removal-reach.js.map +1 -0
- package/dist/index.d.ts +21 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/navigation/go-graph.d.ts +68 -0
- package/dist/navigation/go-graph.d.ts.map +1 -0
- package/dist/navigation/go-graph.js +753 -0
- package/dist/navigation/go-graph.js.map +1 -0
- package/dist/navigation/index.d.ts +7 -1
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +6 -0
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/java-entry-tables.d.ts +43 -0
- package/dist/navigation/java-entry-tables.d.ts.map +1 -0
- package/dist/navigation/java-entry-tables.js +56 -0
- package/dist/navigation/java-entry-tables.js.map +1 -0
- package/dist/navigation/java-graph.d.ts +64 -0
- package/dist/navigation/java-graph.d.ts.map +1 -0
- package/dist/navigation/java-graph.js +466 -0
- package/dist/navigation/java-graph.js.map +1 -0
- package/dist/navigation/navigation-index.d.ts +51 -1
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +72 -0
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/python-graph.d.ts +73 -0
- package/dist/navigation/python-graph.d.ts.map +1 -0
- package/dist/navigation/python-graph.js +867 -0
- package/dist/navigation/python-graph.js.map +1 -0
- package/dist/navigation/ts-call-edges.d.ts +193 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -0
- package/dist/navigation/ts-call-edges.js +2089 -0
- package/dist/navigation/ts-call-edges.js.map +1 -0
- package/dist/navigation/ts-entry-tables.d.ts +88 -0
- package/dist/navigation/ts-entry-tables.d.ts.map +1 -0
- package/dist/navigation/ts-entry-tables.js +50 -0
- package/dist/navigation/ts-entry-tables.js.map +1 -0
- package/dist/path-set/branches.d.ts +52 -0
- package/dist/path-set/branches.d.ts.map +1 -0
- package/dist/path-set/branches.js +124 -0
- package/dist/path-set/branches.js.map +1 -0
- package/dist/path-set/finding-diff.d.ts +63 -0
- package/dist/path-set/finding-diff.d.ts.map +1 -0
- package/dist/path-set/finding-diff.js +150 -0
- package/dist/path-set/finding-diff.js.map +1 -0
- package/dist/path-set/index.d.ts +18 -0
- package/dist/path-set/index.d.ts.map +1 -0
- package/dist/path-set/index.js +12 -0
- package/dist/path-set/index.js.map +1 -0
- package/dist/path-set/line-diff.d.ts +19 -0
- package/dist/path-set/line-diff.d.ts.map +1 -0
- package/dist/path-set/line-diff.js +98 -0
- package/dist/path-set/line-diff.js.map +1 -0
- package/dist/path-set/path-set.d.ts +88 -0
- package/dist/path-set/path-set.d.ts.map +1 -0
- package/dist/path-set/path-set.js +716 -0
- package/dist/path-set/path-set.js.map +1 -0
- package/dist/path-set/templates.d.ts +42 -0
- package/dist/path-set/templates.d.ts.map +1 -0
- package/dist/path-set/templates.js +119 -0
- package/dist/path-set/templates.js.map +1 -0
- package/dist/path-set/types.d.ts +195 -0
- package/dist/path-set/types.d.ts.map +1 -0
- package/dist/path-set/types.js +8 -0
- package/dist/path-set/types.js.map +1 -0
- package/dist/remedy-class/index.d.ts +12 -0
- package/dist/remedy-class/index.d.ts.map +1 -0
- package/dist/remedy-class/index.js +9 -0
- package/dist/remedy-class/index.js.map +1 -0
- package/dist/remedy-class/match.d.ts +165 -0
- package/dist/remedy-class/match.d.ts.map +1 -0
- package/dist/remedy-class/match.js +705 -0
- package/dist/remedy-class/match.js.map +1 -0
- package/dist/remedy-class/output-context.d.ts +25 -0
- package/dist/remedy-class/output-context.d.ts.map +1 -0
- package/dist/remedy-class/output-context.js +150 -0
- package/dist/remedy-class/output-context.js.map +1 -0
- package/dist/remedy-class/sha256.d.ts +18 -0
- package/dist/remedy-class/sha256.d.ts.map +1 -0
- package/dist/remedy-class/sha256.js +89 -0
- package/dist/remedy-class/sha256.js.map +1 -0
- package/dist/remedy-class/table.d.ts +130 -0
- package/dist/remedy-class/table.d.ts.map +1 -0
- package/dist/remedy-class/table.js +457 -0
- package/dist/remedy-class/table.js.map +1 -0
- package/dist/resolution/cross-file.d.ts +11 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +82 -5
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/builder.d.ts +20 -0
- package/dist/stable-ids/builder.d.ts.map +1 -0
- package/dist/stable-ids/builder.js +65 -0
- package/dist/stable-ids/builder.js.map +1 -0
- package/dist/stable-ids/diff.d.ts +18 -0
- package/dist/stable-ids/diff.d.ts.map +1 -0
- package/dist/stable-ids/diff.js +37 -0
- package/dist/stable-ids/diff.js.map +1 -0
- package/dist/stable-ids/go.d.ts +28 -0
- package/dist/stable-ids/go.d.ts.map +1 -0
- package/dist/stable-ids/go.js +160 -0
- package/dist/stable-ids/go.js.map +1 -0
- package/dist/stable-ids/hash.d.ts +22 -0
- package/dist/stable-ids/hash.d.ts.map +1 -0
- package/dist/stable-ids/hash.js +167 -0
- package/dist/stable-ids/hash.js.map +1 -0
- package/dist/stable-ids/index.d.ts +30 -0
- package/dist/stable-ids/index.d.ts.map +1 -0
- package/dist/stable-ids/index.js +59 -0
- package/dist/stable-ids/index.js.map +1 -0
- package/dist/stable-ids/java.d.ts +28 -0
- package/dist/stable-ids/java.d.ts.map +1 -0
- package/dist/stable-ids/java.js +224 -0
- package/dist/stable-ids/java.js.map +1 -0
- package/dist/stable-ids/moves.d.ts +87 -0
- package/dist/stable-ids/moves.d.ts.map +1 -0
- package/dist/stable-ids/moves.js +222 -0
- package/dist/stable-ids/moves.js.map +1 -0
- package/dist/stable-ids/nodes.d.ts +32 -0
- package/dist/stable-ids/nodes.d.ts.map +1 -0
- package/dist/stable-ids/nodes.js +92 -0
- package/dist/stable-ids/nodes.js.map +1 -0
- package/dist/stable-ids/normalize.d.ts +35 -0
- package/dist/stable-ids/normalize.d.ts.map +1 -0
- package/dist/stable-ids/normalize.js +174 -0
- package/dist/stable-ids/normalize.js.map +1 -0
- package/dist/stable-ids/parse-errors.d.ts +24 -0
- package/dist/stable-ids/parse-errors.d.ts.map +1 -0
- package/dist/stable-ids/parse-errors.js +46 -0
- package/dist/stable-ids/parse-errors.js.map +1 -0
- package/dist/stable-ids/python.d.ts +27 -0
- package/dist/stable-ids/python.d.ts.map +1 -0
- package/dist/stable-ids/python.js +212 -0
- package/dist/stable-ids/python.js.map +1 -0
- package/dist/stable-ids/ts-parse-errors.d.ts +27 -0
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -0
- package/dist/stable-ids/ts-parse-errors.js +75 -0
- package/dist/stable-ids/ts-parse-errors.js.map +1 -0
- package/dist/stable-ids/types.d.ts +106 -0
- package/dist/stable-ids/types.d.ts.map +1 -0
- package/dist/stable-ids/types.js +16 -0
- package/dist/stable-ids/types.js.map +1 -0
- package/dist/stable-ids/typescript.d.ts +30 -0
- package/dist/stable-ids/typescript.d.ts.map +1 -0
- package/dist/stable-ids/typescript.js +362 -0
- package/dist/stable-ids/typescript.js.map +1 -0
- package/dist/types/config.d.ts +9 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -20,6 +20,8 @@ import { javaCallArgument, javaCanonicalBaseLacksSeparator } from '../java-canon
|
|
|
20
20
|
import { findGoStringsReplacerSanitizers } from '../go-strings-replacer.js';
|
|
21
21
|
import { findRustLiteralEqualityGuardSanitizers } from '../rust-literal-guard.js';
|
|
22
22
|
import { constLookupTables, isConstTableLookup } from '../const-table-lookup.js';
|
|
23
|
+
import { jsReplaceChainVerdict } from '../js-crlf-strip.js';
|
|
24
|
+
import { jsHelperReturnsNoParam } from '../js-helper-return.js';
|
|
23
25
|
// ---------------------------------------------------------------------------
|
|
24
26
|
// Pattern tables (moved from analyzer.ts)
|
|
25
27
|
// ---------------------------------------------------------------------------
|
|
@@ -298,6 +300,8 @@ export class LanguageSourcesPass {
|
|
|
298
300
|
}
|
|
299
301
|
additionalSanitizers.push(...findBashRegexAllowlistSanitizers(code));
|
|
300
302
|
additionalSanitizers.push(...findBashRealpathPrefixGuardSanitizers(code));
|
|
303
|
+
// #816 CVE-2026-8398: gpg/sha verify-then-install download scripts.
|
|
304
|
+
additionalSanitizers.push(...findBashVerifiedPackageDownloadSanitizers(code));
|
|
301
305
|
// #213 twelfth slice: printf '%q' + ${var@Q} shell-quote helpers.
|
|
302
306
|
additionalSanitizers.push(...findBashShellQuoteSanitizers(code));
|
|
303
307
|
}
|
|
@@ -417,8 +421,14 @@ export class LanguageSourcesPass {
|
|
|
417
421
|
}
|
|
418
422
|
// -- Rust: safe-handler sanitizer detectors (cognium-dev #115 Sprint 31) --
|
|
419
423
|
if (language === 'rust') {
|
|
424
|
+
additionalSanitizers.push(...findRustConstSliceMembershipGuardSanitizers(code));
|
|
420
425
|
additionalSanitizers.push(...findRustSetAllowlistGuardSanitizers(code));
|
|
421
426
|
additionalSanitizers.push(...findRustCanonicalizeGuardSanitizers(code));
|
|
427
|
+
// cognium-dev #816 — PAT-INPUT-01 rust safe mirror: parse + range guards
|
|
428
|
+
// before actix/axum response body (same credit model as JS twin).
|
|
429
|
+
additionalSanitizers.push(...findRustNumericRangeCheckGuardSanitizers(code));
|
|
430
|
+
// cognium-dev #816 — PAT-INFO-01: response echoes only query params, no env secrets.
|
|
431
|
+
additionalSanitizers.push(...findRustPatInfoHttpOnlyResponseSanitizers(code));
|
|
422
432
|
// cognium-dev#293: `if x != "a" && x != "b" { return Err(..) }` literal-equality guard.
|
|
423
433
|
additionalSanitizers.push(...findRustLiteralEqualityGuardSanitizers(code));
|
|
424
434
|
// Sprint 77a (#216 Pattern X): argv-form Command::new(literal).arg(...)
|
|
@@ -484,6 +494,9 @@ export class LanguageSourcesPass {
|
|
|
484
494
|
// #223 REG-144-17/18/19: JS/TS command allowlist guard
|
|
485
495
|
// (Set.has / Array.includes / indexOf) before execFile/spawn.
|
|
486
496
|
additionalSanitizers.push(...findJsCommandAllowlistGuardSanitizers(code));
|
|
497
|
+
// cognium-dev #816 — PAT-INPUT-01 js safe mirror: Number/parseInt
|
|
498
|
+
// coercion + finite/range guards before template response.
|
|
499
|
+
additionalSanitizers.push(...findJsNumericRangeCheckGuardSanitizers(code));
|
|
487
500
|
// Sprint 78 (#190): JS misconfig pattern findings — libxmljs noent:true.
|
|
488
501
|
for (const finding of findJsPatternFindings(code, graph.ir.meta.file)) {
|
|
489
502
|
ctx.addFinding(finding);
|
|
@@ -517,6 +530,9 @@ export class LanguageSourcesPass {
|
|
|
517
530
|
for (const finding of findJsLdapInjectionFindings(code, graph.ir.meta.file)) {
|
|
518
531
|
ctx.addFinding(finding);
|
|
519
532
|
}
|
|
533
|
+
for (const finding of findJsZipHeaderFailopenFindings(code, graph.ir.meta.file)) {
|
|
534
|
+
ctx.addFinding(finding);
|
|
535
|
+
}
|
|
520
536
|
// Sprint 89 (#189): JS insecure_deserialization —
|
|
521
537
|
// JSON.parse(req.body) on raw / text bodies.
|
|
522
538
|
for (const finding of findJsJsonParseBodyFindings(code, graph.ir.meta.file)) {
|
|
@@ -576,6 +592,9 @@ export class LanguageSourcesPass {
|
|
|
576
592
|
additionalSanitizers.push(...findJavaInlineCrlfStripLogSanitizers(code));
|
|
577
593
|
// cognium-dev#293: the same strip, but living in a user-defined helper.
|
|
578
594
|
additionalSanitizers.push(...findCrlfWrapperFunctionSanitizers(code, 'java'));
|
|
595
|
+
// cognium-dev#947: flow-sanitize ssti custom_wrapper — brace-stripping
|
|
596
|
+
// helper at Velocity.evaluate call site.
|
|
597
|
+
additionalSanitizers.push(...findJavaTemplateDelimiterWrapperSanitizers(code));
|
|
579
598
|
// Sprint 77a (#216 Pattern X): argv-form exec sanitizer.
|
|
580
599
|
additionalSanitizers.push(...findJavaArgvFormExecSanitizers(code));
|
|
581
600
|
// Sprint 78 (#190): Java misconfig pattern findings —
|
|
@@ -2114,6 +2133,37 @@ function classifyCSharpLambdaParam(raw) {
|
|
|
2114
2133
|
return { type: 'http_param', name, via: 'string param' };
|
|
2115
2134
|
return null;
|
|
2116
2135
|
}
|
|
2136
|
+
/**
|
|
2137
|
+
* cognium-dev#1049 — an Express handler that destructures the request
|
|
2138
|
+
* (`({ query }: Request, res: Response) => { … query.to … }`, OWASP Juice Shop
|
|
2139
|
+
* `routes/redirect.ts`) reads `query.to`, which no `req.query` pattern matches.
|
|
2140
|
+
* When a parameter object pattern is typed `Request` (optionally
|
|
2141
|
+
* `express.Request`), each request field it binds — `query`, `params`, `body`,
|
|
2142
|
+
* `headers`, `cookies`, under its own name or a rename (`query: q`) — becomes a
|
|
2143
|
+
* source pattern for that binding.
|
|
2144
|
+
*/
|
|
2145
|
+
const REQUEST_FIELD_TYPES = {
|
|
2146
|
+
query: 'http_param', params: 'http_param', body: 'http_body', headers: 'http_header', cookies: 'http_cookie',
|
|
2147
|
+
};
|
|
2148
|
+
function destructuredRequestPatterns(sourceCode) {
|
|
2149
|
+
const out = [];
|
|
2150
|
+
const seen = new Set();
|
|
2151
|
+
for (const m of sourceCode.matchAll(/[(,]\s*\{([^{}]*)\}\s*:\s*(?:express\.)?Request\b/g)) {
|
|
2152
|
+
for (const part of m[1].split(',')) {
|
|
2153
|
+
const bind = /^\s*(\w+)\s*(?::\s*(\w+))?\s*(?:=[^,]*)?$/.exec(part);
|
|
2154
|
+
if (!bind)
|
|
2155
|
+
continue;
|
|
2156
|
+
const field = bind[1];
|
|
2157
|
+
const local = bind[2] ?? bind[1];
|
|
2158
|
+
const type = REQUEST_FIELD_TYPES[field];
|
|
2159
|
+
if (!type || seen.has(local))
|
|
2160
|
+
continue;
|
|
2161
|
+
seen.add(local);
|
|
2162
|
+
out.push({ pattern: new RegExp(`(?<![\\w.])${local}\\s*[.[]`), type });
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
return out;
|
|
2166
|
+
}
|
|
2117
2167
|
function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
2118
2168
|
if (!['javascript', 'typescript'].includes(language))
|
|
2119
2169
|
return [];
|
|
@@ -2129,7 +2179,8 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
|
2129
2179
|
&& /\{[^}]*\bparams\b[^}]*\}/.test(sourceCode);
|
|
2130
2180
|
const patterns = isRouteHandler
|
|
2131
2181
|
? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: 'http_path' }]
|
|
2132
|
-
: JS_TAINTED_PATTERNS;
|
|
2182
|
+
: [...JS_TAINTED_PATTERNS];
|
|
2183
|
+
patterns.push(...destructuredRequestPatterns(sourceCode));
|
|
2133
2184
|
// #667: `REGISTRY[req.query.mod]` on a constant table yields a value the
|
|
2134
2185
|
// program wrote, not request data.
|
|
2135
2186
|
const lookupTables = constLookupTables(sourceCode, language);
|
|
@@ -2164,6 +2215,12 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
|
2164
2215
|
}
|
|
2165
2216
|
if (isConstTableLookup(rhs, lookupTables))
|
|
2166
2217
|
continue;
|
|
2218
|
+
// #992: `v = pick(req.query.x)` where the same-file `pick` returns no
|
|
2219
|
+
// parameter (a literal, or a literal slot of a local array) — the request
|
|
2220
|
+
// value goes in but never comes out.
|
|
2221
|
+
const wholeCall = /^\s*([A-Za-z_$][\w$]*)\s*\(.*\)\s*;?\s*$/.exec(rhs);
|
|
2222
|
+
if (wholeCall && jsHelperReturnsNoParam(sourceCode, wholeCall[1]))
|
|
2223
|
+
continue;
|
|
2167
2224
|
for (const { pattern, type } of patterns) {
|
|
2168
2225
|
if (pattern.test(rhs)) {
|
|
2169
2226
|
const alreadyExists = sources.some(s => s.line === lineNumber && s.type === type && s.variable === varName);
|
|
@@ -2851,6 +2908,171 @@ function computeDeadPythonBranchLines(lines) {
|
|
|
2851
2908
|
}
|
|
2852
2909
|
return dead;
|
|
2853
2910
|
}
|
|
2911
|
+
/**
|
|
2912
|
+
* Line indices (0-based) in unreachable `if`/`else` arms when the condition is
|
|
2913
|
+
* decidable from tracked integer locals (`int num = 86; if ((7*42)-num > 200) …`).
|
|
2914
|
+
*
|
|
2915
|
+
* Targets OWASP Benchmark shapes where the else arm assigns a parameter but
|
|
2916
|
+
* can never run (cognium-dev#913). Braced bodies defer to constant propagation;
|
|
2917
|
+
* this pass handles the common single-statement `if` / `else` lines.
|
|
2918
|
+
*/
|
|
2919
|
+
function parseJavaSwitchCaseLabel(label) {
|
|
2920
|
+
const t = label.trim();
|
|
2921
|
+
if (t === 'default')
|
|
2922
|
+
return 'default';
|
|
2923
|
+
const ch = t.match(/^'(\\.|[^'])'\s*$/);
|
|
2924
|
+
if (ch) {
|
|
2925
|
+
const inner = ch[1];
|
|
2926
|
+
if (inner.startsWith('\\')) {
|
|
2927
|
+
if (inner === "\\'")
|
|
2928
|
+
return 39;
|
|
2929
|
+
if (inner === '\\\\')
|
|
2930
|
+
return 92;
|
|
2931
|
+
if (inner === '\\n')
|
|
2932
|
+
return 10;
|
|
2933
|
+
return undefined;
|
|
2934
|
+
}
|
|
2935
|
+
return inner.charCodeAt(0);
|
|
2936
|
+
}
|
|
2937
|
+
const num = t.match(/^(-?\d+)\s*$/);
|
|
2938
|
+
if (num)
|
|
2939
|
+
return Number(num[1]);
|
|
2940
|
+
return undefined;
|
|
2941
|
+
}
|
|
2942
|
+
function parseJavaSwitchLabelLine(line) {
|
|
2943
|
+
const caseLine = line.match(/^\s*case\s+(.+?)\s*:\s*$/);
|
|
2944
|
+
if (caseLine)
|
|
2945
|
+
return parseJavaSwitchCaseLabel(caseLine[1]);
|
|
2946
|
+
if (/^\s*default\s*:\s*$/.test(line))
|
|
2947
|
+
return 'default';
|
|
2948
|
+
return undefined;
|
|
2949
|
+
}
|
|
2950
|
+
function markDeadJavaSwitchBodies(lines, switchLineIdx, switchValue, dead) {
|
|
2951
|
+
let depth = 0;
|
|
2952
|
+
let started = false;
|
|
2953
|
+
let groupLabels = [];
|
|
2954
|
+
let bodyStart = -1;
|
|
2955
|
+
let explicitCaseMatched = false;
|
|
2956
|
+
const groupIsTaken = () => {
|
|
2957
|
+
if (groupLabels.length === 0)
|
|
2958
|
+
return false;
|
|
2959
|
+
const explicit = groupLabels.some(v => v !== 'default' && v === switchValue);
|
|
2960
|
+
if (explicit)
|
|
2961
|
+
return true;
|
|
2962
|
+
return groupLabels.includes('default') && !explicitCaseMatched;
|
|
2963
|
+
};
|
|
2964
|
+
const flushGroup = (bodyEnd) => {
|
|
2965
|
+
if (bodyStart < 0 || groupLabels.length === 0)
|
|
2966
|
+
return;
|
|
2967
|
+
const taken = groupIsTaken();
|
|
2968
|
+
if (groupLabels.some(v => v !== 'default' && v === switchValue)) {
|
|
2969
|
+
explicitCaseMatched = true;
|
|
2970
|
+
}
|
|
2971
|
+
if (!taken) {
|
|
2972
|
+
for (let k = bodyStart; k < bodyEnd; k++)
|
|
2973
|
+
dead.add(k);
|
|
2974
|
+
}
|
|
2975
|
+
groupLabels = [];
|
|
2976
|
+
bodyStart = -1;
|
|
2977
|
+
};
|
|
2978
|
+
for (let j = switchLineIdx; j < lines.length; j++) {
|
|
2979
|
+
const line = lines[j];
|
|
2980
|
+
for (const ch of line) {
|
|
2981
|
+
if (ch === '{') {
|
|
2982
|
+
depth++;
|
|
2983
|
+
started = true;
|
|
2984
|
+
}
|
|
2985
|
+
else if (ch === '}')
|
|
2986
|
+
depth--;
|
|
2987
|
+
}
|
|
2988
|
+
if (!started)
|
|
2989
|
+
continue;
|
|
2990
|
+
const label = parseJavaSwitchLabelLine(line);
|
|
2991
|
+
if (label !== undefined) {
|
|
2992
|
+
if (bodyStart >= 0 && j === bodyStart) {
|
|
2993
|
+
groupLabels.push(label);
|
|
2994
|
+
bodyStart = j + 1;
|
|
2995
|
+
}
|
|
2996
|
+
else {
|
|
2997
|
+
flushGroup(j);
|
|
2998
|
+
groupLabels = [label];
|
|
2999
|
+
bodyStart = j + 1;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
if (started && depth === 0) {
|
|
3003
|
+
flushGroup(j);
|
|
3004
|
+
break;
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
export function computeDeadJavaBranchLines(lines) {
|
|
3009
|
+
const dead = new Set();
|
|
3010
|
+
const consts = new Map();
|
|
3011
|
+
const stringConsts = new Map();
|
|
3012
|
+
const charConsts = new Map();
|
|
3013
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3014
|
+
const line = lines[i];
|
|
3015
|
+
const stringAssign = line.match(/^\s*String\s+([A-Za-z_]\w*)\s*=\s*"([^"]*)"\s*;\s*$/);
|
|
3016
|
+
if (stringAssign) {
|
|
3017
|
+
stringConsts.set(stringAssign[1], stringAssign[2]);
|
|
3018
|
+
continue;
|
|
3019
|
+
}
|
|
3020
|
+
const charAtAssign = line.match(/^\s*char\s+([A-Za-z_]\w*)\s*=\s*([A-Za-z_]\w*)\.charAt\s*\(\s*(\d+)\s*\)\s*;\s*(?:\/\/.*)?$/);
|
|
3021
|
+
if (charAtAssign) {
|
|
3022
|
+
const str = stringConsts.get(charAtAssign[2]);
|
|
3023
|
+
const idx = Number(charAtAssign[3]);
|
|
3024
|
+
if (str !== undefined && idx >= 0 && idx < str.length) {
|
|
3025
|
+
charConsts.set(charAtAssign[1], str.charCodeAt(idx));
|
|
3026
|
+
}
|
|
3027
|
+
else {
|
|
3028
|
+
charConsts.delete(charAtAssign[1]);
|
|
3029
|
+
}
|
|
3030
|
+
continue;
|
|
3031
|
+
}
|
|
3032
|
+
const intAssign = line.match(/^\s*(?:int|long|short|byte)\s+([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/);
|
|
3033
|
+
if (intAssign) {
|
|
3034
|
+
const v = evaluatePythonConstExpression(intAssign[2].trim(), consts);
|
|
3035
|
+
if (typeof v === 'number')
|
|
3036
|
+
consts.set(intAssign[1], v);
|
|
3037
|
+
else
|
|
3038
|
+
consts.delete(intAssign[1]);
|
|
3039
|
+
continue;
|
|
3040
|
+
}
|
|
3041
|
+
const switchMatch = line.match(/^\s*switch\s*\(([^)]+)\)\s*\{?\s*$/);
|
|
3042
|
+
if (switchMatch) {
|
|
3043
|
+
const sel = switchMatch[1].trim();
|
|
3044
|
+
let switchVal = charConsts.get(sel);
|
|
3045
|
+
if (switchVal === undefined) {
|
|
3046
|
+
const n = evaluatePythonConstExpression(sel, consts);
|
|
3047
|
+
if (typeof n === 'number')
|
|
3048
|
+
switchVal = n;
|
|
3049
|
+
}
|
|
3050
|
+
if (switchVal !== undefined) {
|
|
3051
|
+
markDeadJavaSwitchBodies(lines, i, switchVal, dead);
|
|
3052
|
+
}
|
|
3053
|
+
continue;
|
|
3054
|
+
}
|
|
3055
|
+
const ifMatch = line.match(/^(\s*)if\s*\((.+)\)\s+(.+)$/);
|
|
3056
|
+
if (!ifMatch)
|
|
3057
|
+
continue;
|
|
3058
|
+
const decided = evaluatePythonConstExpression(ifMatch[2].trim(), consts);
|
|
3059
|
+
if (decided !== true && decided !== false)
|
|
3060
|
+
continue;
|
|
3061
|
+
const rest = ifMatch[3].trim();
|
|
3062
|
+
if (/\belse\b/.test(rest))
|
|
3063
|
+
continue;
|
|
3064
|
+
if (i + 1 < lines.length && /^\s*else\b/.test(lines[i + 1])) {
|
|
3065
|
+
if (decided === true)
|
|
3066
|
+
dead.add(i + 1);
|
|
3067
|
+
else
|
|
3068
|
+
dead.add(i);
|
|
3069
|
+
}
|
|
3070
|
+
else if (decided === false) {
|
|
3071
|
+
dead.add(i);
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
return dead;
|
|
3075
|
+
}
|
|
2854
3076
|
export function buildPythonTaintedVars(sourceCode) {
|
|
2855
3077
|
const tainted = new Map();
|
|
2856
3078
|
const containerTainted = new Map();
|
|
@@ -3916,6 +4138,113 @@ export function buildRustTaintedVars(sourceCode, seedVars) {
|
|
|
3916
4138
|
* on the way (a lambda, anonymous class, switch expression or block is not a
|
|
3917
4139
|
* plain wrapped value).
|
|
3918
4140
|
*/
|
|
4141
|
+
/** `code(); // note` → `code();` — a `//` inside a string or char literal is kept. */
|
|
4142
|
+
function stripJavaTrailingLineComment(line) {
|
|
4143
|
+
let quote = null;
|
|
4144
|
+
for (let i = 0; i < line.length; i++) {
|
|
4145
|
+
const c = line[i];
|
|
4146
|
+
if (quote) {
|
|
4147
|
+
if (c === '\\')
|
|
4148
|
+
i++;
|
|
4149
|
+
else if (c === quote)
|
|
4150
|
+
quote = null;
|
|
4151
|
+
}
|
|
4152
|
+
else if (c === '"' || c === "'") {
|
|
4153
|
+
quote = c;
|
|
4154
|
+
}
|
|
4155
|
+
else if (c === '/' && line[i + 1] === '/') {
|
|
4156
|
+
return line.slice(0, i).trimEnd();
|
|
4157
|
+
}
|
|
4158
|
+
}
|
|
4159
|
+
return line;
|
|
4160
|
+
}
|
|
4161
|
+
/** Identifiers at code positions in a Java expression (string and char literal bodies dropped). */
|
|
4162
|
+
function javaExpressionIdents(expr) {
|
|
4163
|
+
const code = expr.replace(/"(?:[^"\\]|\\.)*"/g, ' ').replace(/'(?:[^'\\]|\\.)'/g, ' ');
|
|
4164
|
+
return code.match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
4165
|
+
}
|
|
4166
|
+
/**
|
|
4167
|
+
* `buildJavaTaintedVars` slot tracking (cognium-dev#913/#914/#916/#917). Records
|
|
4168
|
+
* `list.add(x)` / `list.remove(<int>)` / `map.put("<key>", x)` into the slot
|
|
4169
|
+
* tables and returns true for those statements. An `int` constant declaration
|
|
4170
|
+
* is recorded for ternary folding but returns false, so the line is still read
|
|
4171
|
+
* as an assignment.
|
|
4172
|
+
*/
|
|
4173
|
+
function recordJavaSlotStatement(line, listElems, mapSlots, intConsts) {
|
|
4174
|
+
const t = line.trimEnd().replace(/;\s*\/\/[^"]*$/, ';');
|
|
4175
|
+
const intDecl = /^\s*(?:final\s+)?(?:int|long|short|byte)\s+([A-Za-z_]\w*)\s*=\s*([^;]+);\s*$/.exec(t);
|
|
4176
|
+
if (intDecl) {
|
|
4177
|
+
const v = evaluatePythonConstExpression(intDecl[2].trim(), intConsts);
|
|
4178
|
+
if (typeof v === 'number')
|
|
4179
|
+
intConsts.set(intDecl[1], v);
|
|
4180
|
+
else
|
|
4181
|
+
intConsts.delete(intDecl[1]);
|
|
4182
|
+
return false;
|
|
4183
|
+
}
|
|
4184
|
+
const add = /^\s*([A-Za-z_]\w*)\.add\s*\(\s*([A-Za-z_]\w*|"(?:[^"\\]|\\.)*")\s*\)\s*;\s*$/.exec(t);
|
|
4185
|
+
if (add) {
|
|
4186
|
+
const elems = listElems.get(add[1]) ?? [];
|
|
4187
|
+
elems.push(add[2].startsWith('"') ? null : add[2]);
|
|
4188
|
+
listElems.set(add[1], elems);
|
|
4189
|
+
return true;
|
|
4190
|
+
}
|
|
4191
|
+
const remove = /^\s*([A-Za-z_]\w*)\.remove\s*\(\s*(\d+)\s*\)\s*;\s*$/.exec(t);
|
|
4192
|
+
if (remove && listElems.has(remove[1])) {
|
|
4193
|
+
const elems = listElems.get(remove[1]);
|
|
4194
|
+
const idx = Number(remove[2]);
|
|
4195
|
+
if (idx < elems.length)
|
|
4196
|
+
elems.splice(idx, 1);
|
|
4197
|
+
else
|
|
4198
|
+
listElems.delete(remove[1]); // an index we did not see added: stop trusting the slots
|
|
4199
|
+
return true;
|
|
4200
|
+
}
|
|
4201
|
+
const put = /^\s*([A-Za-z_]\w*)\.put\s*\(\s*"((?:[^"\\]|\\.)*)"\s*,\s*(.+?)\s*\)\s*;\s*$/.exec(t);
|
|
4202
|
+
if (put) {
|
|
4203
|
+
const keys = mapSlots.get(put[1]) ?? new Map();
|
|
4204
|
+
keys.set(put[2], javaExpressionIdents(put[3]));
|
|
4205
|
+
mapSlots.set(put[1], keys);
|
|
4206
|
+
return true;
|
|
4207
|
+
}
|
|
4208
|
+
// Any other use of a tracked collection that is not a plain read (passed to a
|
|
4209
|
+
// call, `addAll`, `set`, `clear`, a non-literal `put`, re-declared …) may change
|
|
4210
|
+
// its contents in a way the tables do not model: stop trusting its slots.
|
|
4211
|
+
for (const table of [listElems, mapSlots]) {
|
|
4212
|
+
for (const name of [...table.keys()]) {
|
|
4213
|
+
const mention = new RegExp(`(?<![\\w.])${name}(?!\\w)`);
|
|
4214
|
+
if (!mention.test(t))
|
|
4215
|
+
continue;
|
|
4216
|
+
const reads = new RegExp(`(?<![\\w.])${name}\\.(?:get|size|isEmpty|contains\\w*)\\s*\\(`, 'g');
|
|
4217
|
+
if (mention.test(t.replace(reads, ' ')))
|
|
4218
|
+
table.delete(name);
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4221
|
+
return false;
|
|
4222
|
+
}
|
|
4223
|
+
/**
|
|
4224
|
+
* The identifiers a `list.get(<int>)` / `map.get("<key>")` read (optionally
|
|
4225
|
+
* cast) can carry, from the slot tables; `undefined` when the RHS is not such a
|
|
4226
|
+
* read or the slots are unknown, so the caller falls back to whole-RHS matching.
|
|
4227
|
+
*/
|
|
4228
|
+
function javaSlotRead(rhs, listElems, mapSlots) {
|
|
4229
|
+
const m = /^(?:\(\s*[A-Za-z_][\w.<>]*\s*\)\s*)?([A-Za-z_]\w*)\.get\s*\(\s*(\d+|"(?:[^"\\]|\\.)*")\s*\)$/.exec(rhs.trim());
|
|
4230
|
+
if (!m)
|
|
4231
|
+
return undefined;
|
|
4232
|
+
const [, recv, arg] = m;
|
|
4233
|
+
if (arg.startsWith('"')) {
|
|
4234
|
+
const keys = mapSlots.get(recv);
|
|
4235
|
+
if (!keys)
|
|
4236
|
+
return undefined;
|
|
4237
|
+
return keys.get(arg.slice(1, -1)) ?? [];
|
|
4238
|
+
}
|
|
4239
|
+
const elems = listElems.get(recv);
|
|
4240
|
+
if (!elems)
|
|
4241
|
+
return undefined;
|
|
4242
|
+
const idx = Number(arg);
|
|
4243
|
+
if (idx >= elems.length)
|
|
4244
|
+
return undefined;
|
|
4245
|
+
const slot = elems[idx];
|
|
4246
|
+
return slot === null ? [] : [slot];
|
|
4247
|
+
}
|
|
3919
4248
|
function joinWrappedJavaStatement(lines, i) {
|
|
3920
4249
|
const strip = (l) => l.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)'/g, '""').replace(/\/\/.*$/, '');
|
|
3921
4250
|
const first = strip(lines[i]);
|
|
@@ -3962,10 +4291,30 @@ function joinWrappedJavaStatement(lines, i) {
|
|
|
3962
4291
|
* consumed by `detectExpressionScanFlows` in `taint-propagation-pass.ts`
|
|
3963
4292
|
* to synthesize a virtual source for each derived var.
|
|
3964
4293
|
*/
|
|
3965
|
-
export function buildJavaTaintedVars(sourceCode, seedVars
|
|
4294
|
+
export function buildJavaTaintedVars(sourceCode, seedVars, deadBranchLines,
|
|
4295
|
+
/**
|
|
4296
|
+
* `trackSlots` (cognium-dev#913/#914/#916/#917): follow which element of a list
|
|
4297
|
+
* and which literal key of a map holds taint, and pick the branch of a ternary
|
|
4298
|
+
* whose condition folds to a constant int comparison. Only the helper-return
|
|
4299
|
+
* gate in InterproceduralPass asks for it; every other caller keeps the
|
|
4300
|
+
* whole-collection behaviour.
|
|
4301
|
+
*/
|
|
4302
|
+
options) {
|
|
3966
4303
|
const derived = new Map();
|
|
3967
4304
|
const knownTainted = new Set(seedVars);
|
|
3968
|
-
const
|
|
4305
|
+
const trackSlots = options?.trackSlots === true;
|
|
4306
|
+
// Slot mode also reads `x = list.get(0); // note` as the statement it is: the
|
|
4307
|
+
// assignment patterns below are anchored at `;`.
|
|
4308
|
+
const lines = trackSlots
|
|
4309
|
+
? sourceCode.split('\n').map(stripJavaTrailingLineComment)
|
|
4310
|
+
: sourceCode.split('\n');
|
|
4311
|
+
const dead = deadBranchLines ?? new Set();
|
|
4312
|
+
/** list var → element slots: the added identifier, or `null` for a literal. */
|
|
4313
|
+
const listElems = new Map();
|
|
4314
|
+
/** map var → literal key → the identifiers its stored value mentions. */
|
|
4315
|
+
const mapSlots = new Map();
|
|
4316
|
+
/** int locals with a constant value, for folding a ternary condition. */
|
|
4317
|
+
const intConsts = new Map();
|
|
3969
4318
|
// Declaration: [modifiers] Type[<...>] [ ] lhs = rhs;
|
|
3970
4319
|
// Simple assignment: lhs = rhs;
|
|
3971
4320
|
// The declaration form is tried first because a Type token in front
|
|
@@ -3980,6 +4329,8 @@ export function buildJavaTaintedVars(sourceCode, seedVars) {
|
|
|
3980
4329
|
// original var directly.
|
|
3981
4330
|
const declRe = /^\s*(?:public|private|protected|static|final|volatile|transient|\s)*\s*(?:[A-Za-z_][\w.]*(?:\s*<[^>]*>)?(?:\s*\[\s*\])*)\s+([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
|
|
3982
4331
|
const assignRe = /^\s*([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
|
|
4332
|
+
const thisFieldAssignRe = /^\s*this\.([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
|
|
4333
|
+
const beanSetterCallRe = /\bset([A-Z]\w*)\s*\((.*)\)\s*;?\s*$/;
|
|
3983
4334
|
const JAVA_KEYWORDS = new Set([
|
|
3984
4335
|
'if', 'else', 'while', 'for', 'do', 'switch', 'case', 'return',
|
|
3985
4336
|
'throw', 'try', 'catch', 'finally', 'new', 'this', 'super',
|
|
@@ -4003,11 +4354,28 @@ export function buildJavaTaintedVars(sourceCode, seedVars) {
|
|
|
4003
4354
|
while (changed && guard < lines.length + 2) {
|
|
4004
4355
|
changed = false;
|
|
4005
4356
|
guard++;
|
|
4357
|
+
// Slot state is rebuilt on every pass: it describes the code top to bottom,
|
|
4358
|
+
// while `knownTainted` only grows.
|
|
4359
|
+
listElems.clear();
|
|
4360
|
+
mapSlots.clear();
|
|
4361
|
+
intConsts.clear();
|
|
4006
4362
|
for (let i = 0; i < lines.length; i++) {
|
|
4363
|
+
if (deadBranchLines !== undefined && dead.has(i))
|
|
4364
|
+
continue;
|
|
4007
4365
|
const line = lines[i];
|
|
4008
4366
|
const trimmed = line.trimStart();
|
|
4009
4367
|
if (trimmed.startsWith('//') || trimmed.startsWith('*'))
|
|
4010
4368
|
continue;
|
|
4369
|
+
if (trackSlots && recordJavaSlotStatement(line, listElems, mapSlots, intConsts)) {
|
|
4370
|
+
// `list.add(x)` still taints the list as a whole, as below.
|
|
4371
|
+
const add = /^\s*([A-Za-z_]\w*)\.add\s*\(\s*([A-Za-z_]\w*)\s*\)\s*;/.exec(line);
|
|
4372
|
+
if (add && knownTainted.has(add[2]) && !knownTainted.has(add[1])) {
|
|
4373
|
+
derived.set(add[1], i + 1);
|
|
4374
|
+
knownTainted.add(add[1]);
|
|
4375
|
+
changed = true;
|
|
4376
|
+
}
|
|
4377
|
+
continue;
|
|
4378
|
+
}
|
|
4011
4379
|
// cognium-dev#476: non-assignment statements (must run before the #753
|
|
4012
4380
|
// wrap-join early-continue, which would skip them).
|
|
4013
4381
|
const arrayCopyRe = /\bSystem\.arraycopy\s*\(\s*([A-Za-z_]\w*)\s*,\s*[^,]+\s*,\s*([A-Za-z_]\w*)\s*,/;
|
|
@@ -4042,21 +4410,92 @@ export function buildJavaTaintedVars(sourceCode, seedVars) {
|
|
|
4042
4410
|
// statement whose call argument list wraps over several lines reads like
|
|
4043
4411
|
// the same statement on one line.
|
|
4044
4412
|
const joined = joinWrappedJavaStatement(lines, i);
|
|
4045
|
-
if (joined
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4413
|
+
if (joined !== null) {
|
|
4414
|
+
statement = joined;
|
|
4415
|
+
declMatch = declRe.exec(statement);
|
|
4416
|
+
assignMatch = !declMatch ? assignRe.exec(statement) : null;
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
const thisFieldMatch = thisFieldAssignRe.exec(statement.trim());
|
|
4420
|
+
if (thisFieldMatch) {
|
|
4421
|
+
const fieldName = thisFieldMatch[1];
|
|
4422
|
+
const rhs = thisFieldMatch[2];
|
|
4423
|
+
const rhsCode = rhs
|
|
4424
|
+
.replace(/\$@?"(?:[^"\\]|\\.)*"/g, lit => ' ' + [...lit.matchAll(/\{([^}]*)\}/g)].map(x => x[1]).join(' ') + ' ')
|
|
4425
|
+
.replace(/@?"(?:[^"\\]|\\.)*"/g, ' ')
|
|
4426
|
+
.replace(/'(?:[^'\\]|\\.)'/g, ' ');
|
|
4427
|
+
const rhsIdents = rhsCode.match(/[\p{L}\p{N}_]+/gu);
|
|
4428
|
+
const ref = (rhsIdents !== null && rhsIdents.some(t => knownTainted.has(t))) ||
|
|
4429
|
+
(complexTaintedRes.length > 0 && complexTaintedRes.some(re => re.test(rhsCode)));
|
|
4430
|
+
if (ref) {
|
|
4431
|
+
const thisField = `this.${fieldName}`;
|
|
4432
|
+
if (!knownTainted.has(thisField)) {
|
|
4433
|
+
derived.set(thisField, i + 1);
|
|
4434
|
+
knownTainted.add(thisField);
|
|
4435
|
+
changed = true;
|
|
4436
|
+
}
|
|
4437
|
+
if (!knownTainted.has(fieldName)) {
|
|
4438
|
+
derived.set(fieldName, i + 1);
|
|
4439
|
+
knownTainted.add(fieldName);
|
|
4440
|
+
changed = true;
|
|
4441
|
+
}
|
|
4442
|
+
}
|
|
4443
|
+
continue;
|
|
4444
|
+
}
|
|
4445
|
+
const setterCall = beanSetterCallRe.exec(statement);
|
|
4446
|
+
if (setterCall) {
|
|
4447
|
+
const fieldName = setterCall[1].charAt(0).toLowerCase() + setterCall[1].slice(1);
|
|
4448
|
+
const arg = setterCall[2];
|
|
4449
|
+
const rhsCode = arg
|
|
4450
|
+
.replace(/\$@?"(?:[^"\\]|\\.)*"/g, lit => ' ' + [...lit.matchAll(/\{([^}]*)\}/g)].map(x => x[1]).join(' ') + ' ')
|
|
4451
|
+
.replace(/@?"(?:[^"\\]|\\.)*"/g, ' ')
|
|
4452
|
+
.replace(/'(?:[^'\\]|\\.)'/g, ' ');
|
|
4453
|
+
const rhsIdents = rhsCode.match(/[\p{L}\p{N}_]+/gu);
|
|
4454
|
+
const ref = (rhsIdents !== null && rhsIdents.some(t => knownTainted.has(t))) ||
|
|
4455
|
+
(complexTaintedRes.length > 0 && complexTaintedRes.some(re => re.test(rhsCode)));
|
|
4456
|
+
if (ref) {
|
|
4457
|
+
const thisField = `this.${fieldName}`;
|
|
4458
|
+
if (!knownTainted.has(thisField)) {
|
|
4459
|
+
derived.set(thisField, i + 1);
|
|
4460
|
+
knownTainted.add(thisField);
|
|
4461
|
+
changed = true;
|
|
4462
|
+
}
|
|
4463
|
+
if (!knownTainted.has(fieldName)) {
|
|
4464
|
+
derived.set(fieldName, i + 1);
|
|
4465
|
+
knownTainted.add(fieldName);
|
|
4466
|
+
changed = true;
|
|
4467
|
+
}
|
|
4468
|
+
}
|
|
4469
|
+
continue;
|
|
4050
4470
|
}
|
|
4051
4471
|
const m = declMatch ?? assignMatch;
|
|
4052
4472
|
if (!m)
|
|
4053
4473
|
continue;
|
|
4054
4474
|
const lhs = m[1];
|
|
4055
|
-
|
|
4475
|
+
let rhs = m[2];
|
|
4056
4476
|
if (JAVA_KEYWORDS.has(lhs))
|
|
4057
4477
|
continue;
|
|
4058
4478
|
if (knownTainted.has(lhs))
|
|
4059
4479
|
continue;
|
|
4480
|
+
if (trackSlots) {
|
|
4481
|
+
const slot = javaSlotRead(rhs, listElems, mapSlots);
|
|
4482
|
+
if (slot !== undefined) {
|
|
4483
|
+
if (slot.some(t => knownTainted.has(t))) {
|
|
4484
|
+
derived.set(lhs, i + 1);
|
|
4485
|
+
knownTainted.add(lhs);
|
|
4486
|
+
changed = true;
|
|
4487
|
+
}
|
|
4488
|
+
continue;
|
|
4489
|
+
}
|
|
4490
|
+
const tern = /^([^?]+?)\s*\?\s*([^:]+?)\s*:\s*(.+)$/.exec(rhs.trim());
|
|
4491
|
+
if (tern) {
|
|
4492
|
+
const decided = evaluatePythonConstExpression(tern[1].trim().replace(/^\((.*)\)$/, '$1'), intConsts);
|
|
4493
|
+
if (decided === true)
|
|
4494
|
+
rhs = tern[2];
|
|
4495
|
+
else if (decided === false)
|
|
4496
|
+
rhs = tern[3];
|
|
4497
|
+
}
|
|
4498
|
+
}
|
|
4060
4499
|
// Reduce the RHS to code positions before matching a tainted var name:
|
|
4061
4500
|
// keep `$"…{expr}"` interpolation contents, drop plain / verbatim string
|
|
4062
4501
|
// literal bodies and char literals. Otherwise a tainted var NAME that
|
|
@@ -4152,8 +4591,15 @@ function findBashTaintSources(sourceCode, dfg) {
|
|
|
4152
4591
|
// Suppressed inside function bodies (#73 part 1).
|
|
4153
4592
|
if (!insideFunction) {
|
|
4154
4593
|
const positionalRe = /\$([1-9@*])|\$\{([1-9@*])\}/g;
|
|
4594
|
+
// A one-line definition `name() { …; }` keeps its body on the header
|
|
4595
|
+
// line: only text before the opening brace is at the top level.
|
|
4596
|
+
const header = /^\s*(?:function\s+)?[A-Za-z_][\w-]*\s*(?:\(\s*\))?\s*\{/.exec(line);
|
|
4597
|
+
const isFnHeader = header !== null && (/\(\s*\)/.test(header[0]) || /^\s*function\s/.test(header[0]));
|
|
4598
|
+
// `$1` inside single quotes is literal text (an awk or sed program), not
|
|
4599
|
+
// a positional parameter.
|
|
4600
|
+
const topLevelText = (isFnHeader ? line.slice(0, header[0].length) : line).replace(/'[^']*'/g, "''");
|
|
4155
4601
|
let m;
|
|
4156
|
-
while ((m = positionalRe.exec(
|
|
4602
|
+
while ((m = positionalRe.exec(topLevelText)) !== null) {
|
|
4157
4603
|
const param = m[1] ?? m[2];
|
|
4158
4604
|
const alreadyExists = sources.some(s => s.line === lineNumber && s.variable === param);
|
|
4159
4605
|
if (!alreadyExists) {
|
|
@@ -4893,6 +5339,39 @@ function findBashRealpathPrefixGuardSanitizers(code) {
|
|
|
4893
5339
|
}
|
|
4894
5340
|
return sanitizers;
|
|
4895
5341
|
}
|
|
5342
|
+
/**
|
|
5343
|
+
* cognium-dev #816 (CVE-2026-8398 `daemon_pkg_install` safe mirror): when a
|
|
5344
|
+
* script downloads a package artifact with curl/wget and later verifies
|
|
5345
|
+
* integrity (gpg/sha) before `dpkg`/`rpm` install, credit the download
|
|
5346
|
+
* step's outbound fetch as gated — same whole-script idiom as
|
|
5347
|
+
* `hasIntegrityVerifierAnywhere` for `unverified-package-install`.
|
|
5348
|
+
*/
|
|
5349
|
+
function findBashVerifiedPackageDownloadSanitizers(code) {
|
|
5350
|
+
const lines = code.split('\n');
|
|
5351
|
+
if (!hasIntegrityVerifierAnywhere(lines)) {
|
|
5352
|
+
return [];
|
|
5353
|
+
}
|
|
5354
|
+
const hasDownload = lines.some((l) => /\b(curl|wget)\b/.test(l));
|
|
5355
|
+
const hasInstall = lines.some((l) => matchUnverifiedPackageInstall(l.trim()) !== null);
|
|
5356
|
+
if (!hasDownload || !hasInstall) {
|
|
5357
|
+
return [];
|
|
5358
|
+
}
|
|
5359
|
+
const sanitizers = [];
|
|
5360
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5361
|
+
const line = lines[i];
|
|
5362
|
+
if (line.trimStart().startsWith('#'))
|
|
5363
|
+
continue;
|
|
5364
|
+
if (!/\b(curl|wget)\b/.test(line))
|
|
5365
|
+
continue;
|
|
5366
|
+
sanitizers.push({
|
|
5367
|
+
type: 'verified_package_download',
|
|
5368
|
+
method: 'curl',
|
|
5369
|
+
line: i + 1,
|
|
5370
|
+
sanitizes: ['ssrf'],
|
|
5371
|
+
});
|
|
5372
|
+
}
|
|
5373
|
+
return sanitizers;
|
|
5374
|
+
}
|
|
4896
5375
|
// ---------------------------------------------------------------------------
|
|
4897
5376
|
// Go safe-handler sanitizer detectors (cognium-dev #102 Sprint 24)
|
|
4898
5377
|
// ---------------------------------------------------------------------------
|
|
@@ -5194,6 +5673,208 @@ function findPythonNetlocAllowlistGuardSanitizers(code) {
|
|
|
5194
5673
|
* or UPPER_SNAKE constants (e.g. MAX_QTY). The guard body must contain
|
|
5195
5674
|
* a terminator.
|
|
5196
5675
|
*/
|
|
5676
|
+
/**
|
|
5677
|
+
* JS/TS numeric range-check guards on Number/parseInt-coerced values
|
|
5678
|
+
* (cognium-dev #816, PAT-INPUT-01 safe mirror; Python twin #114).
|
|
5679
|
+
*
|
|
5680
|
+
* const qty = parseInt(req.query.qty, 10);
|
|
5681
|
+
* if (!Number.isFinite(qty) || qty <= 0) return res.status(400).end();
|
|
5682
|
+
* if (qty > MAX) return res.status(400).end();
|
|
5683
|
+
* res.end(`xfer ${qty}`);
|
|
5684
|
+
*
|
|
5685
|
+
* Coercion strips xss in DEFAULT_SANITIZERS but template interpolation
|
|
5686
|
+
* re-taints; a proven finite + bounded range guard shows the emitted
|
|
5687
|
+
* scalar cannot carry markup.
|
|
5688
|
+
*/
|
|
5689
|
+
function findJsNumericRangeCheckGuardSanitizers(code) {
|
|
5690
|
+
const sanitizers = [];
|
|
5691
|
+
const lines = code.split('\n');
|
|
5692
|
+
const coerceDecl = /^\s*(?:const|let|var)\s+([A-Za-z_]\w*)\s*=\s*(?:Number|parseInt)\s*\(/;
|
|
5693
|
+
const lowerGuard = /\bif\s*\(\s*!(?:Number\.)?isFinite\s*\(\s*([A-Za-z_]\w*)\s*\)|\bif\s*\([^)]*\b([A-Za-z_]\w*)\s*<=\s*0/;
|
|
5694
|
+
const upperGuard = /\bif\s*\(\s*([A-Za-z_]\w*)\s*>\s*(?:\d+|[A-Z][A-Z0-9_]+)\s*\)/;
|
|
5695
|
+
const terminator = /\b(?:return|throw|res\s*\.\s*status\s*\([^)]*\)\s*\.\s*(?:send|end|json))/;
|
|
5696
|
+
const coerced = new Map();
|
|
5697
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5698
|
+
const m = coerceDecl.exec(lines[i]);
|
|
5699
|
+
if (m)
|
|
5700
|
+
coerced.set(m[1], i);
|
|
5701
|
+
}
|
|
5702
|
+
if (coerced.size === 0)
|
|
5703
|
+
return sanitizers;
|
|
5704
|
+
const state = new Map();
|
|
5705
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5706
|
+
const line = lines[i];
|
|
5707
|
+
let varName = null;
|
|
5708
|
+
let kind = null;
|
|
5709
|
+
const low = lowerGuard.exec(line);
|
|
5710
|
+
if (low) {
|
|
5711
|
+
varName = low[1] ?? low[2];
|
|
5712
|
+
kind = 'lower';
|
|
5713
|
+
}
|
|
5714
|
+
else {
|
|
5715
|
+
const up = upperGuard.exec(line);
|
|
5716
|
+
if (up) {
|
|
5717
|
+
varName = up[1];
|
|
5718
|
+
kind = 'upper';
|
|
5719
|
+
}
|
|
5720
|
+
}
|
|
5721
|
+
if (!varName || !kind || !coerced.has(varName))
|
|
5722
|
+
continue;
|
|
5723
|
+
if (!terminator.test(line)) {
|
|
5724
|
+
let bodyHasTerminator = false;
|
|
5725
|
+
let blockEnd = i;
|
|
5726
|
+
let braceDepth = 0;
|
|
5727
|
+
let started = false;
|
|
5728
|
+
const maxScan = Math.min(lines.length, i + 26);
|
|
5729
|
+
for (let j = i; j < maxScan; j++) {
|
|
5730
|
+
const ln = lines[j];
|
|
5731
|
+
for (const ch of ln) {
|
|
5732
|
+
if (ch === '{') {
|
|
5733
|
+
braceDepth++;
|
|
5734
|
+
started = true;
|
|
5735
|
+
}
|
|
5736
|
+
else if (ch === '}') {
|
|
5737
|
+
braceDepth--;
|
|
5738
|
+
if (started && braceDepth === 0) {
|
|
5739
|
+
blockEnd = j;
|
|
5740
|
+
break;
|
|
5741
|
+
}
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
if (j > i && terminator.test(ln))
|
|
5745
|
+
bodyHasTerminator = true;
|
|
5746
|
+
if (started && braceDepth === 0 && blockEnd !== i)
|
|
5747
|
+
break;
|
|
5748
|
+
}
|
|
5749
|
+
if (!bodyHasTerminator && !started)
|
|
5750
|
+
continue;
|
|
5751
|
+
if (!bodyHasTerminator)
|
|
5752
|
+
continue;
|
|
5753
|
+
}
|
|
5754
|
+
const st = state.get(varName) ?? { lower: false, upper: false, lastGuardEnd: i };
|
|
5755
|
+
if (kind === 'lower')
|
|
5756
|
+
st.lower = true;
|
|
5757
|
+
else
|
|
5758
|
+
st.upper = true;
|
|
5759
|
+
st.lastGuardEnd = i;
|
|
5760
|
+
state.set(varName, st);
|
|
5761
|
+
}
|
|
5762
|
+
for (const [varName, st] of state) {
|
|
5763
|
+
if (!st.lower || !st.upper)
|
|
5764
|
+
continue;
|
|
5765
|
+
const varRefRe = new RegExp(`\\b${varName}\\b`);
|
|
5766
|
+
for (let l = st.lastGuardEnd + 1; l < lines.length; l++) {
|
|
5767
|
+
if (!varRefRe.test(lines[l]))
|
|
5768
|
+
continue;
|
|
5769
|
+
sanitizers.push({
|
|
5770
|
+
type: 'js_numeric_range_check_guard',
|
|
5771
|
+
method: 'if',
|
|
5772
|
+
line: l + 1,
|
|
5773
|
+
sanitizes: ['xss', 'external_taint_escape'],
|
|
5774
|
+
});
|
|
5775
|
+
}
|
|
5776
|
+
}
|
|
5777
|
+
return sanitizers;
|
|
5778
|
+
}
|
|
5779
|
+
/**
|
|
5780
|
+
* Rust numeric range-check guards on `.parse()`-coerced values
|
|
5781
|
+
* (cognium-dev #816, PAT-INPUT-01 safe mirror).
|
|
5782
|
+
*
|
|
5783
|
+
* let amount: i32 = amount_str.parse().unwrap_or(0);
|
|
5784
|
+
* if amount <= 0 { return HttpResponse::BadRequest().finish(); }
|
|
5785
|
+
* if amount > MAX { return HttpResponse::BadRequest().finish(); }
|
|
5786
|
+
* HttpResponse::Ok().body(format!("xfer {}", amount))
|
|
5787
|
+
*/
|
|
5788
|
+
function findRustNumericRangeCheckGuardSanitizers(code) {
|
|
5789
|
+
const sanitizers = [];
|
|
5790
|
+
const lines = code.split('\n');
|
|
5791
|
+
const coerceDecl = /^\s*let\s+([A-Za-z_]\w*)\s*(?::\s*(?:i\d+|u\d+|isize|usize))?\s*=\s*[^;]*\.parse\s*(?:\(\s*\)|::<)/;
|
|
5792
|
+
const lowerGuard = /\bif\s+([A-Za-z_]\w*)\s*<=\s*0\b/;
|
|
5793
|
+
const upperGuard = /\bif\s+([A-Za-z_]\w*)\s*>\s*(?:\d+|[A-Z][A-Z0-9_]+)\b/;
|
|
5794
|
+
const terminator = /\b(?:return\s+HttpResponse::|return\s+StatusCode::|return\s+Err\s*\(|panic!\s*\()/;
|
|
5795
|
+
const coerced = new Map();
|
|
5796
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5797
|
+
const m = coerceDecl.exec(lines[i]);
|
|
5798
|
+
if (m)
|
|
5799
|
+
coerced.set(m[1], i);
|
|
5800
|
+
}
|
|
5801
|
+
if (coerced.size === 0)
|
|
5802
|
+
return sanitizers;
|
|
5803
|
+
const state = new Map();
|
|
5804
|
+
for (let i = 0; i < lines.length; i++) {
|
|
5805
|
+
const line = lines[i];
|
|
5806
|
+
let varName = null;
|
|
5807
|
+
let kind = null;
|
|
5808
|
+
const low = lowerGuard.exec(line);
|
|
5809
|
+
if (low) {
|
|
5810
|
+
varName = low[1];
|
|
5811
|
+
kind = 'lower';
|
|
5812
|
+
}
|
|
5813
|
+
else {
|
|
5814
|
+
const up = upperGuard.exec(line);
|
|
5815
|
+
if (up) {
|
|
5816
|
+
varName = up[1];
|
|
5817
|
+
kind = 'upper';
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
if (!varName || !kind || !coerced.has(varName))
|
|
5821
|
+
continue;
|
|
5822
|
+
if (!terminator.test(line)) {
|
|
5823
|
+
let bodyHasTerminator = false;
|
|
5824
|
+
let blockEnd = i;
|
|
5825
|
+
let braceDepth = 0;
|
|
5826
|
+
let started = false;
|
|
5827
|
+
const maxScan = Math.min(lines.length, i + 26);
|
|
5828
|
+
for (let j = i; j < maxScan; j++) {
|
|
5829
|
+
const ln = lines[j];
|
|
5830
|
+
for (const ch of ln) {
|
|
5831
|
+
if (ch === '{') {
|
|
5832
|
+
braceDepth++;
|
|
5833
|
+
started = true;
|
|
5834
|
+
}
|
|
5835
|
+
else if (ch === '}') {
|
|
5836
|
+
braceDepth--;
|
|
5837
|
+
if (started && braceDepth === 0) {
|
|
5838
|
+
blockEnd = j;
|
|
5839
|
+
break;
|
|
5840
|
+
}
|
|
5841
|
+
}
|
|
5842
|
+
}
|
|
5843
|
+
if (j > i && terminator.test(ln))
|
|
5844
|
+
bodyHasTerminator = true;
|
|
5845
|
+
if (started && braceDepth === 0 && blockEnd !== i)
|
|
5846
|
+
break;
|
|
5847
|
+
}
|
|
5848
|
+
if (!bodyHasTerminator && !started)
|
|
5849
|
+
continue;
|
|
5850
|
+
if (!bodyHasTerminator)
|
|
5851
|
+
continue;
|
|
5852
|
+
}
|
|
5853
|
+
const st = state.get(varName) ?? { lower: false, upper: false, lastGuardEnd: i };
|
|
5854
|
+
if (kind === 'lower')
|
|
5855
|
+
st.lower = true;
|
|
5856
|
+
else
|
|
5857
|
+
st.upper = true;
|
|
5858
|
+
st.lastGuardEnd = i;
|
|
5859
|
+
state.set(varName, st);
|
|
5860
|
+
}
|
|
5861
|
+
for (const [varName, st] of state) {
|
|
5862
|
+
if (!st.lower || !st.upper)
|
|
5863
|
+
continue;
|
|
5864
|
+
const varRefRe = new RegExp(`\\b${varName}\\b`);
|
|
5865
|
+
for (let l = st.lastGuardEnd + 1; l < lines.length; l++) {
|
|
5866
|
+
if (!varRefRe.test(lines[l]))
|
|
5867
|
+
continue;
|
|
5868
|
+
sanitizers.push({
|
|
5869
|
+
type: 'rust_numeric_range_check_guard',
|
|
5870
|
+
method: 'if',
|
|
5871
|
+
line: l + 1,
|
|
5872
|
+
sanitizes: ['xss', 'external_taint_escape'],
|
|
5873
|
+
});
|
|
5874
|
+
}
|
|
5875
|
+
}
|
|
5876
|
+
return sanitizers;
|
|
5877
|
+
}
|
|
5197
5878
|
function findPythonRangeCheckGuardSanitizers(code) {
|
|
5198
5879
|
const sanitizers = [];
|
|
5199
5880
|
const lines = code.split('\n');
|
|
@@ -6062,6 +6743,161 @@ function findPythonDefusedXmlSanitizers(code) {
|
|
|
6062
6743
|
}
|
|
6063
6744
|
return sanitizers;
|
|
6064
6745
|
}
|
|
6746
|
+
/**
|
|
6747
|
+
* PAT-INFO-01 safe mirror (cognium-dev #816): `HttpResponse` body built with
|
|
6748
|
+
* `format!` interpolates only `web::Query` / `.get(...)` values — no `env::var`.
|
|
6749
|
+
* Credits the sink so CWE-200-style response leaks stay on env-backed TP controls.
|
|
6750
|
+
*/
|
|
6751
|
+
function findRustPatInfoHttpOnlyResponseSanitizers(code) {
|
|
6752
|
+
const sanitizers = [];
|
|
6753
|
+
const lines = code.split('\n');
|
|
6754
|
+
const bodyFormatRe = /HttpResponse::\w+\(\)\s*\.\s*body\s*\(\s*format!\s*\(/;
|
|
6755
|
+
const envBindRe = /(?:^|[^:])env::var\s*\(|std::env::/;
|
|
6756
|
+
const httpGetRe = /\.get\s*\(\s*"[^"]+"\s*\)/;
|
|
6757
|
+
const letVarRe = (v) => new RegExp(String.raw `^\s*let\s+(?:mut\s+)?${v}\s*=`);
|
|
6758
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6759
|
+
const sinkLine = lines[i];
|
|
6760
|
+
if (!bodyFormatRe.test(sinkLine))
|
|
6761
|
+
continue;
|
|
6762
|
+
if (envBindRe.test(sinkLine))
|
|
6763
|
+
continue;
|
|
6764
|
+
const varRefs = [
|
|
6765
|
+
...sinkLine.matchAll(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g),
|
|
6766
|
+
].map((m) => m[1]);
|
|
6767
|
+
if (varRefs.length === 0)
|
|
6768
|
+
continue;
|
|
6769
|
+
let allHttpOnly = true;
|
|
6770
|
+
for (const v of varRefs) {
|
|
6771
|
+
let sawBinding = false;
|
|
6772
|
+
let boundEnv = false;
|
|
6773
|
+
let boundHttp = false;
|
|
6774
|
+
for (let j = i - 1; j >= Math.max(0, i - 24); j--) {
|
|
6775
|
+
const line = lines[j];
|
|
6776
|
+
if (!letVarRe(v).test(line))
|
|
6777
|
+
continue;
|
|
6778
|
+
sawBinding = true;
|
|
6779
|
+
if (envBindRe.test(line))
|
|
6780
|
+
boundEnv = true;
|
|
6781
|
+
if (httpGetRe.test(line))
|
|
6782
|
+
boundHttp = true;
|
|
6783
|
+
break;
|
|
6784
|
+
}
|
|
6785
|
+
if (!sawBinding || boundEnv || !boundHttp) {
|
|
6786
|
+
allHttpOnly = false;
|
|
6787
|
+
break;
|
|
6788
|
+
}
|
|
6789
|
+
}
|
|
6790
|
+
if (!allHttpOnly)
|
|
6791
|
+
continue;
|
|
6792
|
+
sanitizers.push({
|
|
6793
|
+
type: 'rust_pat_info_http_only_body',
|
|
6794
|
+
method: 'format',
|
|
6795
|
+
line: i + 1,
|
|
6796
|
+
sanitizes: [
|
|
6797
|
+
'xss',
|
|
6798
|
+
'external_taint_escape',
|
|
6799
|
+
'open_redirect',
|
|
6800
|
+
'log_injection',
|
|
6801
|
+
],
|
|
6802
|
+
});
|
|
6803
|
+
}
|
|
6804
|
+
return sanitizers;
|
|
6805
|
+
}
|
|
6806
|
+
/**
|
|
6807
|
+
* Rust `const SLICE: &[&str] = &["a", "b"]` membership reject guard
|
|
6808
|
+
* (cognium-dev #816 PAT-TRUST-01; Python twin #563).
|
|
6809
|
+
*
|
|
6810
|
+
* if !THEMES.contains(&theme.as_str()) {
|
|
6811
|
+
* return HttpResponse::BadRequest().finish();
|
|
6812
|
+
* }
|
|
6813
|
+
* session.insert("theme", theme)
|
|
6814
|
+
*/
|
|
6815
|
+
function collectRustConstStrSliceNames(code) {
|
|
6816
|
+
const names = new Set();
|
|
6817
|
+
const re = /^\s*const\s+([A-Z][A-Z0-9_]*)\s*:\s*&\s*\[\s*&\s*str\s*\]\s*=\s*&\s*\[([^\]]*)\]\s*;/;
|
|
6818
|
+
for (const line of code.split('\n')) {
|
|
6819
|
+
const m = re.exec(line);
|
|
6820
|
+
if (!m)
|
|
6821
|
+
continue;
|
|
6822
|
+
const inner = m[2].trim();
|
|
6823
|
+
if (!inner) {
|
|
6824
|
+
names.add(m[1]);
|
|
6825
|
+
continue;
|
|
6826
|
+
}
|
|
6827
|
+
const elems = inner.split(',').map(s => s.trim()).filter(Boolean);
|
|
6828
|
+
if (elems.every(e => /^"(?:[^"\\]|\\.)*"$/.test(e)))
|
|
6829
|
+
names.add(m[1]);
|
|
6830
|
+
}
|
|
6831
|
+
return names;
|
|
6832
|
+
}
|
|
6833
|
+
function findRustConstSliceMembershipGuardSanitizers(code) {
|
|
6834
|
+
const sanitizers = [];
|
|
6835
|
+
const slices = collectRustConstStrSliceNames(code);
|
|
6836
|
+
if (slices.size === 0)
|
|
6837
|
+
return sanitizers;
|
|
6838
|
+
const lines = code.split('\n');
|
|
6839
|
+
const guardOpen = /^\s*if\s+!\s*([A-Z][A-Z0-9_]*)\s*\.\s*contains\s*\(\s*&\s*([A-Za-z_]\w*)(?:\s*\.\s*as_str\s*\(\s*\))?\s*\)\s*\{?\s*$/;
|
|
6840
|
+
const terminator = /\b(?:return\s+HttpResponse::|return\s+StatusCode::|return\s+Err\s*\(|panic!\s*\()/;
|
|
6841
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6842
|
+
const m = guardOpen.exec(lines[i]);
|
|
6843
|
+
if (!m)
|
|
6844
|
+
continue;
|
|
6845
|
+
const sliceName = m[1];
|
|
6846
|
+
const guardedVar = m[2];
|
|
6847
|
+
if (!slices.has(sliceName))
|
|
6848
|
+
continue;
|
|
6849
|
+
let depth = 0;
|
|
6850
|
+
for (const ch of lines[i]) {
|
|
6851
|
+
if (ch === '{')
|
|
6852
|
+
depth++;
|
|
6853
|
+
else if (ch === '}')
|
|
6854
|
+
depth--;
|
|
6855
|
+
}
|
|
6856
|
+
let closeLine = i;
|
|
6857
|
+
let bodyHasTerminator = terminator.test(lines[i]);
|
|
6858
|
+
if (depth > 0) {
|
|
6859
|
+
for (let j = i + 1; j < Math.min(lines.length, i + 26); j++) {
|
|
6860
|
+
if (terminator.test(lines[j]))
|
|
6861
|
+
bodyHasTerminator = true;
|
|
6862
|
+
for (const ch of lines[j]) {
|
|
6863
|
+
if (ch === '{')
|
|
6864
|
+
depth++;
|
|
6865
|
+
else if (ch === '}')
|
|
6866
|
+
depth--;
|
|
6867
|
+
}
|
|
6868
|
+
if (depth === 0) {
|
|
6869
|
+
closeLine = j;
|
|
6870
|
+
break;
|
|
6871
|
+
}
|
|
6872
|
+
}
|
|
6873
|
+
}
|
|
6874
|
+
if (!bodyHasTerminator)
|
|
6875
|
+
continue;
|
|
6876
|
+
const varRe = new RegExp(String.raw `\b${guardedVar}\b`);
|
|
6877
|
+
const reassign = new RegExp(String.raw `^\s*(?:let\s+)?(?:mut\s+)?${guardedVar}\s*=(?!=)`);
|
|
6878
|
+
for (let l = closeLine + 2; l <= lines.length; l++) {
|
|
6879
|
+
const lineText = lines[l - 1];
|
|
6880
|
+
if (!lineText || !varRe.test(lineText))
|
|
6881
|
+
continue;
|
|
6882
|
+
if (reassign.test(lineText))
|
|
6883
|
+
break;
|
|
6884
|
+
sanitizers.push({
|
|
6885
|
+
type: 'rust_const_slice_membership_guard',
|
|
6886
|
+
method: 'if',
|
|
6887
|
+
line: l,
|
|
6888
|
+
sanitizes: [
|
|
6889
|
+
'trust_boundary',
|
|
6890
|
+
'external_taint_escape',
|
|
6891
|
+
'xss',
|
|
6892
|
+
'open_redirect',
|
|
6893
|
+
'ssrf',
|
|
6894
|
+
'command_injection',
|
|
6895
|
+
],
|
|
6896
|
+
});
|
|
6897
|
+
}
|
|
6898
|
+
}
|
|
6899
|
+
return sanitizers;
|
|
6900
|
+
}
|
|
6065
6901
|
/**
|
|
6066
6902
|
* Detect Rust HashSet/HashMap host allow-list guards (cognium-dev #115 FP-23).
|
|
6067
6903
|
*
|
|
@@ -6333,6 +7169,16 @@ function findJsCsvFormulaPrefixSanitizers(code) {
|
|
|
6333
7169
|
* threat-set. Custom wrappers using different escape strategies (e.g.
|
|
6334
7170
|
* URL encode) are not yet covered.
|
|
6335
7171
|
*/
|
|
7172
|
+
/** Return expression of a small JS wrapper (function or arrow) for #562 chain verdict. */
|
|
7173
|
+
function jsWrapperBodyReplaceChainText(body) {
|
|
7174
|
+
const returnM = /\breturn\s+([^;}\n]+)/.exec(body);
|
|
7175
|
+
if (returnM)
|
|
7176
|
+
return returnM[1].trim();
|
|
7177
|
+
const arrowM = /=>\s*([^;}\n]+)/.exec(body);
|
|
7178
|
+
if (arrowM)
|
|
7179
|
+
return arrowM[1].trim();
|
|
7180
|
+
return null;
|
|
7181
|
+
}
|
|
6336
7182
|
function findJsWrapperFunctionSanitizers(code) {
|
|
6337
7183
|
const sanitizers = [];
|
|
6338
7184
|
const lines = code.split('\n');
|
|
@@ -6355,8 +7201,13 @@ function findJsWrapperFunctionSanitizers(code) {
|
|
|
6355
7201
|
kinds.add('external_taint_escape');
|
|
6356
7202
|
}
|
|
6357
7203
|
if (crlfCharClass.test(body)) {
|
|
6358
|
-
|
|
6359
|
-
|
|
7204
|
+
const chainText = jsWrapperBodyReplaceChainText(body);
|
|
7205
|
+
const verdict = chainText ? jsReplaceChainVerdict(chainText) : 'undecided';
|
|
7206
|
+
// #562 / #605: LF-only or CRLF-pair-only strips must not credit log_injection.
|
|
7207
|
+
if (verdict !== 'leaves-crlf') {
|
|
7208
|
+
kinds.add('log_injection');
|
|
7209
|
+
kinds.add('external_taint_escape');
|
|
7210
|
+
}
|
|
6360
7211
|
}
|
|
6361
7212
|
if (kinds.size > 0)
|
|
6362
7213
|
wrappers.set(name, kinds);
|
|
@@ -7765,6 +8616,87 @@ function javaBodyStripsCrAndLf(body) {
|
|
|
7765
8616
|
}
|
|
7766
8617
|
return cr && lf;
|
|
7767
8618
|
}
|
|
8619
|
+
/** True when the helper removes both `{` and `}` via replace/replaceAll (flow-sanitize ssti). */
|
|
8620
|
+
function javaBodyStripsTemplateDelimiters(body) {
|
|
8621
|
+
let open = false;
|
|
8622
|
+
let close = false;
|
|
8623
|
+
for (const m of body.matchAll(/\.\s*(replace|replaceAll)\s*\(\s*(?:"((?:\\.|[^"\\])*)"|'(\\.|[^'\\])')/g)) {
|
|
8624
|
+
const lit = m[2] ?? m[3] ?? '';
|
|
8625
|
+
if (lit === '{')
|
|
8626
|
+
open = true;
|
|
8627
|
+
if (lit === '}')
|
|
8628
|
+
close = true;
|
|
8629
|
+
}
|
|
8630
|
+
return open && close;
|
|
8631
|
+
}
|
|
8632
|
+
/**
|
|
8633
|
+
* Java user-defined wrapper that strips Velocity/Jinja-style `{` `}` delimiters.
|
|
8634
|
+
* Mirrors flow-sanitize `ssti` / `custom_wrapper` safe mirrors (cognium-dev#947).
|
|
8635
|
+
*/
|
|
8636
|
+
function findJavaTemplateDelimiterWrapperSanitizers(code) {
|
|
8637
|
+
const sanitizers = [];
|
|
8638
|
+
const lines = code.split('\n');
|
|
8639
|
+
const declRe = /^\s*(?:public|private|protected)?\s*(?:static\s+)?(?:final\s+)?(?:String|CharSequence)\s+([A-Za-z_]\w*)\s*\(/;
|
|
8640
|
+
const bodyWindow = 10;
|
|
8641
|
+
const wrappers = new Set();
|
|
8642
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8643
|
+
const m = declRe.exec(lines[i]);
|
|
8644
|
+
if (!m)
|
|
8645
|
+
continue;
|
|
8646
|
+
let end = Math.min(lines.length, i + bodyWindow);
|
|
8647
|
+
for (let j = i + 1; j < end; j++) {
|
|
8648
|
+
if (declRe.test(lines[j])) {
|
|
8649
|
+
end = j;
|
|
8650
|
+
break;
|
|
8651
|
+
}
|
|
8652
|
+
}
|
|
8653
|
+
const body = lines.slice(i, end).join('\n');
|
|
8654
|
+
if (javaBodyStripsTemplateDelimiters(body))
|
|
8655
|
+
wrappers.add(m[1]);
|
|
8656
|
+
}
|
|
8657
|
+
if (wrappers.size === 0)
|
|
8658
|
+
return sanitizers;
|
|
8659
|
+
const kinds = ['code_injection', 'external_taint_escape'];
|
|
8660
|
+
for (const name of wrappers) {
|
|
8661
|
+
const assignedCallRe = new RegExp(`\\b([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*${name}\\s*\\(`);
|
|
8662
|
+
const bareCallRe = new RegExp(`\\b${name}\\s*\\(`);
|
|
8663
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8664
|
+
if (!bareCallRe.test(lines[i]))
|
|
8665
|
+
continue;
|
|
8666
|
+
if (declRe.test(lines[i]) && bareCallRe.test(lines[i]))
|
|
8667
|
+
continue;
|
|
8668
|
+
sanitizers.push({
|
|
8669
|
+
type: 'java_wrapper_template_delim_strip',
|
|
8670
|
+
method: name,
|
|
8671
|
+
line: i + 1,
|
|
8672
|
+
sanitizes: [...kinds],
|
|
8673
|
+
});
|
|
8674
|
+
const am = assignedCallRe.exec(lines[i]);
|
|
8675
|
+
if (!am)
|
|
8676
|
+
continue;
|
|
8677
|
+
const callIndent = lines[i].length - lines[i].trimStart().length;
|
|
8678
|
+
const validated = am[1];
|
|
8679
|
+
const validatedRe = new RegExp(`\\b${validated}\\b`);
|
|
8680
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
8681
|
+
const jline = lines[j];
|
|
8682
|
+
if (jline.trim() === '')
|
|
8683
|
+
continue;
|
|
8684
|
+
const jindent = jline.length - jline.trimStart().length;
|
|
8685
|
+
if (jindent < callIndent)
|
|
8686
|
+
break;
|
|
8687
|
+
if (validatedRe.test(jline)) {
|
|
8688
|
+
sanitizers.push({
|
|
8689
|
+
type: 'java_wrapper_template_delim_strip',
|
|
8690
|
+
method: name,
|
|
8691
|
+
line: j + 1,
|
|
8692
|
+
sanitizes: [...kinds],
|
|
8693
|
+
});
|
|
8694
|
+
}
|
|
8695
|
+
}
|
|
8696
|
+
}
|
|
8697
|
+
}
|
|
8698
|
+
return sanitizers;
|
|
8699
|
+
}
|
|
7768
8700
|
function findCrlfWrapperFunctionSanitizers(code, language) {
|
|
7769
8701
|
const sanitizers = [];
|
|
7770
8702
|
const lines = code.split('\n');
|
|
@@ -11196,6 +12128,108 @@ export function findJsLdapInjectionFindings(code, file) {
|
|
|
11196
12128
|
snippet: line.trim(),
|
|
11197
12129
|
});
|
|
11198
12130
|
}
|
|
12131
|
+
// cognium-dev #899: ldapjs also accepts the filter as the 2nd positional
|
|
12132
|
+
// argument (`client.search(base, '(mail=' + email + ')', cb)`), not only
|
|
12133
|
+
// as `opts.filter`. Flag when that argument is built from tainted data.
|
|
12134
|
+
// Base DN is often comma-separated; only match a quoted first argument.
|
|
12135
|
+
const positionalSearchRe = /\.\s*search\s*\(\s*(?:'[^']*'|"[^"]*")\s*,\s*([^,{]+)/;
|
|
12136
|
+
for (let i = 0; i < lines.length; i++) {
|
|
12137
|
+
const line = lines[i];
|
|
12138
|
+
const pm = line.match(positionalSearchRe);
|
|
12139
|
+
if (!pm)
|
|
12140
|
+
continue;
|
|
12141
|
+
const expr = pm[1].trim();
|
|
12142
|
+
if (expr.startsWith('{'))
|
|
12143
|
+
continue;
|
|
12144
|
+
let tainted = false;
|
|
12145
|
+
for (const v of taintedVars) {
|
|
12146
|
+
if (new RegExp(`\\b${v}\\b`).test(expr)) {
|
|
12147
|
+
tainted = true;
|
|
12148
|
+
break;
|
|
12149
|
+
}
|
|
12150
|
+
}
|
|
12151
|
+
if (!tainted)
|
|
12152
|
+
continue;
|
|
12153
|
+
const lineNo = i + 1;
|
|
12154
|
+
if (seen.has(lineNo))
|
|
12155
|
+
continue;
|
|
12156
|
+
seen.add(lineNo);
|
|
12157
|
+
findings.push({
|
|
12158
|
+
id: `ldap_injection-${file}-${lineNo}-js-ldap-positional-filter`,
|
|
12159
|
+
pass: 'language-sources',
|
|
12160
|
+
category: 'security',
|
|
12161
|
+
rule_id: 'ldap_injection',
|
|
12162
|
+
cwe: 'CWE-90',
|
|
12163
|
+
severity: 'critical',
|
|
12164
|
+
level: 'error',
|
|
12165
|
+
message: 'LDAP injection: ldapjs/ldapts `client.search(base, <tainted-filter>, ...)` ' +
|
|
12166
|
+
'lets the attacker break out of the filter expression. Escape user input ' +
|
|
12167
|
+
'or use a structured filter builder.',
|
|
12168
|
+
file,
|
|
12169
|
+
line: lineNo,
|
|
12170
|
+
snippet: line.trim(),
|
|
12171
|
+
});
|
|
12172
|
+
}
|
|
12173
|
+
return findings;
|
|
12174
|
+
}
|
|
12175
|
+
/**
|
|
12176
|
+
* cognium-dev #897 — ZIP local-file-header validation that fail-opens: after
|
|
12177
|
+
* rejecting an invalid PK\\x03\\x04 signature, returning a slice of the caller
|
|
12178
|
+
* buffer instead of throwing lets untrusted bytes through (CWE-20).
|
|
12179
|
+
*/
|
|
12180
|
+
export function findJsZipHeaderFailopenFindings(code, file) {
|
|
12181
|
+
const findings = [];
|
|
12182
|
+
if (typeof code !== 'string' || code.length === 0)
|
|
12183
|
+
return findings;
|
|
12184
|
+
const lines = code.split('\n');
|
|
12185
|
+
const hasPkLocalSig = lines.some((l) => {
|
|
12186
|
+
const t = l.trim();
|
|
12187
|
+
if (t.startsWith('//'))
|
|
12188
|
+
return false;
|
|
12189
|
+
return (/0x50/.test(t) &&
|
|
12190
|
+
/0x4[bB]/.test(t) &&
|
|
12191
|
+
/0x03/.test(t) &&
|
|
12192
|
+
/0x04/.test(t));
|
|
12193
|
+
});
|
|
12194
|
+
if (!hasPkLocalSig)
|
|
12195
|
+
return findings;
|
|
12196
|
+
const seen = new Set();
|
|
12197
|
+
for (let i = 0; i < lines.length; i++) {
|
|
12198
|
+
const trimmed = lines[i].trim();
|
|
12199
|
+
if (trimmed.startsWith('//'))
|
|
12200
|
+
continue;
|
|
12201
|
+
const failBranch = trimmed.match(/^if\s*\(\s*!(\w+)\s*\)\s*(.+)$/);
|
|
12202
|
+
if (!failBranch)
|
|
12203
|
+
continue;
|
|
12204
|
+
const tail = failBranch[2];
|
|
12205
|
+
if (/\bthrow\b/.test(tail))
|
|
12206
|
+
continue;
|
|
12207
|
+
if (!/\breturn\b/.test(tail))
|
|
12208
|
+
continue;
|
|
12209
|
+
if (!/\.(subarray|slice)\s*\(/.test(tail) &&
|
|
12210
|
+
!/Buffer\.from\s*\(/.test(tail)) {
|
|
12211
|
+
continue;
|
|
12212
|
+
}
|
|
12213
|
+
const lineNo = i + 1;
|
|
12214
|
+
if (seen.has(lineNo))
|
|
12215
|
+
continue;
|
|
12216
|
+
seen.add(lineNo);
|
|
12217
|
+
findings.push({
|
|
12218
|
+
id: `input_validation-${file}-${lineNo}-js-zip-header-failopen`,
|
|
12219
|
+
pass: 'language-sources',
|
|
12220
|
+
category: 'security',
|
|
12221
|
+
rule_id: 'input_validation',
|
|
12222
|
+
cwe: 'CWE-20',
|
|
12223
|
+
severity: 'high',
|
|
12224
|
+
level: 'error',
|
|
12225
|
+
message: 'Input validation fail-open: an invalid ZIP local header check still ' +
|
|
12226
|
+
'returns a slice of the caller-controlled buffer. On parse failure, ' +
|
|
12227
|
+
'throw or return empty — do not pass through untrusted bytes.',
|
|
12228
|
+
file,
|
|
12229
|
+
line: lineNo,
|
|
12230
|
+
snippet: trimmed.substring(0, 120),
|
|
12231
|
+
});
|
|
12232
|
+
}
|
|
11199
12233
|
return findings;
|
|
11200
12234
|
}
|
|
11201
12235
|
/**
|
|
@@ -11845,6 +12879,53 @@ export function findGoGobDeserializationFindings(code, file) {
|
|
|
11845
12879
|
}
|
|
11846
12880
|
return findings;
|
|
11847
12881
|
}
|
|
12882
|
+
/**
|
|
12883
|
+
* Blank the contents of JS/TS string and template literals and comments,
|
|
12884
|
+
* keeping newlines and every offset, so a line scanner does not match code
|
|
12885
|
+
* that only appears as text (a message describing `JSON.parse(req.body)`).
|
|
12886
|
+
*/
|
|
12887
|
+
function maskJsLiteralsAndComments(code) {
|
|
12888
|
+
const out = code.split('');
|
|
12889
|
+
let i = 0;
|
|
12890
|
+
const blank = (from, to) => {
|
|
12891
|
+
for (let k = from; k < to; k++)
|
|
12892
|
+
if (out[k] !== '\n')
|
|
12893
|
+
out[k] = ' ';
|
|
12894
|
+
};
|
|
12895
|
+
while (i < code.length) {
|
|
12896
|
+
const c = code[i];
|
|
12897
|
+
const n = code[i + 1];
|
|
12898
|
+
if (c === '/' && n === '/') {
|
|
12899
|
+
let j = i;
|
|
12900
|
+
while (j < code.length && code[j] !== '\n')
|
|
12901
|
+
j++;
|
|
12902
|
+
blank(i, j);
|
|
12903
|
+
i = j;
|
|
12904
|
+
}
|
|
12905
|
+
else if (c === '/' && n === '*') {
|
|
12906
|
+
const end = code.indexOf('*/', i + 2);
|
|
12907
|
+
const j = end < 0 ? code.length : end + 2;
|
|
12908
|
+
blank(i, j);
|
|
12909
|
+
i = j;
|
|
12910
|
+
}
|
|
12911
|
+
else if (c === '"' || c === "'" || c === '`') {
|
|
12912
|
+
let j = i + 1;
|
|
12913
|
+
while (j < code.length && code[j] !== c) {
|
|
12914
|
+
if (code[j] === '\\')
|
|
12915
|
+
j++;
|
|
12916
|
+
else if (c !== '`' && code[j] === '\n')
|
|
12917
|
+
break;
|
|
12918
|
+
j++;
|
|
12919
|
+
}
|
|
12920
|
+
blank(i + 1, Math.min(j, code.length));
|
|
12921
|
+
i = j + 1;
|
|
12922
|
+
}
|
|
12923
|
+
else {
|
|
12924
|
+
i++;
|
|
12925
|
+
}
|
|
12926
|
+
}
|
|
12927
|
+
return out.join('');
|
|
12928
|
+
}
|
|
11848
12929
|
/**
|
|
11849
12930
|
* Sprint 89 detector B (#189) — JS insecure deserialization via
|
|
11850
12931
|
* `JSON.parse(req.body)`.
|
|
@@ -11900,13 +12981,14 @@ export function findJsJsonParseBodyFindings(code, file) {
|
|
|
11900
12981
|
}
|
|
11901
12982
|
const callRe = /\bJSON\s*\.\s*parse\s*\(\s*([^)]+?)\s*\)/g;
|
|
11902
12983
|
const seen = new Set();
|
|
12984
|
+
// Calls only: `JSON.parse(req.body)` inside a string or comment is text.
|
|
12985
|
+
const codeLines = maskJsLiteralsAndComments(code).split('\n');
|
|
11903
12986
|
for (let i = 0; i < lines.length; i++) {
|
|
11904
12987
|
const line = lines[i];
|
|
11905
|
-
|
|
11906
|
-
continue;
|
|
12988
|
+
const codeLine = codeLines[i] ?? '';
|
|
11907
12989
|
callRe.lastIndex = 0;
|
|
11908
12990
|
let m;
|
|
11909
|
-
while ((m = callRe.exec(
|
|
12991
|
+
while ((m = callRe.exec(codeLine)) !== null) {
|
|
11910
12992
|
const arg = m[1];
|
|
11911
12993
|
let tainted = reqBodyRe.test(arg);
|
|
11912
12994
|
if (!tainted) {
|