Repository navigation
Commit 3c12146
refactor(taint): narrow interprocedural taint to bounded direct calls
Two review rounds of the broad interprocedural design showed it kept
producing denial-of-service paths (per-call work proportional to the
number of candidate classes, unbounded receiver class lists, per-source
fact sets, messages copying long identifiers) and recall or precision
regressions (receiver typing that hid real callees, a fallback that bound
into every same-named method, callback rules that bound the wrong
arguments). This narrows interprocedural flow to calls whose callee is
known from syntax alone, in O(1) per call.
Kept:
- Lexical scopes. Function locals and parameters are per function and
module globals keep bare keys; global/nonlocal and closures follow
Python's rules; class bodies are invisible to methods; lambdas and
comprehensions are scopes, with PEP 572 walrus binding. Names resolve
in one depth-first pass over the scope tree with a stack per
identifier, O(1) per name however deep the nesting. Keys are small ints
built from a scope id and a reference to the identifier, never from a
qualified name.
- Direct calls by name to functions defined in the file (including
nested ones visible lexically and lambdas assigned to a name):
positional and keyword arguments, defaults, *args/**kwargs forwarding,
16 positional slots. Every definition bound to one name is one callee,
so binding work is linear in calls, not calls x redefinitions.
- Per-call-site returns. A callee's return summary only carries facts
that do not depend on its parameters; what a call returns from its own
arguments is read at that call site from those arguments (a call's
value includes its arguments, as before). One caller's secret no
longer taints other callers' results, also through closures and
lambdas.
- Methods, only where the callee is syntactic: self.m()/cls.m() bind to
the class's own method or its nearest in-file base (a precomputed lookup
over at most 8 classes), Class.m(obj, ...) with the unbound offset,
super().m(), and Class(...)/cls(...) to __init__. Aliases of a class
bind nothing, as on main. self.x/cls.x attributes are per class: a read
sees stores in its class and in-file bases, never in siblings.
- One source per key and sink lane, the most severe for the lane:
credential > file read > external input for network sinks, and
external input > file read > credential for code execution and
deserialization sinks. A helper's source can no longer turn a TT3 into
TT2/TT4, nor a TT5/TT6 into TT2. When the lanes agree (almost always)
they share one fact, which propagates once.
- Two-phase propagation. Phase A replays main's assignment flows in
main's order; phase B adds argument binding, returns, attributes and
defaults, and only fills clean keys or upgrades to a more severe source.
A flow main reports keeps main's message, except where a more severe
source now reaches the same variable.
- Messages name what the sink spells (never an attribute spelling from
elsewhere in the file); identifiers longer than 120 characters are
shortened, so message bytes stay bounded per finding.
Dropped, each a source of DoS paths or regressions:
- receiver type inference (per-scope type maps, annotations, with-as,
cast and builtin results), MRO linearization beyond the bounded base
lookup, and @Property reads;
- the untyped-receiver fallback into every same-named method;
- callback rules (Thread target, submit, run_in_executor): as on main;
- class hierarchy families and the shared-descendant attribute rule;
- per-source fact sets;
- comprehension iteration flows (main does not model iteration targets,
and they changed which variable messages cite at sinks);
- lambda return summaries (a lambda's value is already read by name).
Bounds: indexing, name resolution, flow building, callee linking and
propagation are linear, and check_runtime runs in each of their loops.
Every flow fires at most once per (lane, rank, slot), 12 times whatever
the number of sources. On every DoS repro from both reviews, every file
completes and later files keep their findings; time is 1.0-2.2x main and
peak memory matches main, except +14% on a variable carrying all 23
sources.
Tests:
- main's 77 taint tests pass unchanged.
- New: name-clash classes found in real skills, direct-call recall,
methods and attributes without sibling leakage, source lanes, message
compatibility, deadlines in indexing, flow building, callee linking and
propagation, and every DoS repro from both reviews as a work-scaling
test (executed analyzer lines at 1x and 4x size, not wall time), a
fact count or a byte count.
- TestNotResolved pins main-like behavior for the dropped features.
- Removed PR tests, with the reason:
- receiver typing and the untyped fallback (library instance
elsewhere, untyped parameter receiver, typed receivers reading or
binding only their class, returns of constructed and attribute
receivers, and their exec/file variants): the features are dropped;
instance receivers now bind nothing, as on main;
- callbacks on attribute, constructor and parameter receivers, Thread
kwargs, Thread(target=Base.m): callback rules are dropped;
- @Property reads, Config.TOKEN read through the class name, mixins and
subclass overrides reached from a base: dropped with hierarchy
families; overrides now assert main-like results;
- comprehension over tainted data tainting its target: iteration flows
are dropped;
- the 1 s workflow-deadline wall-clock test: replaced by operation
counts (it also passed on the unfixed code).
The other PR tests were kept under new names (scope precision, helper
returns, argument binding, closures, attributes, super, unbound calls,
context sensitivity, lambda and comprehension scopes, deadlines).
Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>1 parent 033b4cf commit 3c12146
2 files changed
Lines changed: 2410 additions & 2488 deletions
File tree
- src/skillspector/nodes/analyzers
- tests/nodes/analyzers
0 commit comments