Repository navigation
Conversation
| * statements so their reflective uncertainty does not propagate to later reads. | ||
| * Security flow must instead visit those reads so their barriers remain effective. | ||
| */ | ||
| predicate localFlowStepForTypeInference(EarlyStageNode pred, EarlyStageNode succ) { |
owen-mc
force-pushed
the
experiments/js-shared-ssa
branch
from
October 29, 2026 16:04
d8a3801 to
fda35fc
Compare
owen-mc
force-pushed
the
experiments/js-shared-ssa
branch
from
November 19, 2026 17:48
fda35fc to
c11c472
Compare
Add migration regression and consistency tests before changing the implementation. Mark main's known missing and spurious results inline, and record its current consistency-query output. Use main's existing internal node names and compare public and native definition coordinates so these tests compile before the migration. The integration commit switches representation-specific checks to native shared definitions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add opt-in `includePhiDefsInFlowStep()` support in `DataFlowIntegration` so language libraries can retain data flow nodes for phi definitions even when they have a unique next reference. Propagate barrier guards and phi read liveness across value-preserving uncertain definitions and phi nodes whose control-flow paths all preserve an ancestor definition, such as compound refinement conditions and loops containing refinements. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use shared SSA for definitions, refinements, captures, and local/global data flow. Remove standalone JavaScript liveness, phi insertion, and reaching-definition computation while preserving the public SSA APIs as shared-backed adapters. Register post-update completion positions via `SsaConfig::postUpdateRead` so post-updates take effect after call and assignment completion without adding intermediate reads along ordinary reference chains, and preserve updates across value-preserving reassignments using modeled may-value flow. Keep global continuing-value reads internal so synthesized SSA reads do not leak through `flowsTo`, `getALocalSource`, `analyze`, or `AccessPath::getAReferenceTo`, preserve captured-variable and legacy `Configuration` barrier-guard behavior, and restrict reflective `with`-read shortcuts to type inference. Avoid large intermediate joins in capture-point construction, variable refinement lookup, l-value mapping, and captured assignment inference, add direct SSA definition-to-read steps for type inference, and consolidate cached SSA adapters into `SsaCachedStage`. Update test expectations and add a change note. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
owen-mc
force-pushed
the
experiments/js-shared-ssa
branch
from
November 20, 2026 23:56
88843b1 to
7127c4f
Compare
owen-mc
marked this pull request as ready for review
November 20, 2026 23:57
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical SSA modeling defects can suppress security-relevant data flow and retain invalid guards across writes and await suspension.
8 open issues
Recapture closure variables across await expressions · New Resolve parenthesized values for post-update continuations · New Model accessor updates before call and assignment operands · New Treat with-scope writes and shadowed reads as uncertain · New Model logical compound assignments as variable writes · New Separate value-preserving writes from old-value flow flags · New Close filteredPhiInputWithReplacement before subsequent tests · New Stop the loop-phi preservation base case at the ancestor · New
What changed in this PR
Completes the JavaScript and TypeScript migration to shared SSA, replacing the standalone implementation while retaining public SSA APIs as adapters. The migration updates variable flow, barrier guards, type inference, and post-update ordering.
Changes:
- Extends shared SSA with phi-definition retention and guard propagation through value-preserving definitions.
- Moves JavaScript flow integration onto shared SSA and places post-updates at operation completion.
- Adds compatibility and invariant tests, updates analysis expectations, and documents the migration.
| File | Description |
|---|---|
shared/ssa/codeql/ssa/Ssa.qll |
Adds phi retention and value-preserving guard propagation. |
shared/ssa/change-notes/2026-11-19-refinement-barrier-guards.md |
Documents refinement-aware barrier propagation. |
shared/ssa/change-notes/2026-11-19-include-phi-defs-in-flow-step.md |
Documents the phi-retention option. |
javascript/ql/test/query-tests/Security/CWE-915/PrototypePollutingFunction/tests.js |
Removes alert annotations from a guarded case. |
javascript/ql/test/query-tests/Security/CWE-915/PrototypePollutingFunction/PrototypePollutingFunction.expected |
Updates prototype-pollution results and paths. |
javascript/ql/test/query-tests/Security/CWE-089/untyped/SqlInjection.expected |
Updates results for the guarded version input. |
javascript/ql/test/query-tests/Security/CWE-089/untyped/koarouter.js |
Removes source and alert annotations only. |
javascript/ql/test/query-tests/Security/CWE-079/DomBasedXss/XssWithAdditionalSources.expected |
Removes premature post-update flow paths. |
javascript/ql/test/query-tests/Security/CWE-079/DomBasedXss/Xss.expected |
Updates XSS paths for post-update ordering. |
javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction/UnsafeShellCommandConstruction.expected |
Updates results for guarded sanitization. |
javascript/ql/test/query-tests/Security/CWE-078/UnsafeShellCommandConstruction/lib/lib.js |
Removes a resolved spurious-alert annotation. |
javascript/ql/test/query-tests/Security/CWE-078/SecondOrderCommandInjection/SecondOrderCommandInjection.expected |
Records revised guarded and unchecked-input results. |
javascript/ql/test/query-tests/Security/CWE-078/SecondOrderCommandInjection/second-order.js |
Separates joined guard behavior from unchecked input. |
javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/TaintedPath.expected |
Updates compound-prefix guard results. |
javascript/ql/test/query-tests/Security/CWE-022/TaintedPath/normalizedPaths.js |
Removes a spurious-alert annotation only. |
javascript/ql/test/library-tests/TaintTracking/sanitizer-guards.js |
Removes the resolved phi-edge inconsistency comment. |
javascript/ql/test/library-tests/TaintTracking/DataFlowTracking.expected |
Updates phi and compound-guard flow results. |
javascript/ql/test/library-tests/TaintTracking/booleanOps.js |
Removes the resolved compound-guard inconsistency comment. |
javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected |
Updates taint results for improved guards. |
javascript/ql/test/library-tests/SharedSsaCompatibility/tst.js |
Adds a public phi-source compatibility fixture. |
javascript/ql/test/library-tests/SharedSsaCompatibility/test.ql |
Checks flow from public phi-definition nodes. |
javascript/ql/test/library-tests/SharedSsaCompatibility/test.expected |
Adds compatibility-test expectations. |
javascript/ql/test/library-tests/SharedSsaCompatibility/refinement.ql |
Checks refinement flow, barriers, and bypass prevention. |
javascript/ql/test/library-tests/SharedSsaCompatibility/refinement.js |
Adds refinement, guard, and aliasing fixtures. |
javascript/ql/test/library-tests/SharedSsaCompatibility/refinement.expected |
Adds refinement-test expectations. |
javascript/ql/test/library-tests/SharedSsaCompatibility/nodes.ql |
Checks SSA-node uniqueness, metadata, and flow. |
javascript/ql/test/library-tests/SharedSsaCompatibility/nodes.js |
Adds public and shared SSA-node fixtures. |
javascript/ql/test/library-tests/SharedSsaCompatibility/nodes.expected |
Adds SSA-node test expectations. |
javascript/ql/test/library-tests/SharedSsaCompatibility/namespace.ts |
Covers refinements in a TypeScript namespace. |
javascript/ql/test/library-tests/SharedSsaCompatibility/local.ql |
Checks local flow, update timing, and inference. |
javascript/ql/test/library-tests/SharedSsaCompatibility/local.js |
Adds operation-completion and local-flow fixtures. |
javascript/ql/test/library-tests/SharedSsaCompatibility/local.expected |
Adds local-flow test expectations. |
javascript/ql/test/library-tests/SharedSsaCompatibility/invariants.ql |
Checks SSA mappings and public API invariants. |
javascript/ql/test/library-tests/SharedSsaCompatibility/invariants.expected |
Records expected invariant-query outputs. |
javascript/ql/test/library-tests/SharedSsaCompatibility/captured.ql |
Checks captured-variable and legacy API compatibility. |
javascript/ql/test/library-tests/SharedSsaCompatibility/captured.js |
Adds captured-write and destructuring fixtures. |
javascript/ql/test/library-tests/SharedSsaCompatibility/captured.expected |
Adds captured-variable test expectations. |
javascript/ql/test/library-tests/DataFlow/tests.expected |
Records shared read chains and post-update edges. |
javascript/ql/test/library-tests/BarrierGuardPhiInputs/tst.js |
Adds guarded-join and replacement-input fixtures. |
javascript/ql/test/library-tests/BarrierGuardPhiInputs/test.ql |
Checks barrier filtering of individual phi inputs. |
javascript/ql/test/library-tests/BarrierGuardPhiInputs/test.expected |
Adds phi-input barrier expectations. |
javascript/ql/src/NodeJS/InvalidExport.ql |
Excludes content-only post-updates from invalid exports. |
javascript/ql/lib/semmle/javascript/SSA.qll |
Replaces standalone SSA with shared-backed adapters. |
javascript/ql/lib/semmle/javascript/GlobalAccessPaths.qll |
Excludes synthesized reads from reference APIs. |
javascript/ql/lib/semmle/javascript/dataflow/TypeInference.qll |
Uses dedicated local inference edges. |
javascript/ql/lib/semmle/javascript/dataflow/Sources.qll |
Separates public source flow from internal SSA traversal. |
javascript/ql/lib/semmle/javascript/dataflow/Refinements.qll |
Controls refinement traversal optimization. |
javascript/ql/lib/semmle/javascript/dataflow/internal/VariableTypeInference.qll |
Summarizes assignment values before recapture joins. |
javascript/ql/lib/semmle/javascript/dataflow/internal/TaintTrackingPrivate.qll |
Restricts falsy guards to variable accesses. |
javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll |
Configures shared definitions, captures, refinements, and updates. |
javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowPrivate.qll |
Integrates shared read nodes into global flow. |
javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll |
Introduces shared definition and continuing-read nodes. |
javascript/ql/lib/semmle/javascript/dataflow/internal/BarrierGuards.qll |
Applies guards through shared SSA mappings. |
javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll |
Reworks SSA mapping, local flow, and inference integration. |
javascript/ql/lib/semmle/javascript/dataflow/Configuration.qll |
Adapts legacy phi-edge barriers to shared flow. |
javascript/ql/lib/change-notes/2026-11-20-shared-ssa.md |
Documents the migration and analysis improvements. |
Review effort: Max (adaptive)
Comment on lines
+37
to
+56
| node instanceof js::ControlFlowEntryNode or | ||
| node instanceof js::YieldExpr or | ||
| node instanceof js::InvokeExpr | ||
| ) | ||
| } | ||
|
|
||
| private predicate captureAt(js::Cfg::BasicBlock bb, int i, SsaConfig::SourceVariable v) { | ||
| exists(js::LocalVariable local, js::StmtContainer container, js::ControlFlowNode node | | ||
| local = v.asLocalVariable() and | ||
| capturePoint(bb, i, node, container) and | ||
| capturedReadInContainer(local, container) | ||
| | | ||
| node instanceof js::ControlFlowEntryNode and | ||
| container != local.getDeclaringContainer() | ||
| or | ||
| node instanceof js::YieldExpr and | ||
| ( | ||
| container != local.getDeclaringContainer() or | ||
| hasExternalWrite(local) | ||
| ) |
|
|
||
| /** Gets an operation that may update the object evaluated at `read`. */ | ||
| private js::ControlFlowNode postUpdateOperation(js::ControlFlowNode read) { | ||
| exists(js::InvokeExpr call | read = call.getAnArgument() or read = call.getCallee() | |
Comment on lines
+85
to
+86
| not exists(js::VarDef definition | definition.getTarget() = access) and | ||
| not exists(js::MethodCallExpr call | call.getCallee().stripParens() = access) and |
Comment on lines
+179
to
+181
| certain = true and | ||
| ( | ||
| bb.defAt(i, v.asLocalVariable(), _) |
Comment on lines
+244
to
+248
| exists(js::VarDef write | | ||
| bb.defAt(i, v.asLocalVariable(), write) and | ||
| write.getTarget() instanceof js::VarRef and | ||
| exists(write.getSource()) | ||
| ) |
Comment on lines
+1616
to
+1618
| DfInput::allowFlowIntoUncertainDef(def) and | ||
| not DfInput::ssaDefHasSource(def) and | ||
| uncertainWriteDefinitionInput(def, inp) |
Comment on lines
+107
to
+109
| } | ||
|
|
||
| function emptyRefinementBranches() { |
| } | ||
|
|
||
| private predicate nonValuePreservingDescendant(Definition def, Definition anc) { | ||
| valuePreservingDefInput+(def, anc) and |
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.


Migrates JavaScript and TypeScript SSA, variable data flow, and barrier guards onto
shared/ssa, removing the standalone liveness, phi-insertion, and reaching-definition implementation inSSA.qllwhile keeping the existing public SSA classes as shared-backed adapters.User-visible analysis improvements:
Major design decisions
shared/ssa):includePhiDefsInFlowStep()toDataFlowIntegrationInputSigso JavaScript can preserveDataFlow::SsaDefinitionNodes on phi definitions even when shared SSA would otherwise elide single-use phis.DataFlowIntegration(getAValuePreservingInputDef) so phi-input read checks and barrier guards look through value-preserving uncertain definitions and phi nodes whose paths all preserve an ancestor definition.certain = false) withallowFlowIntoUncertainDefenabled andssaDefHasSourcedisabled. Type inference still narrows values at refinement nodes, while data flow and barrier guards treat them as value-preserving.yield/await, function expressions, and exits) when written outside their declaring container, preserving local SSA flow between capture points alongside existing cross-container capture flow.SsaConfig::postUpdateRead: Operation-completion positions are registered viapostUpdateReadrather than syntheticvariableReads, so ordinary use-use chains skip post-update nodes viaAdjacentSsaRefsand avoid doubling local/parameter-summary fixed-point iterations. When a variable is reassigned inside the same call or assignment (e.g.f(x, x = y)), syntactic definition checks handle trivial self-copies andadditionalPostUpdateContinuationfalls back to modeled may-value flow for aliases.Ssa2::ReadNodeto internalTSharedSsaReadNodes in addition to AST value nodes so barrier guards block continuing variable flow without blocking the guarded expression itself, while excluding internal SSA read nodes (TSharedSsaReadNode,TSsaSynthReadNode) from public local-flow APIs (flowsTo,getALocalSource,analyze,AccessPath::getAReferenceTo).withstatements:sharedTypeInferenceFlowStepuses directlocalMustFlowStepdefinition-to-read edges for uncaptured variables to avoid multi-hop propagation along long read chains, while restrictingwith-statement uncertainty to expression occurrences so one read insidewithdoes not pollute downstream reads.Performance
The average analysis time on DCA increases by 6%. I think the only way to fix this is to edit the shared SSA library, which is out of the scope of this PR.