Skip to content

JS: Require string base in SanitizedChar - #23129

Open
sam-robson wants to merge 1 commit into
mainfrom
sam-robson/js-sanitizedchar-array
Open

sam-robson wants to merge 1 commit into
mainfrom
sam-robson/js-sanitizedchar-array

Conversation

@sam-robson

@sam-robson sam-robson commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #23123

SanitizedChar treats s[i] as sanitized when equality guards exclude each character in getAShellChar() and i is a number. It does not check the type of s, so an array element bypasses the single-character checks:

s = ["x; touch /tmp/marker"]
  s[0] === ";"   // false, whole element reaches sink, no alert

Require s to have inferred type string:

     SanitizedChar() {
       exists(AccessPath ap | this.asExpr() = ap.getAnInstance() |
         forall(string char | char = getAShellChar() | blocksCharInAccess(ap, char, astNode))
       ) and
-      astNode.getPropertyNameExpr().analyze().getTheType() = TTNumber()
+      astNode.getPropertyNameExpr().analyze().getTheType() = TTNumber() and
+      astNode.getBase().analyze().getTheType() = TTString()
     }

@sam-robson
sam-robson force-pushed the sam-robson/js-sanitizedchar-array branch from 9db3006 to 84fa714 Compare November 13, 2026 14:55
@sam-robson
sam-robson marked this pull request as ready for review November 13, 2026 14:56
@sam-robson
sam-robson requested a review from a team as a code owner November 13, 2026 14:56
Copilot AI dynamic review requested due to automatic review settings November 13, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A duplicate sanitizeShellString declaration overrides the original fixture helper, and the production sanitizer-classification change lacks DCA results to assess unexpected alert changes.

2 open issues
What changed in this PR

Tightens JavaScript shell-command sanitizer recognition so array elements are not mistaken for sanitized single characters.

Changes:

  • Requires SanitizedChar to have an inferred string base.
  • Adds string-type regression cases and updates expected alerts and data-flow paths.
  • Documents the detection change and possible false positives around string conversions.
File Description
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​UnsafeShellCommandConstruction/​UnsafeShellCommandConstruction.expected Updates expected alerts and data-flow paths.
javascript/​ql/​test/​query-tests/​Security/​CWE-078/​UnsafeShellCommandConstruction/​lib/​lib.js Adds string-type regression cases and adjusts alert annotations.
javascript/​ql/​lib/​semmle/​javascript/​security/​dataflow/​UnsafeShellCommandConstructionCustomizations.qll Requires a string base for SanitizedChar.
javascript/​ql/​lib/​change-notes/​2026-11-13-sanitized-char-string-base.md Documents detection changes and string-conversion limitations.

Review effort: Max (dynamic)

) and
astNode.getPropertyNameExpr().analyze().getTheType() = TTNumber()
astNode.getPropertyNameExpr().analyze().getTheType() = TTNumber() and
astNode.getBase().analyze().getTheType() = TTString()

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test does not isolate the intended type-inference limitation, and the production query change lacks DCA evidence assessing downstream alert changes or regressions.

2 open issues
1 resolved since last review

Review effort: Max (dynamic)

}

module.exports.sanitizedCharStringChecks = function (name) { // $ Source
cp.exec("rm -rf " + yetAnohterSanitizer(String(name))); // $ SPURIOUS: Alert - String(...) is not modeled by type inference
@sam-robson
sam-robson force-pushed the sam-robson/js-sanitizedchar-array branch from 3b3e6b6 to ef9e463 Compare November 13, 2026 17:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS: Should SanitizedChar apply when the sanitized value can be an array, as in the systeminformation sanitizer bypassed by CVE-2021-21315?

2 participants