Repository navigation
JavaScript: preserve sanitizer barriers on guarded phi inputs - #23005
Open
nikhilred2619 wants to merge 3 commits into
Open
nikhilred2619 wants to merge 3 commits into
nikhilred2619 wants to merge 3 commits into
Conversation
| nd = DataFlow::valueNode(use) | ||
| ) | ||
| or | ||
| exists(BarrierGuard guard, DataFlowPrivate::SsaPhiInputNode input | |
| override Location getLocation() { result = expr.getLocation() } | ||
| } | ||
|
|
||
| /** One incoming edge of an SSA phi, represented as a node so guards can block it. */ |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Captured-variable phi inputs are assigned to the wrong callable, breaking local flow and discarding call context, while the regression test lacks a recognized remote-input source.
3 open issues
What changed in this PR
Addresses #22848 by preserving branch-specific sanitizer guards when JavaScript and TypeScript values merge after fallback assignments, reducing false-positive security alerts.
Changes:
- Introduces guarded phi-input nodes while retaining direct flow for unguarded inputs.
- Adds fixtures for safe fallbacks, loops, incorrect guards, reflected XSS, and resource exhaustion.
- Refreshes expected results, removes an existing spurious shell-command alert, and adds a change note.
| File | Description |
|---|---|
javascript/ql/test/query-tests/Security/CWE-770/ResourceExhaustion/resource-exhaustion.js |
Adds a clamped-allocation scenario. |
javascript/ql/test/query-tests/Security/CWE-079/ReflectedXss/ReflectedXssGood.js |
Adds allowlist and regular-expression fallback scenarios. |
javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.expected |
Removes the spurious alert and related path output. |
javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction/lib/lib.js |
Changes the expectation comment to mark the sanitized command as safe. |
javascript/ql/test/library-tests/TaintTracking/sanitizer-guards.js |
Adds guarded-merge regression fixtures. |
javascript/ql/test/library-tests/TaintTracking/DataFlowTracking.expected |
Refreshes data-flow results and removes a resolved legacy mismatch. |
javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected |
Refreshes taint-flow results for the guard fixtures. |
javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowPrivate.qll |
Defines synthetic phi-input data-flow nodes. |
javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll |
Creates phi-input nodes for guarded predecessors. |
javascript/ql/lib/semmle/javascript/dataflow/internal/BarrierGuards.qll |
Applies sanitizer barriers to individual phi inputs. |
javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll |
Splits guarded phi edges while retaining direct unguarded flow. |
javascript/ql/lib/semmle/javascript/dataflow/Configuration.qll |
Adapts legacy edge barriers to phi-input nodes. |
javascript/ql/lib/change-notes/2026-11-03-sanitizer-guard-phi-inputs.md |
Documents the sanitizer-guard improvement. |
Review effort: Max (auto)
| override string toString() { result = "[ssa-phi-input] " + phi.toString() } | ||
|
|
||
| cached | ||
| override StmtContainer getContainer() { result = phi.getSourceVariable().getDeclaringContainer() } |
Comment on lines
+107
to
+113
| function clampedAllocation(req) { | ||
| let n = parseInt(req.query.n); | ||
| if (n > 1024) { | ||
| n = 1024; | ||
| } | ||
| Buffer.alloc(n); // OK - n is at most 1024 (or an invalid allocation size) | ||
| } |
Comment on lines
+1746
to
+1748
| exists(SsaPhiNode phi, BasicBlock bb | | ||
| pred = TSsaDefNode(phi.getInputFromBlock(bb).getDefinition()) and | ||
| succ = TSsaPhiInputNode(phi, bb) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #22848.
This change fixes false positives caused by sanitizer guards being lost across SSA phi inputs.
The fix preserves branch-specific barriers while keeping direct flow edges for inputs without a dominating condition.
I also added regression tests covering safe fallbacks, guarded loops, incorrect guard conditions, reflected XSS, and resource exhaustion. The existing spurious alert in
UnsafeShellCommandConstructionis removed.Testing: All 21 affected tests passed locally.
Related PR: #22873 addresses the same underlying issue. This version additionally limits synthetic phi-input nodes to guarded predecessor blocks and includes broader regression coverage.
Happy to make any adjustments based on feedback.