Skip to content

JS: Complete migration to shared SSA library - #22937

Open
owen-mc wants to merge 3 commits into
github:mainfrom
owen-mc:experiments/js-shared-ssa
Open

owen-mc wants to merge 3 commits into
github:mainfrom
owen-mc:experiments/js-shared-ssa

Conversation

@owen-mc

@owen-mc owen-mc commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Migrates JavaScript and TypeScript SSA, variable data flow, and barrier guards onto shared/ssa, removing the standalone liveness, phi-insertion, and reaching-definition implementation in SSA.qll while keeping the existing public SSA classes as shared-backed adapters.

User-visible analysis improvements:

  • Barrier guards across joins and refinements: Guards now filter individual phi inputs and propagate across single, compound, and loop-carried refinements, removing false positives when guarded and reassigned branches merge.
  • Post-update ordering: Post-update flow from calls, method calls, and property assignments now takes effect after the operation completes rather than being visible inside the operation's own arguments or right-hand side.

Major design decisions

  • Shared SSA extensions (shared/ssa):
    • Added opt-in includePhiDefsInFlowStep() to DataFlowIntegrationInputSig so JavaScript can preserve DataFlow::SsaDefinitionNodes on phi definitions even when shared SSA would otherwise elide single-use phis.
    • Extended 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.
  • Refinements as uncertain writes: Type refinements are modeled as uncertain SSA writes (certain = false) with allowFlowIntoUncertainDef enabled and ssaDefHasSource disabled. Type inference still narrows values at refinement nodes, while data flow and barrier guards treat them as value-preserving.
  • Captured variables: Captured locals are included in shared SSA with conservative uncertain writes at capture points (calls, 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.
  • Post-updates via SsaConfig::postUpdateRead: Operation-completion positions are registered via postUpdateRead rather than synthetic variableReads, so ordinary use-use chains skip post-update nodes via AdjacentSsaRefs and 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 and additionalPostUpdateContinuation falls back to modeled may-value flow for aliases.
  • Separating occurrence nodes from continuing SSA reads: Global data flow maps Ssa2::ReadNode to internal TSharedSsaReadNodes 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).
  • Type inference and with statements: sharedTypeInferenceFlowStep uses direct localMustFlowStep definition-to-read edges for uncaptured variables to avoid multi-hop propagation along long read chains, while restricting with-statement uncertainty to expression occurrences so one read inside with does 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.

@owen-mc owen-mc added the JS label Oct 29, 2026
* 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
owen-mc force-pushed the experiments/js-shared-ssa branch from d8a3801 to fda35fc Compare October 29, 2026 16:04
@owen-mc
owen-mc force-pushed the experiments/js-shared-ssa branch from fda35fc to c11c472 Compare November 19, 2026 17:48
owen-mc and others added 3 commits November 20, 2026 23:31
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
@owen-mc owen-mc changed the title JS: Use shared SSA library JS: Complete migration to shared SSA library Nov 20, 2026
@owen-mc
owen-mc force-pushed the experiments/js-shared-ssa branch from 88843b1 to 7127c4f Compare November 20, 2026 23:56
@owen-mc
owen-mc marked this pull request as ready for review November 20, 2026 23:57
@owen-mc
owen-mc requested review from a team as code owners November 20, 2026 23:57
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 23:57

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

Unresolved critical SSA modeling defects can suppress security-relevant data flow and retain invalid guards across writes and await suspension.

8 open issues
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

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.

3 participants