Repository navigation
Commit 4e122b2
Address PR #91 P1 + P2 review: per-call-site allowlist + tighten importlib.resources
P1 — Allowlist over-permits within a file.
The original allowlist matched on (relative_path, surface) only, so
one AllowedException("triggers.py", "attr_call:subprocess.run")
blanket-permitted every subprocess.run call in triggers.py.
Reviewer reproduced this: injecting a synthetic 4th subprocess.run
in-memory still passed the contract test.
Fix: AllowedException now pins (relative_path, surface, line,
snippet). Violation carries snippet=ast.unparse(node). Match requires
all four fields, so each call site needs its own entry. Adding an
unreviewed subprocess.run to an already-allowlisted file now fails
the test with the precise (line, surface, snippet) triple. Argv
shape changes flip the snippet → also fails → forces re-review.
Three subprocess.run sites in triggers.py and two in
cli/discovery/artifacts.py each have distinct entries. Total
ALLOWED_EXCEPTIONS grows from 7 to 13.
P2 — importlib.resources.files() globally exempted.
importlib.resources was in ALLOWED_FORBIDDEN_MODULE_IMPORTS, so
``files(name)`` produced no violation. Current call sites use a
literal 'agents_shipgate' anchor, but a future user-controlled
anchor would bypass the dynamic-import lint entirely.
Fix: importlib.resources.files joins FORBIDDEN_ATTR_CALLS_EXACT,
and importlib.resources joins TRACKED_NON_FORBIDDEN_MODULES so
``from importlib.resources import files; files(...)`` is resolved
through name-aliases. Both call sites (triggers.py:61,
fixtures.py:40) are individually pinned with snippet
``files('agents_shipgate')``. A future files(user_var) call would
change the snippet and fail the test.
Negative controls confirmed (both reverted before commit):
- Adding ``subprocess.run(['git', 'status'], ...)`` into
triggers.py at line 364 fails with
"triggers.py:364 attr_call:subprocess.run snippet=...".
- Replacing files('agents_shipgate') with files(some_user_anchor)
in triggers.py:61 fails with snippet mismatch.
New contract tests:
- test_allowlist_entry_matches_real_surface — now checks all four
fields (surface, line, snippet) with three failure-mode diagnostics
(removed surface, line drift, snippet drift).
- test_allowed_exceptions_have_no_duplicates — guards against two
entries covering the same call site.
- test_allowed_exceptions_pin_subprocess_run_per_call_site —
regression-tests the P1 fix by asserting triggers.py has 3
distinct subprocess.run entries (not 1) and artifacts.py has 2.
Scanner-internal changes:
- Violation gains snippet: str (ast.unparse output).
- From-import-of-forbidden-attr line now emits surface
"import:<canonical>" instead of "attr_call:<canonical>" so it's
distinguishable from the call-site flag in audit output.
Tests: 179 lint tests pass (170 → 179); 1192 full suite passes;
ruff clean; coverage 87.23%.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 5319c8c commit 4e122b2
3 files changed
Lines changed: 480 additions & 82 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
5 | 47 | | |
6 | 48 | | |
7 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
273 | 280 | | |
274 | 281 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
279 | 298 | | |
280 | 299 | | |
281 | 300 | | |
| |||
0 commit comments