Repository navigation
Commit ea5aeef
authored
fix(e2): report child-process env pass-through as LOW instead of HIGH (NVIDIA#492)
* fix(e2): exempt child-process env pass-through from harvesting
E2 fired HIGH at 0.6 confidence on `subprocess.run(cmd, env={**os.environ,
...})` and on an `os.environ.copy()` bound to a name and passed as `env=`,
which is the standard way to hand an environment to a child process. A real
harvester and the most common benign idiom were indistinguishable in the
report.
The analyzer's own docstring already excluded this case: a full mapping copy
is a harvesting signal "unlike a targeted single-key lookup or passing
os.environ through to a child process". The code did not implement the second
half, because it keyed on the copy rather than on where the copy goes.
Collect the expressions passed as `env=` to a known process launcher, plus the
names bound to them, and skip those at emit time. An environ copy that goes
anywhere else still fires, and network and execution sinks remain the
behavioral taint analyzer's job.
Fixes NVIDIA#441
Signed-off-by: Malin Fossum <[email protected]>
* fix(e2): scope child-process env pass-through to the reaching definition
The pass-through exemption keyed on every name ever handed to a launcher's
env= anywhere in the file, so a later env = {} passed to subprocess.run hid
an earlier env = os.environ.copy() that was posted to the network, and a
single mapping that was both exfiltrated and passed through was hidden too.
Bindings are now followed in evaluation order until the name is rebound; a
copy is exempt only when every use up to that point is a child-process env=
argument or an in-place edit of the mapping. Adds regression tests for the
rebinding and dual-use cases.
Signed-off-by: Malin Fossum <[email protected]>
* fix(e2): track environment bindings per lexical scope
The flow visitor kept one flat binding map, so a nested parameter, local
assignment, lambda argument, comprehension target or class attribute with
the same name closed the outer binding and left a benign pass-through copy
reported as E2.
Bindings now live in a scope stack that follows Python's resolution rules
(global, nonlocal, class bodies, comprehension targets and walrus). A
function or lambda body runs later, so its reads of an enclosing name count
against every binding open at its definition or made after it. That also
catches a leaking closure defined before the copy, which the flat map missed.
Signed-off-by: Malin Fossum <[email protected]>
* fix(e2): close environment bindings only on rebindings that surely run
A rebinding now closes only the bindings made in its own block or in blocks
nested inside it. One inside an if, try, with, match or loop body leaves the
outer binding open, and later uses count against both. Nothing closes where a
raise, break or continue can skip the rebinding (try, except, with and loop
bodies), or through a walrus. A read anywhere in a loop counts against every
binding made in that loop, which covers the next pass reading this pass's
copy. This stays linear: visiting loop bodies twice would double the work at
every nesting level, and the open bindings per name are capped so a crafted
file cannot make the pass quadratic.
pop and setdefault count as in-place edits when their value is discarded or
comes from one literal key; popitem only when discarded. A walrus result, a
class attribute, a class-body read that falls through to globals, and any
name in a file that calls globals(), locals(), vars(), eval() or exec() keep
the finding. A RecursionError in the flow pass falls back to reporting every
full read instead of dropping the file's E1-E5 findings.
Signed-off-by: Malin Fossum <[email protected]>
* fix(e2): trust only imported launchers and unreachable bindings
The pass-through trusted a launcher's spelling and one file's view of a
name. Three ordinary spellings hid real exfiltration:
- A local `def run` or `class subprocess` matched the launcher allowlist.
A launcher root now counts only when it is bound solely by an absolute
import from subprocess or asyncio, is never rebound in the file, and
nothing writes to that module (attribute stores, setattr, vars,
__dict__, sys.modules, star imports).
- A module global can be imported by another file. By-name pass-through
now needs a function local, or a module global bound in a top-level
`if __name__ == "__main__":` body while `__name__` is never rebound.
- `secret = env.pop("KEY")` counted as an edit. Literal-key pop and
setdefault now count only when the result is discarded, as popitem.
Any reference to globals, locals, vars, eval, exec or sys.modules, and
any f_locals, f_globals or __globals__ attribute, now counts as a dynamic
read, so an aliased `locals` or a frame lookup keeps the finding.
Signed-off-by: Malin Fossum <[email protected]>
* fix(e2): visit annotations and report pass-through copies as LOW
The flow pass skipped argument and return annotations, type parameters and
type alias values, so a copy read there was marked as pass-through. Visit
them as reads that run when defined or later. Comprehension targets that
only load a name no longer bind it, and an augmented assignment other than
|= reads the old value.
A copy traced only to a child process's env= is now reported as an E2 LOW
at confidence 0.2 instead of being dropped. The pass covers ordinary Python
evaluation, not frames, hooks or other introspection, so a read it misses
lowers the finding rather than removing a HIGH.
Signed-off-by: Malin Fossum <[email protected]>
---------
Signed-off-by: Malin Fossum <[email protected]>1 parent 3764778 commit ea5aeef
3 files changed
Lines changed: 1527 additions & 6 deletions
File tree
- src/skillspector/nodes/analyzers
- tests/nodes/analyzers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
565 | | - | |
| 565 | + | |
566 | 566 | | |
567 | 567 | | |
568 | 568 | | |
| |||
0 commit comments