Skip to content

Make DataFlowNode locations deterministic by construction (private constructor) - #11953

Merged
danog merged 6 commits into
vimeo:masterfrom
danog:taint/deterministic-by-construction
Sep 15, 2026
Merged

danog merged 6 commits into
vimeo:masterfrom
danog:taint/deterministic-by-construction

Conversation

@danog

@danog danog commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Builds on the previous PR to enforce, structurally, that a node's location is a pure function of its id.

  • Factories for identity copies — add withSpecialization() and withFlow(), used in TaintFlowGraph and VariableUseGraph in place of new DataFlowNode(...), so a node re-keyed or advanced during resolution carries its location/label/identity over from an existing node unchanged. Also folds a taint source/sink's location into its id (as getForAssignment() already does). This removes every remaining external new DataFlowNode(...).
  • Private constructor (breaking) — with all construction going through factories, __construct becomes private so a CodeLocation can only reach a node through a factory that derives it deterministically from the node's identity. The class-level invariant is documented. External code (including plugins) can no longer new DataFlowNode(...).

TaintTest passes unchanged.

Part 3 of a 4-PR stack. Stacked on #11952 — review/merge that first; the diff here includes its commits until it merges.

🤖 Generated with Claude Code

danog and others added 6 commits September 15, 2026 13:29
Taint resolution previously ran a fixed 40-round BFS and stopped at a
hard-coded nesting limit, so flows longer than 40 hops were silently
missed and the round count was unrelated to convergence.

Run to a true fixed point instead: loop while sources and sinks remain,
relying on the existing (id, taints) visited guard -- whose state space
is finite -- to guarantee termination. This removes the resolution-depth
limit entirely, so deep taint flows are no longer missed. Propagation
semantics are otherwise unchanged: each (id, taints) state is explored
exactly as before.

Adds tests for a flow deeper than the old 40-hop cap (via plain
assignments and via a chain of distinct specialized function calls) and
for a sanitized array value that must not be reported.

Co-Authored-By: Claude Opus 4.8 
Restrict resolution to the sub-graph from which a sink is actually
reachable, via a backward reachability pass from the sinks over the
forward edges: a node from which no sink is reachable can never produce
an issue, so propagating taint into it is wasted work. On real codebases
the full taint graph is huge while this relevant sub-graph is tiny,
which is what keeps running to convergence cheap.

Specialized and unspecialized nodes are linked both by their
authoritative unspecialized_id field and by the id-string separator, so
the prune never drops a node whose specialized or de-specialized form
can reach a sink (the resolution walk maps freely between the two).

Co-Authored-By: Claude Opus 4.8 
When analysis runs across forked workers, each builds a partial
DataFlowGraph the parent merges with `+=` (first value per key wins). The
same node id could be created at several sites with different
code_locations and sink taints, so which survived the merge depended on
worker scheduling. Since a taint issue is reported at its node's
code_location, this shifted reported locations and per-file occurrence
counts between identical runs, so baselined issues silently reappeared
and --set-baseline never converged.

Make a node's location and sink taints a pure function of its identity:

* getForCallableArg()/getForCallableReturn() no longer accept an
  independent CodeLocation (breaking). A callable node has no storage to
  derive a canonical location from, so its location is now always its
  specialization (the callsite), which is already part of the node id.
* getForMethodArgument() derives its sink taints from the parameter's
  storage rather than a caller-supplied argument (breaking).
* The inherited-method return-node kind is dropped: MethodCallReturnType-
  Fetcher always builds return nodes via getForMethodReturn(), resolving
  the declaring storage, so the location is the canonical return location
  wherever the id is produced.

Co-Authored-By: Claude Opus 4.8 
The argument sink node id (`Class::method#offset`) is shared by every
call of the method, so its location must be a function of that identity.
When the caller has no storage in hand (e.g. an inherited method has no
storage under its own id), resolve the declaring method's storage from
the cased method id itself, rather than leaving the location unset here
and letting it differ between the forked-worker graphs. Every site that
mints the node then agrees on the canonical parameter location.

Co-Authored-By: Claude Opus 4.8 
Add withSpecialization() and withFlow() to DataFlowNode and use them in
TaintFlowGraph and VariableUseGraph in place of `new DataFlowNode(...)`,
so a node re-keyed or advanced during resolution carries its location,
label and identity-derived fields over from an existing node unchanged
rather than having them re-supplied by the caller.

Also fold a taint source/sink's location into its id (as getForAssignment()
already does), so the same $taint_id reused at several sites maps to one
location per site; the human-readable label keeps the bare $taint_id.

This removes every remaining external `new DataFlowNode(...)`, preparing
the constructor to be made private.

Co-Authored-By: Claude Opus 4.8 
With every construction now going through a factory, make __construct
private so a CodeLocation can only reach a node through a factory that
derives it deterministically from the node's identity. This structurally
enforces the invariant that a node's location is a pure function of its
id, which is what makes taint findings reproducible across forked
workers. Document the invariant on the class.

External code (including plugins) can no longer `new DataFlowNode(...)` --
hence a breaking change.

Co-Authored-By: Claude Opus 4.8 
@danog
danog merged commit f73c51b into vimeo:master Sep 15, 2026
48 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant