forked from bchanot/claude
Merge bugfix/guardrails-residuals into develop
This commit is contained in:
commit
68d774fd49
19 files changed
+993
-98
No files matched your search
@@ -52,6 +52,7 @@ rules:
|
||||
| BLK-030 | 2026-10-15 | model-router kept routing best-tier phases to Fable out of usage credits: each new session + each hold lapse lost a turn to 429 `model_requires_usage_credits`; breaker reactive only | resolved |
|
||||
| BLK-031 | 2026-10-16 | model-router: session starting on Fable w/o credits lost 1st turn + each hold lapse; probe skipped kept cur | resolved |
|
||||
| BLK-032 | 2026-10-19 | Main loop pinned on Fable in long sessions: session model Fable 1M + downgrade cap 120k + prompt rule `plan` → inline code on Fable xhigh; user routing policy recorded for next /feat | open |
|
||||
| BLK-033 | 2026-10-21 | Guardrails residuals: probe trusted plan `supabase.url`, redirects free of budget, unread bodies read CLOSED, `str(URLError)` hid budget signal; rules 5 FP / 7 misses | resolved |
|
||||
|
||||
---
|
||||
|
||||
@@ -334,3 +335,9 @@ rules:
|
||||
## BLK-032 — Main loop pinned on Fable in long sessions: session model Fable 1M + downgrade cap 120k + prompt rule `plan` → inline code on Fable xhigh [open]
|
||||
- **Cause**: `~/.claude/settings.json` `"model": "claude-fable-5-1[1m]"` (every session starts on Fable); model-router never moves main above the session model, moves DOWN only under `downgradeMaxTokens` 120000 (LRN-204 cold read) → a long session (faunosteo R4.x, context > 120k) never reaches `implement`/sonnet; prompt rule `(plan|design|architecture…)` → phase plan = best/xhigh each turn ("plan §B.1.7"). No doctrine ceiling: CLAUDE.md allows inline work "doable in a few tool calls", BDR-115 "pin = default, never ceiling".
|
||||
- **User policy 2026-10-19**: session model Opus 5.5; sonnet writes, opus decides what to write; Fable only for orchestrator reflection/plans and the important audits (security, functional), other judges opus. → next `/feat`: settings model, `judge` split, ceiling rule in CLAUDE.md, BDR superseding part of BDR-066 / BDR-115. Links [[BDR-066]], [[BDR-107]], [[BDR-115]], [[LRN-204]].
|
||||
|
||||
## BLK-033 — Guardrails residuals: probe trusted plan `supabase.url`, redirects free of budget, unread bodies read CLOSED; rules 5 FP / 7 misses [resolved]
|
||||
- **Friction**: GATE 2 of the a11y split (f586304) left a MEDIUM + 3 LOW on probe.py, opus review left Minors on the rules. Parked in TODO, fixed via `/bugfix` 2026-10-20/21.
|
||||
- **Cause**: `supabase.url` read from the plan w/o `_http_url` → planted SUPABASE_URL would receive GUARDRAILS_ANON_KEY / JWT2, `file://` read CLOSED; `_SameHost` redirector followed hops w/o charging `session.budget`; `_rows_state` collapsed non-200 / empty / >1 MB / non-JSON into CLOSED (unobserved = CLOSED, breaks LRN-220); plan r2 mapped budget exhaustion on `str(URLError)`, which wraps the reason → never matched. Rules: SENSITIVE_KEY on metadata names (`token_type`, `has_password`), 403 on first map candidate stopped the walk, hydrated scan read whole route file, NOSQL `$where` fired on GraphQL `_bool_exp`; misses: Go backtick Sprintf, `rf`/triple-quoted f-strings, `sql|db|trx.raw`, empty `.select()`, multi-line hidden input, Rust `{}` shell arg, `"sources"` map head.
|
||||
- **Solution**: 5a98c2c (`_BudgetExhausted(URLError)` + `BUDGET_EXHAUSTED` constant, `_SameHost(session)` charges per hop, `_rows_state` rows|empty|unreadable → SKIPPED, `_map_outcome` full candidate walk, `data:` OPEN w/o decoding, `printable` on remote strings, `_safe_text` in scanner, rule fixes + mutant per language variant) + 633faa2 (checks.md: `IN (…)` placeholder list flagged, judged by hand). Plan r3 after 2 challenge rounds, contract 22 oracles MET, verifier CONFORME, auditor PASS. Suites probe 84, scan 241.
|
||||
- **Residual** (LOW, parked in TODO): table names not `IDENT.fullmatch`-checked per table (`/` → path walk on the approved host); `printable` lets Unicode bidi/format controls through. Links [[LRN-219]], [[LRN-220]], [[LRN-222]], [[LRN-223]].
|
||||
@@ -629,3 +629,7 @@ rules:
|
||||
|
||||
## 2026-10-19
|
||||
- Guardrails split shipped via /ship-feature (feature/a11y-split-inj-exp): /a11y skill on the shared engine, injection + exposure domains, probe exposure block, secure-by-default six domains. SDD 9 tasks, GATE 1 ECARTS(9)→CONFORME (fields CLOSED route, suppressions removed), GATE 2 PASS (7 LOW), opus review 0 Critical / 6 Important fixed. Routing finding: Fable pinned in long sessions (BLK-032), user policy recorded for a later /feat. Merge on user go.
|
||||
|
||||
## 2026-10-21
|
||||
- /prune-memory: learnings.md index backfilled LRN-191..218 (28 rows), c7ebc3d on chore/prune-learnings-index. Index 221 rows = 221 entries.
|
||||
- /bugfix guardrails residuals (bugfix/guardrails-residuals): plan r3 after 2 challenge rounds (4 BLOCKERs r1: WARN severity, budget must raise, three-way SKIPPED, vacuous timing; r2: `str(URLError)` wrap), contract 22 oracles, 3 part executors, GATE 0/1/2 green, 5a98c2c + 633faa2 (checks.md IN() wording caught by doc-syncer, not the gates). BLK-033, LRN-222/223. Two LOW parked. Both branches await merge signal. Next: /feat routing policy (BLK-032).
|
||||
@@ -241,6 +241,8 @@ rules:
|
||||
| LRN-219 | 2026-10-19 | Scanner regex over untrusted trees: bound every repeat, cap comment blankers, timing lock on adversarial file | any whole-file regex scanner |
|
||||
| LRN-220 | 2026-10-19 | Live probe verdicts fail closed by construction: fixture route per negative branch, 3xx = SKIPPED, depth/size limit = SKIPPED never CLOSED | writing probes and their suites |
|
||||
| LRN-221 | 2026-10-19 | Floor-guard suppressions: remove, never waive; contract CHECK asserts intent (symbol/behaviour), not one code spelling | suppressions, writing CHECK: lines |
|
||||
| LRN-222 | 2026-10-21 | Map an error to a verdict on a typed exception or carried constant, never on `str(err)`: URLError wraps its reason | probe/fetch error mapping, any err→verdict code |
|
||||
| LRN-223 | 2026-10-21 | Regex timing lock is vacuous when the input matches early: feed a non-matching worst-path input, assert `is None`, keep ≥ 2x margin under the lock | every bounded regex test |
|
||||
|
||||
---
|
||||
|
||||
@@ -1856,3 +1858,11 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s
|
||||
## LRN-221 — Floor-guard suppressions: remove, never waive; contract oracles assert intent, not syntax
|
||||
- **Context**: GATE 1 counted 6 floor findings: `# noqa: E402` ×2 (import after `sys.path.insert`), a `# shellcheck disable=SC2016` copied from another suite (dead: deleting it raised nothing), 3 plan quotes of the same lines. `importlib.import_module` after the insert needs no noqa. Then criterion 16's CHECK grepped `^import scanner` and went red on the legit fix.
|
||||
- **Apply**: a suppression = first try the construct that needs none; test a copied `disable` by deleting it; a CHECK greps the symbol or behaviour (`scanner.Catalogue` loaded), never one spelling of the code. Links [[BDR-102]].
|
||||
|
||||
## LRN-222 — Map an error to a verdict on a typed exception or carried constant, never on `str(err)`
|
||||
- **Context**: guardrails residuals plan r2 detected budget exhaustion by `BUDGET_EXHAUSTED in str(err)`; `URLError` renders as `<urlopen error …>` and wraps the reason object, so the match never fired and the verdict stayed SKIPPED instead of ERROR. Challenger (correctness lens) caught it as BLOCKER before the contract. Fix: `_BudgetExhausted(URLError)` subclass carrying the constant, mapper uses `isinstance`, regression test raises the real type.
|
||||
- **Apply**: err→verdict code matches on type or an attribute the raiser sets; the test raises the real exception class through the real call path, never a hand-built message. Links [[LRN-220]], [[BLK-033]].
|
||||
|
||||
## LRN-223 — Regex timing lock is vacuous when the input matches early: non-matching worst-path input, assert `is None`, ≥ 2x margin
|
||||
- **Context**: plan r1 timing cases (LRN-219 lock, 1.0 s / 80 KB) fed inputs the bounded regex matched at the start, so they ran fast by construction and proved nothing (challenger BLOCKER, robustness lens). r3: inputs built to force the longest non-matching scan, cases assert `is None` and the elapsed time; SHELL_DB case at 0.65 s was too close to the lock → 1800 units (~29 KB) for margin.
|
||||
- **Apply**: one timing case per bounded regex, input that does NOT match and exercises the widest quantifier; assert the non-match too, else a regex that matches everything passes the lock; keep elapsed ≤ half the lock. Links [[LRN-219]], [[BLK-033]].
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
## 2026-10-19 — guardrails split: /a11y + injection/exposure (feature/a11y-split-inj-exp)
|
||||
- [x] run — SDD 9/9, gates 0/1/2 green, opus review Importants fixed (c0fdbec, 9275e0d, 63a88bc), capitalize BDR-122 LRN-219..221 BLK-032; merge = user go
|
||||
- [ ] parked (review Minors): SENSITIVE_KEY matches metadata names (`token_type`, `has_password`, `next_page_token` locked as sensitive); 403 on first map candidate → SKIPPED before header/comment candidates (S3/CloudFront); EXP-HYDRATED-SENSITIVE scans whole route file (Remix/SvelteKit actions); `webpack.dev.js` WARN; `data-password-toggle` WARN; GraphQL `$where: users_bool_exp` → INJ-NOSQL-OPERATOR; misses: Go raw-string Sprintf, Drizzle `sql.raw`, `db.raw`, `rf""`, Supabase `.select()` no arg, multi-line JSX hidden input, triple-quoted f-strings; `IN (${placeholders})` = FAIL (name in judging step); timing lock skips CONCAT (~2.6 s/1 MB); per-language variants without mutant; SKILL.md:96 fields bearer JWT2; large `.map` head misses esbuild/rollup (`"version":3`); URL-encoded `data:` maps.
|
||||
- [ ] parked (GATE 2 non-blocking, pre-existing on develop): probe `supabase.url` not validated by `_http_url` nor shown in the `--authorized` refusal (MEDIUM, probe.py:168,194: planted SUPABASE_URL would receive the test JWT; `file://` reads CLOSED); same-host redirects not counted in `session.budget` (LOW); `_nonempty_rows` catches ValueError only, deep JSON → RecursionError exit 1 (LOW); scanner text output prints `f.path` / `project.root` without `_printable` (LOW).
|
||||
- [x] parked review Minors + GATE 2 residuals (probe `supabase.url`, redirects, `_nonempty_rows`, printable) → /bugfix 2026-10-21, 5a98c2c + 633faa2, BLK-033
|
||||
- [ ] parked (GATE 2 LOW, 5a98c2c): probe table names not checked with `IDENT.fullmatch` per table (a `/` walks a path on the approved Supabase host); `printable` lets Unicode bidi/format controls (U+202E, U+2066…) through to the tty
|
||||
- [ ] routing policy /feat (user 2026-10-19, BLK-032): settings model → Opus 5.5; `judge` split (security-auditor + verifier → Fable, plan-challenger/analyzer/code review → opus); executors stay sonnet, "what to write" on opus; ceiling rule: main on Fable never writes code beyond a hotfix edit → dispatched executor; BDR superseding part of BDR-066 / BDR-115.
|
||||
|
||||
## 2026-10-18 — secure-by-default guardrails: 5 domains + /guardrails skill (feature/secure-by-default)
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
# CONTRACT — guardrails-residuals
|
||||
- date: 2026-10-20 | flow: bugfix | branch: develop (bugfix branch at STEP 4)
|
||||
- status: active
|
||||
- plan: .claude/tasks/plans/2026-10-20-guardrails-residuals-1410.md (r3, challenged twice)
|
||||
|
||||
## REQUEST (verbatim — IMMUTABLE)
|
||||
User message (typed): "corrige tout les 4 points qui tu as souligne" — point 1 = the MEDIUM
|
||||
of the security gate (probe `supabase.url` unvalidated) and point 2 = the parked
|
||||
review Minors and the 4 LOW, both in `.claude/tasks/TODO.md` lines 5-6.
|
||||
|
||||
Skill arguments ($ARGUMENTS to /bugfix):
|
||||
"Guardrails residuals parked in .claude/tasks/TODO.md lines 5-6 after the a11y split merge (f586304). Fix all of them: (1) probe.py `supabase.url` validated through `_http_url` and echoed next to base_url in the `--authorized` refusal (planted SUPABASE_URL would receive GUARDRAILS_ANON_KEY / GUARDRAILS_JWT2; `file://` reads CLOSED); same-host redirects counted against `session.budget`; `_nonempty_rows` catches RecursionError like `_json_body`; scanner.py text output passes `f.path` and `project.root` through a printable filter. (2) review Minors: SENSITIVE_KEY false positives on metadata names (`token_type`, `has_password`, `next_page_token`); 403 on the first map candidate must not stop before header/comment candidates; EXP-HYDRATED-SENSITIVE scoped to the loader/getServerSideProps return, not the whole route file; `webpack.dev.js` and `data-password-toggle` stay silent; GraphQL `$where: users_bool_exp` not INJ-NOSQL-OPERATOR; misses to cover: Go raw-string Sprintf, Drizzle `sql.raw`, `db.raw`, Python `rf""`, Supabase `.select()` with no arg, multi-line JSX hidden input, triple-quoted f-strings; `IN (${placeholders})` named in checks.md judging step; timing lock also covers CONCAT; a mutant per language variant; SKILL.md:96 fields example with bearer JWT2; large `.map` head detection for esbuild/rollup (`"version":3`); URL-encoded `data:` source maps. Suites: lib/tests/guardrails-scan.test.sh, guardrails-probe.test.sh, a11y-scan.test.sh via make test. Working tree has two pre-existing uncommitted files (mods/model-router/routing.json, settings.json) that are not part of this task and must never be staged."
|
||||
|
||||
## CLARIFICATIONS
|
||||
Pass B (STEP 3, 2026-10-20, AskUserQuestion): plan approved; B1 full METADATA_KEY list
|
||||
(`next_page_token` stops being reported); webpack dev configs and UI-suffixed data-*
|
||||
names silent with benign locks; no new CLI flag. [gated 2026-10-20]
|
||||
Analyzer corrections accepted: B12's real miss is the key order of rollup maps (the
|
||||
`"mappings"` key after `sourcesContent`), not a `"version":3` test; B13 base64 form
|
||||
was already OPEN, the percent-encoded form was the miss. The judging step named in
|
||||
the request lives in SKILL.md (checks.md has none): the bullet goes there, the
|
||||
by-design line in checks.md is amended.
|
||||
Challenge rulings (r1, r2): a line-start `data:` sourceMappingURL directive is OPEN
|
||||
whatever its encoding (no decoding); budget exhaustion is one constant
|
||||
`BUDGET_EXHAUSTED` mapped in `fetch`; hydrated scope = export chunks; triple-quoted
|
||||
f-strings = STMT-anchored alternative; timing cases assert non-match at ≈ 80 KB.
|
||||
Executor rulings (Part 1, 2026-10-20): METADATA_KEY alternation `expires?(?:_in)?` so `token_expires_in` is metadata (plan regex missed it); oracle 12 wrapped in a subshell (orchestrator oracle defect). [gated 2026-10-20]
|
||||
Executor rulings (Part 2, 2026-10-20): oracle 17 gains an `index.js` (a lone .map leaves the exposure domain not applicable, orchestrator oracle defect); SKILL.md Part 1 sentence reworded "Before adding `--authorized`" to match criterion 20's grep; oracle 15 negative grep narrowed to the INJ-NOSQL-OPERATOR row (g.ts under src/api also raises API-ROUTE-NO-AUTH, orchestrator oracle defect).
|
||||
Severities never change: INJ-NOSQL-OPERATOR WARN, INJ-SQL-CONCAT FAIL, INJ-SQL-RAW-UNSAFE WARN.
|
||||
|
||||
## ACCEPTANCE CRITERIA
|
||||
1. Probe suite green.
|
||||
CHECK: make test suite=lib/tests/guardrails-probe.test.sh >/dev/null 2>&1 && echo PT-GREEN
|
||||
EXPECT: PT-GREEN
|
||||
EVIDENCE: MET exit=0 marker-found :: PT-GREEN
|
||||
2. Scan suite green.
|
||||
CHECK: make test suite=lib/tests/guardrails-scan.test.sh >/dev/null 2>&1 && echo ST-GREEN
|
||||
EXPECT: ST-GREEN
|
||||
EVIDENCE: MET exit=0 marker-found :: ST-GREEN
|
||||
3. a11y suite green untouched (shared engine).
|
||||
CHECK: make test suite=lib/tests/a11y-scan.test.sh >/dev/null 2>&1 && git diff --quiet develop -- lib/tests/a11y-scan.test.sh && echo A11Y-GREEN
|
||||
EXPECT: A11Y-GREEN
|
||||
EVIDENCE: MET exit=0 marker-found :: A11Y-GREEN
|
||||
4. Full suite and shellcheck green.
|
||||
CHECK: make test >/dev/null 2>&1 && shellcheck *.sh hooks/*.sh lib/*.sh && echo ALL-GREEN
|
||||
EXPECT: ALL-GREEN
|
||||
EVIDENCE: MET exit=0 marker-found :: ALL-GREEN
|
||||
5. A1: a non-http(s) `supabase.url` is a usage error (exit 2) naming it; tables without a url is a usage error too; no traceback.
|
||||
CHECK: p=$(mktemp); printf '{"base_url":"http://127.0.0.1:9","supabase":{"url":"file:///etc/hosts","tables":["t"]}}' > "$p"; python3 -B skills/guardrails/scripts/probe.py "$p" --authorized >/dev/null 2>"$p.err"; rc=$?; q=$(mktemp); printf '{"base_url":"http://127.0.0.1:9","supabase":{"tables":["t"]}}' > "$q"; python3 -B skills/guardrails/scripts/probe.py "$q" --authorized >/dev/null 2>"$q.err"; rc2=$?; [ "$rc" -eq 2 ] && [ "$rc2" -eq 2 ] && grep -q 'supabase.url must be an http(s) url' "$p.err" && ! grep -q Traceback "$q.err" && echo A1-URL-GUARDED
|
||||
EXPECT: A1-URL-GUARDED
|
||||
EVIDENCE: MET exit=0 marker-found :: A1-URL-GUARDED
|
||||
6. A1: the refusal names the Supabase url next to base_url, control characters replaced.
|
||||
CHECK: p=$(mktemp); printf '{"base_url":"http://127.0.0.1:9","supabase":{"url":"https://a.test/\\u001b[2J","tables":["t"]}}' > "$p"; python3 -B skills/guardrails/scripts/probe.py "$p" 2>&1 | grep -q 'confirm you own http://127.0.0.1:9 and https://a.test/?\[2J' && echo A1-REFUSAL-BOTH
|
||||
EXPECT: A1-REFUSAL-BOTH
|
||||
EVIDENCE: MET exit=0 marker-found :: A1-REFUSAL-BOTH
|
||||
7. A2: budget exhaustion is one constant reported by `fetch`, before and inside a redirect.
|
||||
CHECK: cd skills/guardrails/scripts && python3 -B -c 'import probe; s=probe.Session(budget=0); r=probe.fetch(s,"GET","http://127.0.0.1:9/"); assert r.error==probe.BUDGET_EXHAUSTED, r.error; assert issubclass(probe._BudgetExhausted, Exception); import inspect; assert "session" in inspect.signature(probe._SameHost.__init__).parameters; print("A2-BUDGET-CONST")'
|
||||
EXPECT: A2-BUDGET-CONST
|
||||
EVIDENCE: MET exit=0 marker-found :: A2-BUDGET-CONST
|
||||
8. A2: a redirect chain is charged per hop and an exhausted budget mid-chain reads ERROR on a route probe (locked in the probe suite).
|
||||
CHECK: grep -q 'DEFAULT_BUDGET - 3' lib/tests/guardrails-probe.test.sh && grep -q 'budget=2' lib/tests/guardrails-probe.test.sh && grep -q '/hop1' lib/tests/guardrails-probe.test.sh && echo A2-HOPS-LOCKED
|
||||
EXPECT: A2-HOPS-LOCKED
|
||||
EVIDENCE: MET exit=0 marker-found :: A2-HOPS-LOCKED
|
||||
9. A3: a 200 body the probe cannot read as JSON rows is `unreadable` (→ SKIPPED), an empty list is `empty`, rows are `rows`.
|
||||
CHECK: cd skills/guardrails/scripts && python3 -B -c 'import probe; R=probe.Response; print(probe._rows_state(R(200,{},b"["*200000)), probe._rows_state(R(200,{},b"[]")), probe._rows_state(R(200,{},b"[{\"a\":1}]")))' | grep -q '^unreadable empty rows$' && echo A3-THREE-WAY
|
||||
EXPECT: A3-THREE-WAY
|
||||
EVIDENCE: MET exit=0 marker-found :: A3-THREE-WAY
|
||||
10. A4: the scanner's text output never carries control characters, in the report, the check-mode rows and the usage error, while the finding still raises.
|
||||
CHECK: d=$(mktemp -d); mkdir -p "$d/src/components"; f="$d/src/components/$(printf 'x\033[31m').tsx"; printf 'export default function X({user}){ console.log(user); return null }\n' > "$f"; o=$(python3 -B skills/guardrails/scripts/scan.py "$d" 2>&1); a=$(python3 -B skills/guardrails/scripts/scan.py "$d" --assert-absent "EXP-CONSOLE-DATA:src/components/$(printf 'x\033[31m').tsx" 2>&1); printf '%s\n%s\n' "$o" "$a" | grep -q 'EXP-CONSOLE-DATA' && [ "$(printf '%s%s' "$o" "$a" | grep -c $'\033')" -eq 0 ] && printf '%s\n' "$a" | grep -q 'PRESENT' && echo A4-PRINTABLE
|
||||
EXPECT: A4-PRINTABLE
|
||||
EVIDENCE: MET exit=0 marker-found :: A4-PRINTABLE
|
||||
11. B1: metadata keys are never sensitive, matched after snake-casing; real secrets still are.
|
||||
CHECK: cd skills/guardrails/scripts && python3 -B -c 'import probe; m=lambda k: bool(probe.METADATA_KEY.search(probe._snake(k))); assert all(m(k) for k in ["tokenType","has_password","next_page_token","token_expires_in","password_changed_at","csrf_token"]); assert not any(m(k) for k in ["password_hash","api_key","access_token","secret"]); print("B1-METADATA")'
|
||||
EXPECT: B1-METADATA
|
||||
EVIDENCE: MET exit=0 marker-found :: B1-METADATA
|
||||
12. B2/B13: every map candidate is examined; a line-start `data:` directive is OPEN without decoding; an unconfirmed status is a note, never a negative.
|
||||
CHECK: (cd skills/guardrails/scripts && python3 -B -c 'import probe; s=probe.Session(budget=0); k=lambda u: probe._map_outcome(s,"http://h.test/a.js",u)[0]; assert k("data:application/json,%7B%22version%22%3A3%7D")=="open"; assert k("data:application/json;base64,eyJ2ZXJzaW9uIjozfQ==")=="open"; assert k("https://cdn.invalid/a.js.map")=="note"; print("B2-OUTCOMES")') && grep -q 'forbidden-real' lib/tests/guardrails-probe.test.sh && grep -q 'limited.js' lib/tests/guardrails-probe.test.sh && echo B2-WALK-LOCKED
|
||||
EXPECT: B2-WALK-LOCKED
|
||||
EVIDENCE: MET exit=0 marker-found :: B2-OUTCOMES B2-WALK-LOCKED
|
||||
13. B3: hydrated scope is the export chunk of the loader: a Remix action after a clean loader is silent, a one-line loader returning a token raises.
|
||||
CHECK: d=$(mktemp -d); mkdir -p "$d/app/routes"; printf 'export async function loader() {\n return json({ ok: true });\n}\nexport async function action({ request }) {\n const form = await request.formData();\n return json({ password: form.get("password") });\n}\n' > "$d/app/routes/a.tsx"; printf 'export const loader = () => json({ token: t });\n' > "$d/app/routes/b.tsx"; o=$(python3 -B skills/guardrails/scripts/scan.py "$d" --json 2>/dev/null); printf '%s' "$o" | grep -q 'EXP-HYDRATED-SENSITIVE' && ! printf '%s' "$o" | grep -q 'routes/a.tsx' && echo B3-CHUNK-SCOPED
|
||||
EXPECT: B3-CHUNK-SCOPED
|
||||
EVIDENCE: MET exit=0 marker-found :: B3-CHUNK-SCOPED
|
||||
14. B4/B5: a webpack dev config and a UI-suffixed data attribute are silent; a prod config and a value-carrying attribute still raise.
|
||||
CHECK: d=$(mktemp -d); mkdir -p "$d/src/components"; printf 'module.exports = { devtool: "eval-source-map" };\n' > "$d/webpack.dev.js"; printf 'module.exports = { devtool: "source-map" };\n' > "$d/webpack.prod.js"; printf 'export const A = () => <div data-password-toggle="true" data-hide-api-key={k} />;\n' > "$d/src/components/A.tsx"; o=$(python3 -B skills/guardrails/scripts/scan.py "$d" 2>/dev/null); printf '%s\n' "$o" | grep -q 'EXP-SOURCEMAP-PUBLIC *webpack.prod.js' && ! printf '%s\n' "$o" | grep -q 'webpack.dev.js' && [ "$(printf '%s\n' "$o" | grep -c 'EXP-DATA-ATTR-SENSITIVE')" -eq 1 ] && echo B4-B5-SILENT
|
||||
EXPECT: B4-B5-SILENT
|
||||
EVIDENCE: MET exit=0 marker-found :: B4-B5-SILENT
|
||||
15. B6: `$where` with a string, an identifier or a call is WARN INJ-NOSQL-OPERATOR; a GraphQL `_bool_exp` type is silent.
|
||||
CHECK: d=$(mktemp -d); mkdir -p "$d/src/api"; printf 'db.find({ $where: clause });\ndb.find({ $where: buildWhere(req.query) });\n' > "$d/src/api/m.ts"; printf 'const q = gql`query($where: users_bool_exp) { users(where: $where) { id } }`;\n' > "$d/src/api/g.ts"; o=$(python3 -B skills/guardrails/scripts/scan.py "$d" 2>/dev/null); [ "$(printf '%s\n' "$o" | grep -c 'WARN *INJ-NOSQL-OPERATOR *src/api/m.ts')" -eq 2 ] && ! printf '%s\n' "$o" | grep -q 'INJ-NOSQL-OPERATOR *src/api/g.ts' && echo B6-WHERE
|
||||
EXPECT: B6-WHERE
|
||||
EVIDENCE: MET exit=0 marker-found :: B6-WHERE
|
||||
16. B7: Go backtick Sprintf, a multi-line triple-quoted f-string, `sql.raw(var)`, `.select()` on users and a multi-line hidden input all raise.
|
||||
CHECK: d=$(mktemp -d); mkdir -p "$d/src/api" "$d/src/components"; printf 'package a\nfunc q(o string) string { return fmt.Sprintf(`select id from notes where owner = %%s`, o) }\n' > "$d/src/api/a.go"; printf 'def q(owner):\n return f"""\n select id from notes\n where owner = {owner}\n """\n' > "$d/src/api/b.py"; printf 'export const r = (w) => db.execute(sql.raw(w));\nexport const u = () => supabase.from("users").select();\n' > "$d/src/api/c.ts"; printf 'export const F = () => (\n <input\n type="hidden"\n name="api_key"\n value={k}\n />\n);\n' > "$d/src/components/F.tsx"; o=$(python3 -B skills/guardrails/scripts/scan.py "$d" 2>/dev/null); printf '%s\n' "$o" | grep -q 'FAIL *INJ-SQL-CONCAT *src/api/a.go' && printf '%s\n' "$o" | grep -q 'FAIL *INJ-SQL-CONCAT *src/api/b.py' && printf '%s\n' "$o" | grep -q 'WARN *INJ-SQL-RAW-UNSAFE *src/api/c.ts' && printf '%s\n' "$o" | grep -q 'EXP-RESPONSE-WIDE *src/api/c.ts' && printf '%s\n' "$o" | grep -q 'EXP-DATA-ATTR-SENSITIVE *src/components/F.tsx' && echo B7-MISSES-COVERED
|
||||
EXPECT: B7-MISSES-COVERED
|
||||
EVIDENCE: MET exit=0 marker-found :: B7-MISSES-COVERED
|
||||
17. B12: a public map over 1 MB in rollup key order (mappings last) is FAIL.
|
||||
CHECK: d=$(mktemp -d); mkdir -p "$d/public"; printf 'export const a = 1;\n' > "$d/index.js"; { printf '{"version":3,"file":"app.js","sources":["a.ts"],"sourcesContent":["'; head -c 1100000 /dev/zero | tr '\0' 'x'; printf '"],"names":[],"mappings":"AAAA"}'; } > "$d/public/app.js.map"; python3 -B skills/guardrails/scripts/scan.py "$d" 2>/dev/null | grep -q 'FAIL *EXP-SOURCEMAP-PUBLIC *public/app.js.map' && echo B12-ROLLUP-MAP
|
||||
EXPECT: B12-ROLLUP-MAP
|
||||
EVIDENCE: MET exit=0 marker-found :: B12-ROLLUP-MAP
|
||||
18. B9: the timing lock covers the CONCAT alternatives, NOSQL and HIDDEN_INPUT with non-matching inputs.
|
||||
CHECK: awk '/== regex timing/,/REGEX-FAST/' lib/tests/guardrails-scan.test.sh > /tmp/timing-block.$$; grep -q 'injection.CONCAT' /tmp/timing-block.$$ && grep -q 'injection.NOSQL' /tmp/timing-block.$$ && grep -q 'exposure.HIDDEN_INPUT' /tmp/timing-block.$$ && grep -q 'is None' /tmp/timing-block.$$ && grep -q 'export const load' /tmp/timing-block.$$ && rm -f /tmp/timing-block.$$ && echo B9-TIMING-COVERS
|
||||
EXPECT: B9-TIMING-COVERS
|
||||
EVIDENCE: MET exit=0 marker-found :: B9-TIMING-COVERS
|
||||
19. B10: per-variant locks exist (routing-dependent mutants plus the sub-pattern table).
|
||||
CHECK: grep -q '== per-variant' lib/tests/guardrails-scan.test.sh && [ "$(grep -c '^mutant ' lib/tests/guardrails-scan.test.sh)" -ge 100 ] && grep -q 'Command::new' lib/tests/guardrails-scan.test.sh && grep -q 'getTraceAsString' lib/tests/guardrails-scan.test.sh && echo B10-VARIANTS
|
||||
EXPECT: B10-VARIANTS
|
||||
EVIDENCE: MET exit=0 marker-found :: B10-VARIANTS
|
||||
20. B8/B11 docs: the judging bullet, the RAW receivers, the metadata exclusion, the data: wording, the bearer sentence and the both-hosts step are in the skill docs.
|
||||
CHECK: grep -q 'placeholders' skills/guardrails/SKILL.md && grep -q 'logged-in user sees' skills/guardrails/SKILL.md && grep -qi 'before adding `--authorized`' skills/guardrails/SKILL.md && grep -q '`--json` output' skills/guardrails/SKILL.md && grep -q 'sql.raw' skills/guardrails/references/checks.md && grep -q '_bool_exp' skills/guardrails/references/checks.md && grep -qi 'metadata' skills/guardrails/references/checks.md && grep -q 'exhausted budget' skills/guardrails/references/checks.md && echo DOCS-SYNCED
|
||||
EXPECT: DOCS-SYNCED
|
||||
EVIDENCE: MET exit=0 marker-found :: DOCS-SYNCED
|
||||
21. Pre-existing dirty files never staged or committed.
|
||||
CHECK: ! git diff --cached --name-only | grep -Eq '^(settings.json|mods/model-router/routing.json)$' && [ -z "$(git log --oneline develop..HEAD -- settings.json mods/model-router/routing.json)" ] && echo DIRTY-UNTOUCHED
|
||||
EXPECT: DIRTY-UNTOUCHED
|
||||
EVIDENCE: MET exit=0 marker-found :: DIRTY-UNTOUCHED
|
||||
22. No new lint or test suppression in the diff (floor-guard clean).
|
||||
CHECK: bash lib/floor-guard.sh develop -- . >/dev/null 2>&1 && echo FLOOR-CLEAN
|
||||
EXPECT: FLOOR-CLEAN
|
||||
EVIDENCE: MET exit=0 marker-found :: FLOOR-CLEAN
|
||||
|
||||
## FILE SCOPE
|
||||
skills/guardrails/scripts/probe.py
|
||||
skills/guardrails/scripts/scanner.py
|
||||
skills/guardrails/scripts/checks/common.py
|
||||
skills/guardrails/scripts/checks/exposure.py
|
||||
skills/guardrails/scripts/checks/injection.py
|
||||
skills/guardrails/references/checks.md
|
||||
skills/guardrails/SKILL.md
|
||||
lib/tests/guardrails-scan.test.sh
|
||||
lib/tests/guardrails-probe.test.sh
|
||||
.claude/tasks/plans/2026-10-20-guardrails-residuals-1410.md
|
||||
.claude/tasks/contracts/2026-10-20-guardrails-residuals-1455.md
|
||||
.claude/tasks/TODO.md
|
||||
.claude/tasks/plans/2026-10-20-guardrails-residuals-part1-report.md [gated 2026-10-20: executor report, orchestrator artifact]
|
||||
.claude/tasks/plans/2026-10-20-guardrails-residuals-part2-report.md [gated 2026-10-20: executor report, orchestrator artifact]
|
||||
.claude/tasks/plans/2026-10-20-guardrails-residuals-part3-report.md [gated 2026-10-20: executor report, orchestrator artifact]
|
||||
@@ -0,0 +1,244 @@
|
||||
# FIX PLAN r3 — guardrails residuals after the a11y split (TODO.md lines 5-6)
|
||||
|
||||
Base: develop f586304. Analysis: scratchpad `bugfix-analysis.md` (analyzer, read-only).
|
||||
r1 and r2 challenged by three lenses each; r3 closes every r2 BLOCKER/MAJOR by
|
||||
a named change (see "Challenge log"). No further challenge round (lib: one
|
||||
re-challenge); residual MINORs are listed as blind spots in checks.md.
|
||||
|
||||
Three executor parts, split by file, sequential on the same branch. Every rule
|
||||
change ships a mutant (raises); every false-positive fix and every regex
|
||||
widening ships a benign lock (stays silent); every new or widened repeat ships
|
||||
a timing case that asserts BOTH `search(text) is None` AND < 1.0 s, sized to
|
||||
about 0.2 s on this machine (5x margin). Suites: `make test suite=lib/tests/guardrails-probe.test.sh`
|
||||
(PT), `make test suite=lib/tests/guardrails-scan.test.sh` (ST), full `make test`
|
||||
once at the end. Rule ids, severities and exit codes never change (BDR-121):
|
||||
INJ-NOSQL-OPERATOR WARN, INJ-SQL-CONCAT FAIL, INJ-SQL-RAW-UNSAFE WARN.
|
||||
Shell suites: portable idioms only (`edit()` helper, no `sed -i`, BDR-110).
|
||||
|
||||
Shared helper, written in Part 1, reused in Part 2 — `checks/common.py`:
|
||||
```python
|
||||
def printable(text):
|
||||
"""Control characters of a remote string, path or message never reach the tty."""
|
||||
return re.sub(r"[\x00-\x1f\x7f-\x9f\udc80-\udcff]", "?", str(text))
|
||||
```
|
||||
probe.py deletes `_printable` and does `from checks.common import printable`
|
||||
(probe.py runs from `scripts/`, the package resolves like scan.py's import).
|
||||
|
||||
## Part 1 — probe.py + lib/tests/guardrails-probe.test.sh
|
||||
|
||||
A1 `_shape_error`: whenever `supabase` has `tables` or `cross_user_paths`, an
|
||||
http(s) `url` is required (`"supabase.url must be an http(s) url"`) and
|
||||
`tables`, when present, must be a list of strings
|
||||
(`"supabase.tables must be a list of strings"`). `main`: the refusal prints both
|
||||
urls through `printable` (`refused: pass --authorized to confirm you own <base_url> and <supabase.url> and may probe them`,
|
||||
the "and …" part only when supabase.url is set); the `usage error:` line goes
|
||||
through `printable` too. PT: `file:///etc/hosts` url → exit 2 + message; tables
|
||||
without url → exit 2, no traceback; `"tables": "notes"` → exit 2; refusal on a
|
||||
supabase url holding an ESC byte → `?` shown, 0 ESC bytes in stderr.
|
||||
`skills/guardrails/SKILL.md` STEP 5 "Run it" (line ~97): before adding
|
||||
`--authorized`, show the user the two hosts the plan names (base_url and the
|
||||
Supabase url, the latter taken from the project's config and therefore
|
||||
untrusted) and get their go on both; one sentence, single line (loops-light
|
||||
locks STEP 9-11 strings only).
|
||||
|
||||
A2 budget on redirects. probe.py defines
|
||||
`BUDGET_EXHAUSTED = "request budget exhausted"` and
|
||||
`class _BudgetExhausted(urllib.error.URLError)`. `_SameHost(session)`:
|
||||
`Session.__init__` builds `build_opener(_SameHost(self))`; `redirect_request`:
|
||||
off-host → None (unchanged); `self.session.budget <= 0` →
|
||||
`raise _BudgetExhausted(BUDGET_EXHAUSTED)`; else decrement and delegate.
|
||||
`fetch`: the pre-check returns `Response(None, {}, b"", BUDGET_EXHAUSTED)`;
|
||||
`except _BudgetExhausted` (before the URLError clause) returns the same. So the
|
||||
error string is one constant everywhere. `_rate_verdict`: when fewer than the
|
||||
requested count were answered and no 429 was seen → SKIPPED
|
||||
`"burst cut short (budget or transport), rate limit not confirmed"`, never OPEN.
|
||||
PT: fixture routes `/hop1` → 302 `/hop2` → 302 `/hop3` → 200 `{"ok": true}`.
|
||||
Python block on the PT `same_host` pattern (~378-383): `Session()` +
|
||||
`fetch(s, "GET", BASE + "/hop1")` → status 200 and `s.budget == DEFAULT_BUDGET - 3`;
|
||||
`Session(budget=2)` + same fetch → `error == probe.BUDGET_EXHAUSTED`; and
|
||||
`_route_probe(Session(budget=2), BASE, {"path": "/hop1"})` → verdict ERROR.
|
||||
No new plan file, nothing added to `plan.json`.
|
||||
|
||||
A3 rows state. `_verdict` keeps handling the transport error first (ERROR). For
|
||||
`_table_probe` and `_cross_user_probe`: status 200 → three-way
|
||||
`_rows_state(resp)` through `_json_body`: `[]` or a non-list JSON → `empty`
|
||||
(CLOSED, notes unchanged); a non-empty list → `rows` (OPEN); parse failure
|
||||
(RecursionError, ValueError, empty body, truncated at BODY_CAP) → `unreadable`
|
||||
→ SKIPPED `f"HTTP {resp.status}: body not readable as JSON rows, not confirmed"`.
|
||||
Status 401/403/404 → CLOSED as today; any other non-200 → SKIPPED
|
||||
`f"HTTP {resp.status}: not confirmed"`. PT: fixture route `/rest/v1/deep`
|
||||
answering 200 with `b"[" * 200000`; plan `deep.json` with
|
||||
`"supabase": {"url": BASE, "tables": ["deep"]}` run with `GUARDRAILS_ANON_KEY=test-anon`
|
||||
→ `anon-read:deep` SKIPPED, no `Traceback` in stderr; cross-user on
|
||||
`/api/guarded` (401) stays CLOSED (lock it).
|
||||
|
||||
B1 metadata keys. `METADATA_KEY = re.compile(r"^(?:has|is|needs|requires)_|_(?:type|count|length|url|expires?|expiry|ttl|at)$|^(?:next_page_token|page_token|cursor|csrf_?token|xsrf_?token)$")`
|
||||
tested on `_snake(k)` before SENSITIVE_KEY; a metadata key is never sensitive.
|
||||
PT: `/api/me` keeps `next_page_token`; the lock at ~248 becomes
|
||||
`api_key, password_hash$`; new route `/meta/keys` →
|
||||
`{"tokenType": "bearer", "has_password": true, "token_expires_in": 3600, "password_changed_at": "2026"}`
|
||||
→ fields CLOSED (camelCase proves the snake-cased match; `token_expires_in` and
|
||||
`password_changed_at` are sensitive today).
|
||||
|
||||
B2 + B13 `_map_verdict` walks every candidate. Candidates: resolve each through
|
||||
`_same_host` first; dedupe on the resolved url, else on the raw url. Split a
|
||||
per-candidate classifier `_map_outcome(session, script_url, url) -> (kind, target, note)`
|
||||
with kind in `open | negative | note | error` out of the loop (25-line limit).
|
||||
Per candidate:
|
||||
- `data:` url (always a line-start `sourceMappingURL` directive since c0fdbec)
|
||||
→ `open`, note `inline source map in the script`, no decoding (base64 and
|
||||
percent-encoded alike; the `"base64," not in url: continue` guard is deleted).
|
||||
- off-host → `note` `map url on another host, not fetched`.
|
||||
- transport error (incl. BUDGET_EXHAUSTED) → `error` → return ERROR now (today's behaviour).
|
||||
- 200 at BODY_CAP → `note` (checked BEFORE the sources test; PT /bigmap.js.map lock stays SKIPPED).
|
||||
- 200 with `"sources"` → `open`.
|
||||
- 404, 410, or 200 without sources → `negative`.
|
||||
- any other status (3xx, 401, 403, 429, 5xx…) → `note` `f"HTTP {status}: map not readable, not confirmed"`.
|
||||
After the loop: any note → `("SKIPPED", first noted target, its note)`, else CLOSED.
|
||||
PT, in a NEW plan file `maps2.json` (maps.json already lists 8 of SCRIPT_CAP 10):
|
||||
`/forbidden.js` (comment → `/forbidden-real.js.map`; `/forbidden.js.map` → 403;
|
||||
`/forbidden-real.js.map` → 200 with sources) → OPEN; `/pct.js`
|
||||
(`sourceMappingURL=data:application/json,%7B%22version%22%3A3%7D`) → OPEN;
|
||||
`/limited.js` (bare map → 429) → SKIPPED. Existing `/err.js` 503 and
|
||||
`/inline.js` / `/biginline.js` locks stay.
|
||||
|
||||
## Part 2 — engine, checks, docs, lib/tests/guardrails-scan.test.sh
|
||||
|
||||
A4 scanner.py: one helper `_safe_text(text)` = `"\n".join(printable(l) for l in text.split("\n"))`
|
||||
applied at the three text print sites (the text report, the check-mode lines,
|
||||
the usage error); JSON untouched. ST: mutant with an ESC byte in a file name AND
|
||||
in a supabase policy name (supabase.py:160 echoes it in `f.message`): 0 ESC bytes
|
||||
in the text report; a `--assert-absent RULE:<ESC-named path>` run prints the
|
||||
PRESENT row with `?` and 0 ESC bytes; a `--baseline` run 0 ESC bytes; findings
|
||||
still raise. `SKILL.md` STEP 9 (~187-195): one sentence "pairs come from the
|
||||
`--json` output, never from the text report". a11y suite stays green untouched.
|
||||
|
||||
B3 `_hydrated` scoped by export chunks. One `finditer` of `^export\b` (re.M)
|
||||
gives chunk starts (plus offset 0, EOF). For each chunk holding a LOADER match,
|
||||
run `HYDRATED.finditer(text, line_start_of_first_match, chunk_end)`; offsets are
|
||||
absolute, chunks disjoint, no merge. A `window.__X__ =` match is a LOADER member
|
||||
and follows the same rule. Findings through `dedupe_lines`. ST mutants (WARN):
|
||||
Prettier multi-line-params `getServerSideProps` with `}) => {`; one-line
|
||||
`export const loader = () => json({ token: t });`; multi-line Remix `loader`;
|
||||
SvelteKit `export async function load()`; multi-line `window.__STATE__ = {\n token: t\n}`.
|
||||
Benigns: clean `loader` followed by an `action` holding `password: form.get("password")`;
|
||||
`// getServerSideProps` comment above a clean loader. Timing case: 1 MB of
|
||||
`export const load = 1\n` through the chunk builder + HYDRATED, < 1.0 s.
|
||||
checks.md blind spots: a non-exported helper between two exports is still
|
||||
scanned (false positive as today); a sensitive object built in a helper above
|
||||
the loader is missed; a fix that moves the key above the loader clears the
|
||||
oracle, the STEP 3 judge re-reads the whole loader.
|
||||
|
||||
B4 `_map_config`: `other = [p for p in _named(project, "webpack") if p not in prod and not DEV_TOKEN.search(p.name)]`.
|
||||
ST: benigns `webpack.dev.js`, `webpack.config.dev.js` with `devtool: 'eval-source-map'`;
|
||||
`webpack.config.js` still WARN; mutant `webpack.prod.js` with the same devtool → FAIL.
|
||||
|
||||
B5 DATA_ATTR: the sensitive word list becomes one constant `SENSITIVE_WORD`
|
||||
used by DATA_ATTR and by `UI_ATTR = re.compile(rf"{SENSITIVE_WORD}-(?:toggle|visible|visibility|show|hide|reveal|mask|strength|meter|hint|label|placeholder|confirm|error|required|pattern)$", re.I)`
|
||||
tested with `search` on the captured name (anchored at its end) → silent.
|
||||
ST: benigns `data-password-toggle="true"`, `data-password-strength="3"`,
|
||||
`data-secret-visible`; mutants `data-password="hunter2"`, `data-hide-api-key={k}`,
|
||||
`data-api-key-input-value={v}` still WARN.
|
||||
|
||||
B6 NOSQL `$where`: `\$where\s*:\s*(?!\w{0,64}_(?:bool_)?exp\b|[A-Z]\w{0,64}!?\s*[),])(?:['"`]|\w)`
|
||||
(bounded repeats; excludes GraphQL `_bool_exp` types and a Capitalised type
|
||||
followed by `)` or `,`). ST mutants (WARN): `{ $where: "this.name == '" + name + "'" }`,
|
||||
`{ $where: clause }`, `{ $where: buildWhere(req.query) }`; benign
|
||||
`$where: users_bool_exp` and `($where: UsersWhere)` in a `.ts` gql template.
|
||||
Blind spot (checks.md): `$where: PascalCase` or `*_exp` identifiers.
|
||||
Timing case added (B9).
|
||||
|
||||
B7 misses, one mutant each, clean fixture stays 0/0:
|
||||
- Go: CONCAT `.go` → `fmt\.Sprintf\(\s*(?:\"{DQ}?{STMT}|`\s{0,40}{STMT})`; mutants
|
||||
double-quoted and backtick (statement first). Blind spot: a raw literal whose
|
||||
statement keyword does not open it.
|
||||
- RAW JS adds `\b(?:sql|db|trx|knex)\.raw` (non-literal argument → WARN).
|
||||
- Python `rf""` / `fr""`: first `.py` alternative `\b(?:rf|fr|f)['\"]...`.
|
||||
- Triple-quoted f-strings: alternative `\b(?:rf|fr|f)(?:\"\"\"|''')\s{0,40}{STMT}`
|
||||
(STMT-anchored like the single-quote form, no `{` required). Mutant: multi-line
|
||||
`f"""\n select id from notes\n where owner = {owner}\n"""`; benign plain
|
||||
`"""select … %s"""`. Blind spot: a literal whose first non-blank line holds no
|
||||
statement (comment first).
|
||||
- Supabase `.select()` empty → WIDE `\.select\(\s*(?:['\"]\*['\"]\s*)?\)`.
|
||||
- HIDDEN_INPUT `<input\b[^>]{0,300}>` (newlines allowed, bounded); mutant with
|
||||
`type="hidden"` and `name="api_key"` on separate lines.
|
||||
|
||||
B8 docs, one pass. `SKILL.md` judging step (~50-57): bullet "INJ-SQL-CONCAT on
|
||||
`IN (${placeholders})` where the list is generated `?`/`$n` markers and the
|
||||
values travel in a separate array: parameterised, confirm by hand and drop it
|
||||
from the proposals." `references/checks.md`: :41 RAW row adds `sql.raw`,
|
||||
`db.raw`, `trx.raw`; :44 `$where` row "a string, an identifier or a function
|
||||
(GraphQL `_bool_exp` and Capitalised types excluded)"; :52 webpack "WARN
|
||||
elsewhere, dev configs silent"; :59 EXP-RESPONSE-WIDE adds `.select()`;
|
||||
:141 by-design list adds the generated `?` list, webpack dev configs,
|
||||
UI-suffixed data-* names, export-chunk scoping, metadata keys in the fields
|
||||
probe; :226 fields row mentions the metadata exclusion; :232 verdict wording
|
||||
"SKIPPED is a missing key or a body the probe could not read; ERROR is a
|
||||
transport failure or an exhausted budget"; sourcemap row: a line-start
|
||||
`data:` directive is OPEN whatever its encoding; blind spots list (B3, B6, B7
|
||||
above, 1 MB per-file CONCAT cost ≈ 3 s accepted).
|
||||
|
||||
B9 timing lock (ST ~506-528): ADD cases, each asserting `search is None` and
|
||||
< 1.0 s, sized ≈ 80 KB: JS backtick (`"`" + "select from " * N`), JS `'`-quoted,
|
||||
py `f'`, py `f"""`, Go `` fmt.Sprintf(` `` raw, NOSQL `$where: ` units,
|
||||
HIDDEN_INPUT `<input ` units, the B3 chunk case. Units carry no closing keyword
|
||||
(`select from `) so no alternative matches. Expected ≈ 0.1-0.2 s each here.
|
||||
|
||||
B11 `SKILL.md` ~96: after "never `service_role`." add "The fields probe sends
|
||||
`GUARDRAILS_JWT2` as a bearer when set, so an OPEN there is what a logged-in user sees."
|
||||
|
||||
B12 `_large_map`: head counts when `b'"mappings"' in head or b'"sources"' in head`.
|
||||
ST: mutant 1.1 MB `public/app.js.map` in rollup order (`{"version":3,"file":"app.js","sources":["a.ts"],"sourcesContent":["` + padding, `"mappings"` last) → FAIL;
|
||||
existing large-level-map benign stays silent.
|
||||
|
||||
## Part 3 — B10 per-variant locks (ST, plus minimal regex fixes and their checks.md rows)
|
||||
|
||||
Routing-dependent rows get end-to-end mutants: Rust `format!` (`.rs`), Django
|
||||
`.objects.raw(var)` and `.extra(` alone on their line, `knex.raw(var)` alone
|
||||
(dedupe), `sqlalchemy.text(` gate, `$executeRawUnsafe`, `sequelize.query`,
|
||||
`Sequelize.literal`, `GENERATE_SOURCEMAP=true` in `.env.production`, vite
|
||||
`sourcemap: true`, angular `sourceMap: true` (WARN), Rails
|
||||
`consider_all_requests_local = true` in `config/environments/production.rb`,
|
||||
`FLASK_DEBUG=1` in `.env.production`.
|
||||
Alternation-only rows go in one python table block (`regex.search(sample)`
|
||||
per row, next to the timing block): CONCAT py `%` and `.format(` tails, JS
|
||||
`'…' + x`, Ruby `"select … #{}"`; DYNAMIC_EXEC `execute var ||`; POSTGREST
|
||||
`.filter(` / `.not(` / `.match(` / `.textSearch(` and the `'…' + x` branch;
|
||||
NOSQL `find(req.body)`, `updateOne({x: req.body.y})`, `findOneAndUpdate`,
|
||||
`deleteMany`, `countDocuments`; SENDING forms (jsonify, JSONResponse,
|
||||
HTTPException, `detail=`, `echo`, `reply.send`, `ctx.body`); ERROR_STACK
|
||||
`traceback.format_exc`, `getTraceAsString()`, `json({ error: err })`;
|
||||
ERROR_MESSAGE `str(e)`, `repr(e)`, `->getMessage()`; `app.debug = True`;
|
||||
SHELL_DB heads (`Command::new`, `popen`, `passthru`, `proc_open`, `spawn`,
|
||||
`system`) and interpolations (`#{`, `{x}`, `%s`, `$var`).
|
||||
A row that does not match is a real miss: fix the regex minimally, add a benign
|
||||
lock for the widened form, a timing case if a repeat widens, and update its
|
||||
checks.md row. More than 5 regex edits in this part → `STATUS : NEED-DECISION`
|
||||
listing the rows, never widen further.
|
||||
|
||||
## Out of scope
|
||||
settings.json, mods/model-router/routing.json (pre-existing dirty, never staged).
|
||||
Other domains' missing mutants (api, hosting, supabase, messaging, functions).
|
||||
|
||||
## Gated answers [gated 2026-10-20]
|
||||
- Plan approved (r1), both parts; r2/r3 restructure into three parts by file.
|
||||
- B1: full METADATA_KEY list; `next_page_token` stops being reported.
|
||||
- B4 + B5: webpack dev configs and UI-suffixed data-* names are silent, each with a benign lock.
|
||||
- No new CLI flag (A2 locked through a python block).
|
||||
|
||||
## Challenge log
|
||||
r1 → r2: B6 mutants WARN; A2 URLError → ERROR; A3 three-way; B9 non-matching
|
||||
shapes; B2 allowlist; B3 spans; B5 anchored; B6 identifier branch kept; B10 own
|
||||
part; one `printable`; split by file; MINORs (DEV_TOKEN, `_at$`, url required,
|
||||
two map keys, RAW receivers, checks.md rows, base64 unchanged, dedupe, A4 locks,
|
||||
snake fixture, route names).
|
||||
r2 → r3 (all three lenses):
|
||||
- BLOCKER (c#1, r#1, s#3): `BUDGET_EXHAUSTED` constant + `_BudgetExhausted` subclass mapped in `fetch`; B2 keeps today's transport-error ERROR return.
|
||||
- MAJOR c#2 / r#2 / s#4: A3 gated on status (200 three-way; 401/403/404 CLOSED; other SKIPPED), error first, `/rest/v1/deep` route only, 401 cross-user lock.
|
||||
- MAJOR c#3 / s#2 / r#11: triple-quoted alternative = STMT-anchored form, multi-line mutant, blind spot documented.
|
||||
- MAJOR c#4 / r#4 / s#1: B3 export-chunk scoping (linear), Prettier mutant.
|
||||
- MAJOR c#5: Part 2 regains webpack.prod FAIL, loader/load/one-line WARN and double-quoted Go mutants.
|
||||
- MAJOR r#3: SKILL.md STEP 5 shows both hosts before `--authorized`.
|
||||
- MAJOR r#5 / r#6: timing cases assert non-match, sized ≈ 80 KB, 1 MB cost recorded as residual.
|
||||
- s#3 accepted in part: `data:` directive → OPEN without decoding (simplicity r1#3 now accepted: the directive is line-anchored, so the payload is observed); the base64 guard is deleted.
|
||||
- MINORs: tables typed (c#12, r#15); usage error printable (r#16); rate-limit SKIPPED on a cut burst (r#7); cap before sources, dedupe key (c#6, r#8); B5 end-anchored and shared word list (r#12, s#8); B6 bounded + timing (r#13, s#12); B12 OR (r#14, s#9); `expires_in` → `token_expires_in` (c#11); `_map_config` name (c#10); A4 single helper and ESC pair (s#6, c#7); JSON pairs sentence (r#17); docs rows (c#9); Part 3 table split and checks.md rows (s#10, s#11); hops.json dropped (s#5).
|
||||
@@ -0,0 +1,29 @@
|
||||
# Part 1 report — guardrails residuals (probe.py)
|
||||
|
||||
STATUS: DONE (one plan hole fixed, one oracle defect found)
|
||||
|
||||
Files: skills/guardrails/scripts/probe.py, skills/guardrails/scripts/checks/common.py
|
||||
(printable), skills/guardrails/SKILL.md (STEP 5 sentence), lib/tests/guardrails-probe.test.sh.
|
||||
|
||||
Applied: shared printable; A1 (supabase url/tables validation, refusal names both
|
||||
hosts, usage error printable, SKILL.md sentence); A2 (BUDGET_EXHAUSTED,
|
||||
_BudgetExhausted, _SameHost(session), rate verdict SKIPPED on cut burst); A3
|
||||
(_rows_state, _rows_verdict, 401/403/404 CLOSED, other non-200 SKIPPED); B1
|
||||
(METADATA_KEY, _is_sensitive); B2+B13 (_map_outcome, _status_outcome, walk of
|
||||
all candidates, dedupe on resolved url, data: always OPEN).
|
||||
|
||||
Tests: probe suite 84 passed 0 failed (70 passed 14 failed with probe.py and
|
||||
common.py stashed: negative control OK). a11y-scan 23/0, guardrails-scan 184/0.
|
||||
|
||||
Deviations:
|
||||
1. Plan hole: METADATA_KEY as written does not match `token_expires_in`
|
||||
(`_expires?$` needs the key to end there). Made it `expires?(?:_in)?`.
|
||||
Required by the plan's own PT and oracle 11.
|
||||
2. Oracle 12 (contract) is defective: after `cd skills/guardrails/scripts`
|
||||
its `grep -q ... lib/tests/...` uses a relative path and fails. The python
|
||||
half and both greps pass when run from the repo root. Orchestrator should
|
||||
fix the oracle (use an absolute path or a subshell).
|
||||
|
||||
Gates: criteria 1-9, 11, 21 MET. 12 NOT-MET for the oracle defect above.
|
||||
10, 13-20, 22 belong to Parts 2-3 (22 is a diff-wide check, re-run at the end).
|
||||
settings.json and routing.json untouched by me (pre-existing dirty).
|
||||
@@ -0,0 +1,20 @@
|
||||
# Part 2 report (guardrails-residuals)
|
||||
|
||||
STATUS DONE. Suites: guardrails-scan 222/0, a11y-scan 23/0, guardrails-probe 84/0. shellcheck on the scan suite clean.
|
||||
Gates rows 2,3,10,13-18,20 MET (19 = Part 3, 22 = floor guard, see below).
|
||||
|
||||
Files: scanner.py (_safe_text at the 3 text print sites, printable imported), checks/exposure.py (SENSITIVE_WORD, UI_ATTR, HIDDEN_INPUT multi-line, WIDE .select(), _map_config dev exclusion, _large_map "sources" key, _hydrated_spans export chunks + dedupe_lines), checks/injection.py (Go backtick, rf/fr, triple-quoted f, sql/db/trx.raw, $where exclusions), SKILL.md, references/checks.md, lib/tests/guardrails-scan.test.sh, contract (oracle rulings).
|
||||
|
||||
Negative control: with scanner/exposure/injection stashed the suite fails 20 checks (mutants, benigns, ESC, timing); restored after.
|
||||
Timing at ~80 KB: every new case < 0.01 s, chunk builder on 1 MB of `export const load` 0.03 s.
|
||||
|
||||
Choices the plan left open
|
||||
- Test layout: new `== residual misses` section uses `solo`-based `raises` helper; ESC checks in a new `== text output` section; timing python moved to $WORK/timing.py (heredoc inside $(...) broke on quotes/backticks).
|
||||
- Benigns that must stay 0/0 on the fixture sit under src/lib (src/api is a route dir and raises API-ROUTE-NO-AUTH); select-with-fields appended to $API.
|
||||
- Contract oracle defects fixed (contract is in scope): 17 gains an index.js (a lone .map leaves exposure not applicable); 15 negative grep narrowed to the INJ-NOSQL-OPERATOR row (g.ts also raises API-ROUTE-NO-AUTH).
|
||||
- SKILL.md Part 1 sentence reworded "Before adding it" -> "Before adding `--authorized`" so criterion 20's grep matches.
|
||||
- STEP 3 bullet placed after the blind-spot paragraph; `--json` pairs sentence placed in STEP 10 item 3 (where the RULE:path pairs are written), not STEP 9.
|
||||
- checks.md blind-spot bullets and by-design list extended as the plan lists.
|
||||
- A variable named PY in the suite's python made shellcheck read it as heredoc end: renamed PYC.
|
||||
|
||||
Concern: criterion 22 floor-guard flags only the contract text itself (line 116 mentions noqa); no suppression added by this diff.
|
||||
@@ -0,0 +1,8 @@
|
||||
# Part 3 report (B10 per-variant locks)
|
||||
STATUS DONE. Files: lib/tests/guardrails-scan.test.sh, skills/guardrails/scripts/checks/injection.py, skills/guardrails/references/checks.md.
|
||||
- `== per-variant` section: 17 end-to-end mutants (Rust format!, objects.raw, extra, knex.raw, executeRawUnsafe, sequelize.query/literal, GENERATE_SOURCEMAP, vite true, angular WARN, Rails, FLASK_DEBUG, app.debug, Rust/Ruby shell-db, PHP getTraceAsString, flask str(e)) + 2 benign locks. mutant lines 86 -> 103.
|
||||
- Python table in $WORK/timing.py: ~75 alternation rows (CONCAT, DYNAMIC_EXEC, POSTGREST, NOSQL, SENDING x ERROR_STACK/MESSAGE, SHELL_DB heads x interps incl. Command::new), regex.search per row.
|
||||
- One real miss: SHELL_INTERP lacked Rust positional `{}` (Command::new("psql").arg(format!("-c {}", q))). Widened with `\{\}(?=[^"{}\n]{0,12}"\s*,)` (bounded, `{}` must close a format string before `,`). Benign locks: execSync("psql ...", {}) and Rust argv. Timing case `system(psql {} ` x5000 (0.65 s at 90 KB; first widening with {0,200} took 1.85 s, narrowed). checks.md INJ-SHELL-DB-TOOL row updated.
|
||||
- Regex edits: 1 (limit 5).
|
||||
- Results: scan suite 241 passed 0 failed; make test all green; shellcheck ok; gates VERDICT MET (22/22).
|
||||
- Concern: SHELL_DB is pre-existing quadratic on single-line non-matching input (~0.5 s at 84 KB), margin to the 1 s timing lock is thin on slow machines.
|
||||
@@ -38,6 +38,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/) and this project
|
||||
- model-router residuals of the confirmation waves: a failed `/route forget` or `/route ask` write logs its cause and answers a generic text; forget answers clean every file-sourced name, phase and key; a restore names a frontmatter file only for a valid skill name and refuses a `__proto__` row; `/route forget` never restores `changed.phases`; the dialog's Change offers and writes shipped phases only (a machine-only phase never reaches routing.json, and an alias no shipped phase uses says so); a failure after the user answered keeps the key asked instead of asking again at every use.
|
||||
- `gitflow delete` (and `finish`) land on the base that contains the branch and drop the branch's upstream before `git branch -d`, so a branch whose upstream lags (manual-push mode) is deleted instead of refused by git (T18k).
|
||||
- An invalid `gitflow.autopush` value (not a boolean, or a config read that fails) no longer pushes. The post-commit / post-merge hooks and every push site of `lib/gitflow.sh` (`start`, `finish`, the `origin/` cleanup of `delete`) read it as auto and pushed; they now push nothing and say why. Each hook run prints `gitflow post-commit: gitflow.autopush unreadable (git rc <n>) — NOT pushed, treated as manual push mode; fix the value by hand` (post-merge likewise), and the lib passes through the `push-mode` verb's line, `gitflow.sh push-mode: gitflow.autopush='<value>' is not a boolean (git rc <n>)`. A repo with its own committed `.githooks/` (onboarded projects) keeps running its old hooks, which still push on an invalid value, until a session start runs `reconcile-hooks` and rewrites them; commit that refresh so other clones get it. Tests: `lib/gitflow-test.sh` T18q block.
|
||||
- `/guardrails` residuals. The live probe fails closed in more cases: every followed same-host redirect is charged to the request budget, and a budget that runs out mid-redirect reads ERROR; an anon-read or cross-user answer that is not a 200 or a refusal, or a 200 whose body is empty, over 1 MB or not JSON, reads SKIPPED instead of CLOSED; a rate-limit burst cut short by the budget or the transport reads SKIPPED; the source-map probe tries every candidate map of a script instead of stopping at the first it cannot confirm, and a `data:` map is OPEN whatever its encoding; the fields probe no longer flags metadata keys (`token_type`, `has_password`, `next_page_token`). The plan's Supabase `url` must be an http(s) url when tables or cross-user paths are set, `supabase.tables` must be a list of strings, and the `--authorized` refusal names both hosts. Scanner and probe text output strip control characters from file names and remote strings. Static rules lose false positives (hydrated state read per export chunk, webpack dev configs, `data-*` names with a UI suffix such as `-toggle` or `-strength`, GraphQL `_bool_exp` and capitalised types under `$where`) and gain detections: Go backtick SQL in `fmt.Sprintf`, `rf` / `fr` and triple-quoted Python f-strings, `sql.raw` / `db.raw` / `trx.raw`, an empty `.select()` on a users table, a hidden input spanning lines, a Rust `{}` argument to a DB shell tool, a large public `.map` whose head holds `"sources"`. Tests: `lib/tests/guardrails-scan.test.sh`, `lib/tests/guardrails-probe.test.sh`.
|
||||
|
||||
## [2.0.0] — 2026-10-06
|
||||
|
||||
|
||||
@@ -127,6 +127,31 @@ class H(BaseHTTPRequestHandler):
|
||||
if path == "/boom":
|
||||
return self._send(500, b"Traceback (most recent call last):\n"
|
||||
b' File "app.py", line 12, in handler\n')
|
||||
if path == "/hop1":
|
||||
return self._send(302, b"", {"Location": "/hop2"})
|
||||
if path == "/hop2":
|
||||
return self._send(302, b"", {"Location": "/hop3"})
|
||||
if path == "/hop3":
|
||||
return self._send(200, b'{"ok": true}')
|
||||
if path == "/rest/v1/deep":
|
||||
return self._send(200, b"[" * 200000)
|
||||
if path == "/meta/keys":
|
||||
return self._send(200, b'{"tokenType": "bearer", "has_password": true, '
|
||||
b'"token_expires_in": 3600, "password_changed_at": "2026"}',
|
||||
{"Content-Type": "application/json"})
|
||||
if path == "/forbidden.js":
|
||||
return self._send(200, b"f();\n//# sourceMappingURL=forbidden-real.js.map\n")
|
||||
if path == "/forbidden.js.map":
|
||||
return self._send(403, b"")
|
||||
if path == "/forbidden-real.js.map":
|
||||
return self._send(200, b'{"version":3,"sources":["f.ts"]}')
|
||||
if path == "/pct.js":
|
||||
return self._send(200, b"p();\n//# sourceMappingURL=data:"
|
||||
b"application/json,%7B%22version%22%3A3%7D\n")
|
||||
if path == "/limited.js":
|
||||
return self._send(200, b"l();\n")
|
||||
if path == "/limited.js.map":
|
||||
return self._send(429, b"")
|
||||
if path == "/api/me":
|
||||
return self._send(200, b'{"id": 1, "email": "t@t.io", '
|
||||
b'"password_hash": "x", "profile": {"api_key": "y"}, '
|
||||
@@ -245,7 +270,7 @@ check "the random 404 path is CLOSED" \
|
||||
check "sensitive keys in a JSON response are OPEN" \
|
||||
"$(verdict "$OUT" 'fields:/api/me')" OPEN
|
||||
check "the sensitive key names are listed, never the values" \
|
||||
"$(printf '%s\n' "$OUT" | grep -A1 'fields:/api/me' | grep -c 'api_key, next_page_token, password_hash$')" 1
|
||||
"$(printf '%s\n' "$OUT" | grep -A1 'fields:/api/me' | grep -c 'api_key, password_hash$')" 1
|
||||
check "a bare token key is OPEN, a bare private key is not" \
|
||||
"$(verdict "$OUT" 'fields:/api/session')" OPEN
|
||||
check "the session key list is token only" \
|
||||
@@ -336,6 +361,19 @@ check "a truncated script is SKIPPED" \
|
||||
check "an oversize map is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/bigmap.js')" SKIPPED
|
||||
|
||||
cat > "$WORK/maps2.json" <<EOF
|
||||
{"base_url": "$BASE",
|
||||
"exposure": {"scripts": ["/forbidden.js", "/pct.js", "/limited.js"],
|
||||
"error_routes": []}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/maps2.json")"
|
||||
check "a 403 first candidate does not hide a map the comment names" \
|
||||
"$(verdict "$OUT" 'sourcemap:/forbidden.js')" OPEN
|
||||
check "a percent-encoded data: source map is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/pct.js')" OPEN
|
||||
check "a 429 on the only map candidate is SKIPPED, never CLOSED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/limited.js')" SKIPPED
|
||||
|
||||
echo "== fields probe: depth and bearer"
|
||||
cat > "$WORK/fields.json" <<EOF
|
||||
{"base_url": "$BASE",
|
||||
@@ -390,6 +428,68 @@ check "a same-scheme same-host url is kept" \
|
||||
check "an http to https upgrade on the host is kept" \
|
||||
"$(same_host http://a.test/x https://a.test/y)" True
|
||||
|
||||
echo "== supabase plan, rows state, redirect budget, metadata keys"
|
||||
printf '{"base_url": "%s", "supabase": {"url": "file:///etc/hosts", "tables": ["t"]}}\n' \
|
||||
"$BASE" > "$WORK/sbfile.json"
|
||||
ERR="$(probe --authorized "$WORK/sbfile.json" 2>&1 >/dev/null)"
|
||||
check "a file:// supabase url exits 2" \
|
||||
"$(probe --authorized "$WORK/sbfile.json" >/dev/null 2>&1; echo $?)" 2
|
||||
check "the usage error names supabase.url" \
|
||||
"$(printf '%s\n' "$ERR" | grep -c 'supabase.url must be an http(s) url')" 1
|
||||
printf '{"base_url": "%s", "supabase": {"tables": ["t"]}}\n' "$BASE" > "$WORK/sbnourl.json"
|
||||
ERR="$(probe --authorized "$WORK/sbnourl.json" 2>&1 >/dev/null)"
|
||||
check "tables without a supabase url is a usage error, no traceback" \
|
||||
"$(printf '%s\n' "$ERR" | grep -c 'Traceback')" 0
|
||||
check "tables without a supabase url exits 2" \
|
||||
"$(probe --authorized "$WORK/sbnourl.json" >/dev/null 2>&1; echo $?)" 2
|
||||
printf '{"base_url": "%s", "supabase": {"url": "%s", "tables": "notes"}}\n' \
|
||||
"$BASE" "$BASE" > "$WORK/sbstr.json"
|
||||
check "a string tables exits 2" \
|
||||
"$(probe --authorized "$WORK/sbstr.json" >/dev/null 2>&1; echo $?)" 2
|
||||
printf '{"base_url": "%s", "supabase": {"url": "https://a.test/\\u001b[2J", "tables": ["t"]}}\n' \
|
||||
"$BASE" > "$WORK/sbesc.json"
|
||||
ERR="$(probe "$WORK/sbesc.json" 2>&1 >/dev/null)"
|
||||
check "the refusal names the supabase url, control character replaced" \
|
||||
"$(printf '%s\n' "$ERR" | grep -cF 'and https://a.test/?[2J')" 1
|
||||
check "no ESC byte reaches the refusal" \
|
||||
"$(printf '%s\n' "$ERR" | LC_ALL=C grep -c "$(printf '\033')")" 0
|
||||
cat > "$WORK/deep.json" <<EOF
|
||||
{"base_url": "$BASE", "supabase": {"url": "$BASE", "tables": ["deep"]}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/deep.json" 2>"$WORK/deep.err")"
|
||||
check "a deeply nested rows body is SKIPPED, never CLOSED" \
|
||||
"$(verdict "$OUT" 'anon-read:deep')" SKIPPED
|
||||
check "a deeply nested rows body raises no traceback" \
|
||||
"$(grep -c Traceback "$WORK/deep.err")" 0
|
||||
cat > "$WORK/cu401.json" <<EOF
|
||||
{"base_url": "$BASE", "supabase": {"url": "$BASE", "cross_user_paths": ["/api/guarded"]}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/cu401.json")"
|
||||
check "a cross-user read refused with 401 stays CLOSED" \
|
||||
"$(verdict "$OUT" 'cross-user:/api/guarded')" CLOSED
|
||||
cat > "$WORK/meta.json" <<EOF
|
||||
{"base_url": "$BASE", "routes": [{"path": "/meta/keys"}],
|
||||
"exposure": {"scripts": [], "error_routes": []}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/meta.json")"
|
||||
check "metadata keys (camelCase and snake) are never sensitive" \
|
||||
"$(verdict "$OUT" 'fields:/meta/keys')" CLOSED
|
||||
hops() { python3 -B -c '
|
||||
import sys
|
||||
sys.path.insert(0, sys.argv[1])
|
||||
import probe
|
||||
base = sys.argv[2]
|
||||
s = probe.Session()
|
||||
r = probe.fetch(s, "GET", base + "/hop1")
|
||||
print(r.status, s.budget == probe.DEFAULT_BUDGET - 3)
|
||||
s = probe.Session(budget=2)
|
||||
print(probe.fetch(s, "GET", base + "/hop1").error == probe.BUDGET_EXHAUSTED)
|
||||
print(probe._route_probe(probe.Session(budget=2), base,
|
||||
{"path": "/hop1"}).verdict)' \
|
||||
"$ROOT/skills/guardrails/scripts" "$BASE"; }
|
||||
check "a redirect chain is charged per hop and exhaustion reads ERROR" \
|
||||
"$(hops | tr '\n' ' ')" "200 True True ERROR "
|
||||
|
||||
echo "== JSON output"
|
||||
check "json reports the open count" \
|
||||
"$(probe --authorized --json "$WORK/plan.json" \
|
||||
|
||||
@@ -254,6 +254,62 @@ mutant hydrated-identifier WARN EXP-HYDRATED-SENSITIVE \
|
||||
mutant console-next-page WARN EXP-CONSOLE-DATA \
|
||||
"printf '%s\n' 'export default function Home({ user }) { console.log(\"render\", user); return null; }' > src/pages/index.tsx"
|
||||
|
||||
echo "== residual misses (hydrated chunks, dev configs, Go/py/Drizzle forms)"
|
||||
raises() { # raises <label> <file> <content> <SEVERITY> <RULE>: one-file mutant
|
||||
solo "$1" "$2" "$3"
|
||||
check "$1 raises $4 $5" "$(has "$4" "$5")" yes
|
||||
}
|
||||
HYD=EXP-HYDRATED-SENSITIVE
|
||||
raises hydrated-ssr-multiline-params src/pages/account.tsx \
|
||||
$'export async function getServerSideProps({\n req,\n}: Ctx) {\n return { props: { accessToken: tok } };\n}' WARN $HYD
|
||||
raises hydrated-loader-oneline app/routes/b.tsx \
|
||||
'export const loader = () => json({ token: t });' WARN $HYD
|
||||
raises hydrated-remix-multiline app/routes/c.tsx \
|
||||
$'export async function loader() {\n const t = await tok();\n return json({ token: t });\n}' WARN $HYD
|
||||
raises hydrated-sveltekit-load src/routes/+page.server.ts \
|
||||
$'export async function load() {\n return { token: await t() };\n}' WARN $HYD
|
||||
raises hydrated-window-state src/state.ts \
|
||||
$'window.__STATE__ = {\n token: t\n};' WARN $HYD
|
||||
mutant webpack-prod-devtool FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
"printf '%s\n' 'module.exports = { devtool: \"eval-source-map\" };' > webpack.prod.js"
|
||||
raises data-attr-literal-password src/components/D1.tsx \
|
||||
'export const D = () => <div data-password="hunter2" />;' WARN EXP-DATA-ATTR-SENSITIVE
|
||||
raises data-attr-hide-api-key src/components/D2.tsx \
|
||||
'export const D = () => <div data-hide-api-key={k} />;' WARN EXP-DATA-ATTR-SENSITIVE
|
||||
raises data-attr-api-key-input-value src/components/D3.tsx \
|
||||
'export const D = () => <div data-api-key-input-value={v} />;' WARN EXP-DATA-ATTR-SENSITIVE
|
||||
raises hidden-input-multiline src/components/F.tsx \
|
||||
$'export const F = () => (\n <input\n type="hidden"\n name="api_key"\n value={k}\n />\n);' WARN EXP-DATA-ATTR-SENSITIVE
|
||||
raises nosql-where-string src/api/m1.ts \
|
||||
'db.find({ $where: "this.name == '"'"'" + name + "'"'"'" });' WARN INJ-NOSQL-OPERATOR
|
||||
raises nosql-where-identifier src/api/m2.ts \
|
||||
'db.find({ $where: clause });' WARN INJ-NOSQL-OPERATOR
|
||||
raises nosql-where-call src/api/m3.ts \
|
||||
'db.find({ $where: buildWhere(req.query) });' WARN INJ-NOSQL-OPERATOR
|
||||
raises sql-concat-go-backtick src/api/a.go \
|
||||
$'package a\nfunc q(o string) string { return fmt.Sprintf(`select id from notes where owner = %s`, o) }' FAIL INJ-SQL-CONCAT
|
||||
raises sql-concat-go-quoted src/api/a2.go \
|
||||
$'package a\nfunc q(o string) string { return fmt.Sprintf("select id from notes where owner = %s", o) }' FAIL INJ-SQL-CONCAT
|
||||
raises sql-concat-py-rf src/api/r.py \
|
||||
$'def q(o):\n return rf"select id from notes where owner = {o}"' FAIL INJ-SQL-CONCAT
|
||||
raises sql-concat-py-triple src/api/b.py \
|
||||
$'def q(owner):\n return f"""\n select id from notes\n where owner = {owner}\n """' FAIL INJ-SQL-CONCAT
|
||||
raises raw-drizzle-sql-raw src/api/c.ts \
|
||||
'export const r = (w) => db.execute(sql.raw(w));' WARN INJ-SQL-RAW-UNSAFE
|
||||
raises raw-db-raw src/api/d.ts \
|
||||
'export const r = (w) => db.raw(w);' WARN INJ-SQL-RAW-UNSAFE
|
||||
raises raw-trx-raw src/api/e.ts \
|
||||
'export const r = (w) => trx.raw(w);' WARN INJ-SQL-RAW-UNSAFE
|
||||
raises select-no-argument src/api/u.ts \
|
||||
'export const u = () => supabase.from("users").select();' WARN EXP-RESPONSE-WIDE
|
||||
mkdir -p "$WORK/rollup/public"; printf '%s\n' 'export const a = 1;' > "$WORK/rollup/index.js"
|
||||
{ printf '%s' '{"version":3,"file":"app.js","sources":["a.ts"],"sourcesContent":["'
|
||||
head -c 1100000 /dev/zero | tr '\0' x
|
||||
printf '%s' '"],"names":[],"mappings":"AAAA"}'; } > "$WORK/rollup/public/app.js.map"
|
||||
LAST_OUT=$(scan "$WORK/rollup")
|
||||
check "rollup-ordered 1 MB map raises FAIL EXP-SOURCEMAP-PUBLIC" \
|
||||
"$(has FAIL EXP-SOURCEMAP-PUBLIC)" yes
|
||||
|
||||
echo "== benign patterns stay silent"
|
||||
benign() { # benign <label> <snippet>: a legitimate pattern raises nothing
|
||||
local label="$1" snippet="$2" dir="$WORK/$1"
|
||||
@@ -301,6 +357,26 @@ benign log-with-password-label \
|
||||
"printf '%s\n' 'console.log(\"password reset sent to\", email);' > src/lib/reset.ts"
|
||||
benign i18n-password-label \
|
||||
"mkdir -p src/i18n; printf '%s\n' 'export const de = { password: \"Passwort\" };' > src/i18n/de.ts"
|
||||
benign remix-action-after-loader \
|
||||
"mkdir -p app/routes; printf 'export async function loader() {\n return json({ ok: true });\n}\nexport async function action({ request }) {\n const form = await request.formData();\n return json({ password: form.get(\"password\") });\n}\n' > app/routes/a.tsx"
|
||||
benign comment-names-loader-above-clean-one \
|
||||
"mkdir -p app/routes; printf '// getServerSideProps is not used here\nexport async function loader() {\n return json({ ok: true });\n}\n' > app/routes/n.tsx"
|
||||
benign webpack-dev-config \
|
||||
"printf '%s\n' 'module.exports = { devtool: \"eval-source-map\" };' > webpack.dev.js"
|
||||
benign webpack-config-dev \
|
||||
"printf '%s\n' 'module.exports = { devtool: \"eval-source-map\" };' > webpack.config.dev.js"
|
||||
benign data-attr-ui-suffixes \
|
||||
"printf '%s\n' '<i data-password-toggle=\"true\" data-password-strength=\"3\" data-secret-visible=\"1\" />' > src/components/Toggle.tsx"
|
||||
benign graphql-bool-exp-variable \
|
||||
"printf '%s\n' 'const q = gql\`query(\$where: users_bool_exp) { users(where: \$where) { id } }\`;' > src/lib/g.ts"
|
||||
benign graphql-capitalised-variable \
|
||||
"printf '%s\n' 'const q = gql\`query(\$where: UsersWhere) { users(where: \$where) { id } }\`;' > src/lib/g2.ts"
|
||||
benign plain-triple-quoted-placeholder \
|
||||
"printf '%s\n' 'Q = \"\"\"select id from notes where owner = %s\"\"\"' > src/lib/q.py"
|
||||
benign sql-raw-literal \
|
||||
"printf '%s\n' 'export const n = () => db.execute(sql.raw(\"now()\"));' > src/lib/n.ts"
|
||||
benign select-with-fields \
|
||||
"printf '%s\n' 'export const u = () => supabase.from(\"users\").select(\"id, name\");' >> $API"
|
||||
ENVKEY='printf "SUPABASE_SERVICE_ROLE_KEY=%s.%s.signaturepart\n" "$(b64 "{\"alg\":\"HS256\"}")" "$(b64 "{\"role\":\"service_role\"}")" > .env.worker'
|
||||
benign env-worker-ignored "printf '.env.*\n' >> .gitignore; $ENVKEY"
|
||||
mutant env-worker-tracked FAIL SB-SERVICE-ROLE-LITERAL "$ENVKEY"
|
||||
@@ -502,11 +578,74 @@ out=$(scan "$WORK/linked")
|
||||
check "symlinked directory is not followed" \
|
||||
"$(printf '%s\n' "$out" | grep -c '(0 files)')" 1
|
||||
|
||||
echo "== text output carries no control characters"
|
||||
ESCNAME=$(printf 'x\033[31m')
|
||||
cp -R "$GOOD" "$WORK/esc"
|
||||
printf 'export default function X({user}){ console.log(user); return null }\n' \
|
||||
> "$WORK/esc/src/components/$ESCNAME.tsx"
|
||||
printf '%s\n' "create policy \"p$(printf '\033[2J')\" on public.notes for insert to authenticated with check (true);" >> "$WORK/esc/$SQL"
|
||||
out=$(scan "$WORK/esc" 2>&1)
|
||||
check "text report has no ESC byte" "$(printf '%s' "$out" | grep -c "$(printf '\033')")" 0
|
||||
check "text report still raises the console finding" \
|
||||
"$(printf '%s\n' "$out" | grep -c 'EXP-CONSOLE-DATA')" 1
|
||||
check "text report still raises the open policy" \
|
||||
"$(printf '%s\n' "$out" | grep -c 'SB-POLICY-OPEN-WRITE')" 1
|
||||
out=$(scan "$WORK/esc" --assert-absent "EXP-CONSOLE-DATA:src/components/$ESCNAME.tsx" 2>&1)
|
||||
check "assert-absent prints PRESENT with no ESC byte" \
|
||||
"$(printf '%s' "$out" | grep -c "$(printf '\033')"):$(printf '%s\n' "$out" | grep -c PRESENT)" 0:1
|
||||
out=$(scan "$WORK/esc" --baseline "$WORK/clean-before.json" 2>&1)
|
||||
check "baseline rows have no ESC byte and list the new hit" \
|
||||
"$(printf '%s' "$out" | grep -c "$(printf '\033')"):$(printf '%s\n' "$out" | grep -c '^ NEW ')" 0:2
|
||||
out=$(scan "$WORK/esc" --assert-absent "NOPE$(printf '\033[1m'):x" 2>&1)
|
||||
check "usage error has no ESC byte" \
|
||||
"$(printf '%s' "$out" | grep -c "$(printf '\033')")" 0
|
||||
|
||||
echo "== per-variant"
|
||||
mutant var-rust-format FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'fn q(o: &str) -> String { format!(\"select id from notes where owner = {}\", o) }' > src/lib/q.rs"
|
||||
mutant var-django-objects-raw WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'rows = Note.objects.raw(statement)' > src/lib/n.py"
|
||||
mutant var-django-extra WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'rows = Note.objects.all().extra(clause)' > src/lib/n2.py"
|
||||
mutant var-knex-raw-alone WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'const r = await knex.raw(statement);' > src/lib/k.ts"
|
||||
mutant var-execute-raw-unsafe WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'await prisma.\$executeRawUnsafe(statement);' > src/lib/x.ts"
|
||||
mutant var-sequelize-query WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'const r = await sequelize.query(statement);' > src/lib/s.ts"
|
||||
mutant var-sequelize-literal WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'const w = Sequelize.literal(clause);' > src/lib/s2.ts"
|
||||
mutant var-generate-sourcemap FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
"printf '%s\n' 'GENERATE_SOURCEMAP=true' > .env.production"
|
||||
mutant var-vite-sourcemap-true FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
"printf '%s\n' 'export default { build: { sourcemap: true } };' > vite.config.ts"
|
||||
mutant var-angular-sourcemap WARN EXP-SOURCEMAP-PUBLIC \
|
||||
"printf '%s\n' '{ \"sourceMap\": true }' > angular.json"
|
||||
mutant var-rails-local-requests FAIL EXP-DEBUG-ON \
|
||||
"mkdir -p config/environments; printf '%s\n' 'config.consider_all_requests_local = true' > config/environments/production.rb"
|
||||
mutant var-flask-debug-env FAIL EXP-DEBUG-ON \
|
||||
"printf '%s\n' 'FLASK_DEBUG=1' > .env.production"
|
||||
mutant var-flask-app-debug FAIL EXP-DEBUG-ON \
|
||||
"printf '%s\n' 'app.debug = True' > src/lib/app.py"
|
||||
mutant var-shell-db-rust FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' 'let o = Command::new(\"psql\").arg(format!(\"-c {}\", q));' > src/lib/sh.rs"
|
||||
mutant var-shell-db-ruby FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' 'system(\"psql -c #{query}\")' > src/lib/sh.rb"
|
||||
mutant var-error-trace-php FAIL EXP-ERROR-STACK \
|
||||
"printf '%s\n' '<?php echo \$e->getTraceAsString();' > src/lib/err.php"
|
||||
mutant var-error-message-flask WARN EXP-ERROR-MESSAGE \
|
||||
"printf '%s\n' 'return jsonify(error=str(e)), 500' > src/lib/err.py"
|
||||
|
||||
benign shell-db-psql-empty-options \
|
||||
"printf '%s\n' 'execSync(\"psql -c select1\", {});' > src/lib/sh.ts"
|
||||
benign shell-db-rust-argv \
|
||||
"printf '%s\n' 'let o = Command::new(\"psql\").arg(\"-c\").arg(q);' > src/lib/sh.rs"
|
||||
|
||||
echo "== regex timing"
|
||||
FAST="$(cd "$ROOT" && python3 -B - <<'PY'
|
||||
cat > "$WORK/timing.py" <<'PY'
|
||||
import importlib.util, sys, time
|
||||
sys.path.insert(0, "skills/guardrails/scripts")
|
||||
from checks import common, exposure
|
||||
from checks import common, exposure, injection
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"probe", "skills/guardrails/scripts/probe.py")
|
||||
probe = importlib.util.module_from_spec(spec)
|
||||
@@ -523,9 +662,70 @@ for pattern, text in cases:
|
||||
start = time.perf_counter()
|
||||
pattern.search(text)
|
||||
slow += time.perf_counter() - start >= 1.0
|
||||
JS = injection.CONCAT[injection.JS_EXTS]
|
||||
PYC = injection.CONCAT[(".py",)]
|
||||
GO = injection.CONCAT[(".go",)]
|
||||
unit = "select from "
|
||||
locked = [
|
||||
(JS, "`" + unit * 7000),
|
||||
(JS, "'" + unit * 7000),
|
||||
(PYC, "f'" + unit * 7000),
|
||||
(PYC, 'f"""' + unit * 7000),
|
||||
(GO, "fmt.Sprintf(`" + unit * 7000),
|
||||
(injection.NOSQL, "$where: " * 10000),
|
||||
(exposure.HIDDEN_INPUT, "<input " * 11000),
|
||||
(injection.SHELL_DB, "system(psql {} " * 1800),
|
||||
]
|
||||
for pattern, text in locked:
|
||||
start = time.perf_counter()
|
||||
miss = pattern.search(text) is None
|
||||
slow += (not miss) or time.perf_counter() - start >= 1.0
|
||||
rows = [
|
||||
(PYC, 'cur.execute("select id from notes where owner = %s" % owner)'),
|
||||
(PYC, 'cur.execute("select id from notes where o = {}".format(o))'),
|
||||
(JS, "const q = 'select id from notes where owner = ' + owner;"),
|
||||
(injection.CONCAT[(".rb",)], 'q = "select id from notes where o = #{o}"'),
|
||||
(injection.DYNAMIC_EXEC, "execute tbl || ' where true'"),
|
||||
(injection.POSTGREST, "supabase.from('t').filter(`a.eq.${v}`)"),
|
||||
(injection.POSTGREST, "supabase.from('t').not('a.eq.' + v)"),
|
||||
(injection.POSTGREST, "supabase.from('t').match(`a.eq.${v}`)"),
|
||||
(injection.POSTGREST, "supabase.from('t').textSearch(`a.${v}`)"),
|
||||
(injection.POSTGREST, "supabase.from('t').or('a.eq.' + v)"),
|
||||
(injection.NOSQL, "Notes.find(req.body)"),
|
||||
(injection.NOSQL, "Notes.updateOne({ id: req.body.id }, {})"),
|
||||
(injection.NOSQL, "Notes.findOneAndUpdate(req.query, {})"),
|
||||
(injection.NOSQL, "Notes.deleteMany(req.params)"),
|
||||
(injection.NOSQL, "Notes.countDocuments({ a: req.body.a })"),
|
||||
]
|
||||
senders = ("return jsonify(", "return JSONResponse(", "raise HTTPException(",
|
||||
"raise X(detail=", "echo ", "reply.send(", "ctx.body = ")
|
||||
for sending in senders:
|
||||
rows.append((exposure.ERROR_STACK, sending + "traceback.format_exc())"))
|
||||
rows.append((exposure.ERROR_MESSAGE, sending + "str(e))"))
|
||||
rows += [
|
||||
(exposure.ERROR_STACK, "echo $e->getTraceAsString();"),
|
||||
(exposure.ERROR_STACK, "res.json({ error: err })"),
|
||||
(exposure.ERROR_MESSAGE, "return jsonify(error=repr(e))"),
|
||||
(exposure.ERROR_MESSAGE, "echo $e->getMessage();"),
|
||||
(exposure.DEBUG_CODE, "app.debug = True"),
|
||||
]
|
||||
heads = ("Command::new(", "popen(", "passthru(", "proc_open(", "spawn(",
|
||||
"system(")
|
||||
for head in heads:
|
||||
for tail in ('"psql -c #{q}")', '"psql {q}")', '"psql %s" % q)',
|
||||
'"psql " + q)', '"psql ${q}")'):
|
||||
rows.append((injection.SHELL_DB, head + tail))
|
||||
rows.append((injection.SHELL_DB_PHP, head + '"psql $Q")'))
|
||||
for pattern, sample in rows:
|
||||
slow += pattern.search(sample) is None
|
||||
loads = "export const load = 1\n" * 45000
|
||||
start = time.perf_counter()
|
||||
spans = exposure._hydrated_spans(loads)
|
||||
miss = all(exposure.HYDRATED.search(loads, b, e) is None for b, e in spans)
|
||||
slow += (not miss) or time.perf_counter() - start >= 1.0
|
||||
print("REGEX-FAST" if not slow else "REGEX-SLOW")
|
||||
PY
|
||||
)"
|
||||
FAST="$(cd "$ROOT" && python3 -B "$WORK/timing.py")"
|
||||
check "adversarial inputs finish each regex under one second" \
|
||||
"$(printf '%s\n' "$FAST" | grep -c 'REGEX-FAST')" 1
|
||||
|
||||
|
||||
@@ -56,6 +56,10 @@ it ever reached git history is a separate check (`gitleaks git <repo>`).
|
||||
Heuristic blind spots are in `references/checks.md`: check them before
|
||||
calling a hit false.
|
||||
|
||||
- INJ-SQL-CONCAT on `IN (${placeholders})` where the list is generated
|
||||
`?`/`$n` markers and the values travel in a separate array: parameterised,
|
||||
confirm by hand and drop it from the proposals.
|
||||
|
||||
## STEP 4: Cover what the scanner cannot
|
||||
|
||||
Read the code for the domains that apply and answer, with file:line evidence:
|
||||
@@ -93,8 +97,10 @@ never a third party.
|
||||
the `routes` (mark the ones meant to be public), `cors`, and a
|
||||
`rate_limit` route if the user wants that one burst. Add an `exposure` block (`{}` for the defaults, `error_routes` for a route you own that answers an error to a malformed id, never a path you guess) so the probe reads source maps, error bodies and response keys; every path in the plan starts with `/`. Secrets never go in
|
||||
the plan or the command line: export `GUARDRAILS_ANON_KEY` and, for the
|
||||
cross-user probe, `GUARDRAILS_JWT2`, from test keys, never `service_role`.
|
||||
2. **Run it**, confirming ownership with `--authorized`:
|
||||
cross-user probe, `GUARDRAILS_JWT2`, from test keys, never `service_role`. The fields probe sends
|
||||
`GUARDRAILS_JWT2` as a bearer when set, so an OPEN there is what a
|
||||
logged-in user sees.
|
||||
2. **Run it**, confirming ownership with `--authorized`. Before adding `--authorized`, show the user both hosts the plan names (`base_url` and the Supabase `url`, the latter read from the project's config and so untrusted) and get their go on both:
|
||||
```
|
||||
python3 -B "$HOME/.claude/skills/guardrails/scripts/probe.py" \
|
||||
plan.json --authorized
|
||||
@@ -201,7 +207,8 @@ file before anything else. Accepted set empty → stop.
|
||||
proof the scanner cannot run (probe, cross-user, manual SQL) is a
|
||||
criterion without CHECK: STEP 11 settles it. FILE SCOPE = the files the
|
||||
accepted proposals name. Paths go in single quotes; a path holding a
|
||||
single quote is named to the user, never written into a CHECK.
|
||||
single quote is named to the user, never written into a CHECK. The
|
||||
RULE:path pairs come from the `--json` output, never from the text report.
|
||||
4. **Positive control.** Run each oracle once on the unfixed tree: it must
|
||||
fail. An oracle that passes before the fix proves nothing; drop it, find
|
||||
why, and say so.
|
||||
|
||||
@@ -38,25 +38,25 @@ match (an interpolation inside a raw escape stays FAIL).
|
||||
| Rule | Sev | Catches | Fix |
|
||||
|---|---|---|---|
|
||||
| INJ-SQL-CONCAT | FAIL | a SQL statement (select … from … where, insert into, update … set, delete … where, create/drop/alter) built with `${}`, `+`, an f-string, `%`, `.format`, PHP `$var`, Ruby `#{}` (ActiveRecord `where("… #{}")` included), `format!`, `Sprintf` | placeholders and a parameter list |
|
||||
| INJ-SQL-RAW-UNSAFE | WARN | `$queryRawUnsafe`, `$executeRawUnsafe`, `knex.raw`, `sequelize.query`, `Sequelize.literal`, Django `.objects.raw()` / `.extra()`, SQLAlchemy `text()` / `sa.text(` / `sqlalchemy.text(` fed a variable (a variable may hold a constant)| show it is a constant with bound values, else bind them; or the tagged `$queryRaw` |
|
||||
| INJ-SQL-RAW-UNSAFE | WARN | `$queryRawUnsafe`, `$executeRawUnsafe`, `knex.raw`, `sql.raw`, `db.raw`, `trx.raw`, `sequelize.query`, `Sequelize.literal`, Django `.objects.raw()` / `.extra()`, SQLAlchemy `text()` / `sa.text(` / `sqlalchemy.text(` fed a variable (a variable may hold a constant)| show it is a constant with bound values, else bind them; or the tagged `$queryRaw` |
|
||||
| INJ-SQL-DYNAMIC-EXEC | WARN | plpgsql `EXECUTE '…' \|\| x` | `format('… %I %L', …)` and `USING` |
|
||||
| INJ-POSTGREST-FILTER | WARN | supabase-js `.or()`, `.filter()`, `.not()`, `.match()`, `.textSearch()` with an interpolated string, in a file that uses supabase | `.eq()` and friends, validated values |
|
||||
| INJ-NOSQL-OPERATOR | WARN | Mongo `$where` with a string; a filter taken from `req.body`, `req.query` or `req.params` | allowlist the fields, cast to string, `sanitizeFilter` |
|
||||
| INJ-SHELL-DB-TOOL | FAIL | a shell call naming psql, mysql, mysqldump, pg_dump, mongosh, redis-cli, sqlite3… with an interpolated argument (an argv array and a bare `$ENV_VAR` stay silent; in PHP every `$name` counts) | an argv array, no shell, validated input |
|
||||
| INJ-NOSQL-OPERATOR | WARN | Mongo `$where` with a string, an identifier or a function (a GraphQL `_bool_exp` type and a Capitalised type are excluded); a filter taken from `req.body`, `req.query` or `req.params` | allowlist the fields, cast to string, `sanitizeFilter` |
|
||||
| INJ-SHELL-DB-TOOL | FAIL | a shell call naming psql, mysql, mysqldump, pg_dump, mongosh, redis-cli, sqlite3… with an interpolated argument (`${x}`, `#{x}`, `{x}`, a positional `{}` closing a Rust format string, `%s`; an argv array and a bare `$ENV_VAR` stay silent; in PHP every `$name` counts) | an argv array, no shell, validated input |
|
||||
|
||||
## exposure
|
||||
|
||||
| Rule | Sev | Catches | Fix |
|
||||
|---|---|---|---|
|
||||
| EXP-CONSOLE-DATA | WARN | `console.log/info/debug/dir/table` in client-reachable code with a data argument (user, session, response, token, body…); string literals are ignored | strip console calls in the production build, log server-side |
|
||||
| EXP-SOURCEMAP-PUBLIC | FAIL / WARN | `productionBrowserSourceMaps: true`, vite `sourcemap: true` or `'inline'`, `GENERATE_SOURCEMAP=true` in a committed non-dev env file, webpack `devtool` readable maps (FAIL in `webpack.prod*`, WARN elsewhere), a real `.map` under `public/` or `static/` (any size; vendored and `.min.` maps excluded); angular `sourceMap: true` (WARN) | off, or `hidden` and upload to the error tracker |
|
||||
| EXP-SOURCEMAP-PUBLIC | FAIL / WARN | `productionBrowserSourceMaps: true`, vite `sourcemap: true` or `'inline'`, `GENERATE_SOURCEMAP=true` in a committed non-dev env file, webpack `devtool` readable maps (FAIL in `webpack.prod*`, WARN elsewhere, dev configs silent), a real `.map` under `public/` or `static/` (any size; vendored and `.min.` maps excluded); angular `sourceMap: true` (WARN) | off, or `hidden` and upload to the error tracker |
|
||||
| EXP-HYDRATED-SENSITIVE | WARN | a token, secret, key, password or ssn-like key returned by `getServerSideProps`, `getStaticProps`, a Remix `loader`, a SvelteKit `load` or set on `window.__STATE__`; a TS type member is skipped | return only the fields the page renders |
|
||||
| EXP-MARKUP-COMMENT | WARN | `<!-- -->` shipped to the browser (html, astro, php, ejs, hbs, twig, njk, liquid) with todo, fixme, debug, password, token, internal, staging, admin… | delete it, or move it to a code comment the build strips |
|
||||
| EXP-DATA-ATTR-SENSITIVE | WARN | `data-*` attribute or hidden input named secret, api-key, password, jwt, private, credential (csrf, xsrf, authenticity, nonce excluded) | keep it server-side, send an opaque id |
|
||||
| EXP-DATA-ATTR-SENSITIVE | WARN | `data-*` attribute or hidden input named secret, api-key, password, jwt, private, credential (csrf, xsrf, authenticity, nonce excluded; a UI suffix such as `-toggle`, `-visible` or `-strength` is silent) | keep it server-side, send an opaque id |
|
||||
| EXP-ERROR-STACK | FAIL | in any server file: `err.stack`, the error object, `traceback.format_exc()` or `getTraceAsString()` in a response | generic message out, full error in the server log |
|
||||
| EXP-ERROR-MESSAGE | WARN | in any server file: `err.message`, `str(e)`, `$e->getMessage()` sent as is | map to a safe message; validation errors are fine, DB errors are not |
|
||||
| EXP-DEBUG-ON | FAIL | `DEBUG = True` in a settings module (not dev/local/test), `APP_DEBUG=true` / `FLASK_DEBUG=1` in a committed non-dev env file, `app.debug = True`, `consider_all_requests_local = true`, `errorhandler()` mounted without an environment guard | env-driven, false in production |
|
||||
| EXP-RESPONSE-WIDE | WARN | a route returning `select *` / `select('*')` on a users-like table, or a single-line Prisma `findUnique/findFirst/findMany` without `select` or `omit` | an explicit field list |
|
||||
| EXP-RESPONSE-WIDE | WARN | a route returning `select *` / `select('*')` / `.select()` on a users-like table, or a single-line Prisma `findUnique/findFirst/findMany` without `select` or `omit` | an explicit field list |
|
||||
|
||||
## supabase
|
||||
|
||||
@@ -126,6 +126,14 @@ The scanner is regex over text. It cannot see:
|
||||
elsewhere: the column rule fires only when no library is found anywhere,
|
||||
so trace the write point by hand (STEP 4)
|
||||
- a log call spanning several lines, or `req.body` dumped to a log
|
||||
- hydrated state is read per export chunk: a non-exported helper between two
|
||||
exports is still scanned (false positive), a sensitive object built in a
|
||||
helper above the loader is missed, and moving a key above the loader clears
|
||||
the oracle, so the STEP 3 judge re-reads the whole loader
|
||||
- `$where: PascalCase` and `*_exp` identifiers are read as GraphQL types
|
||||
- a raw SQL literal whose statement keyword does not open it (Go backtick,
|
||||
Python triple-quoted f-string with a comment first) is not seen
|
||||
- INJ-SQL-CONCAT costs about 3 s on a 1 MB file: accepted
|
||||
|
||||
Sender classification is by file path only: names with contact, reset, verify,
|
||||
otp, receipt and the like count as transactional, names with newsletter,
|
||||
@@ -138,7 +146,9 @@ The scanner skips log files and cache directories, and never follows symlinks.
|
||||
By design the scanner ignores: policies granted only to `service_role`,
|
||||
UI route components, keys
|
||||
inside git-ignored env files, and password literals in test, fixture and
|
||||
i18n files, tagged SQL templates, placeholders with a separate parameter list, an argv array handed to a DB tool, console calls in server code, logging calls that carry a stack, `sourcemap: 'hidden'`, a debug flag read from the environment, dev, local and test env files and settings modules, minified files and built directories, and a hidden input or data attribute named csrf, xsrf, authenticity or nonce.
|
||||
i18n files, tagged SQL templates, placeholders with a separate parameter list, an argv array handed to a DB tool, console calls in server code, logging calls that carry a stack, `sourcemap: 'hidden'`, a debug flag read from the environment, dev, local and test env files and settings modules, minified files and built directories, a hidden input or data attribute named csrf, xsrf, authenticity or nonce, webpack dev configs, data-* names ending in a UI suffix, a loader scoped to its export chunk, and metadata keys in the fields probe.
|
||||
|
||||
Still flagged, judge by hand: INJ-SQL-CONCAT on a template literal that builds a generated `?` or `$n` list inside `IN (…)` while the values travel in a separate array; it is parameterised, drop it from the proposals.
|
||||
|
||||
## Live Supabase checks (the user runs them in the SQL editor)
|
||||
|
||||
@@ -221,13 +231,14 @@ The fields probe sends `GUARDRAILS_JWT2` as a bearer when it is set. Every path
|
||||
| no-auth route | `no-auth:<path>` | the route answered 200 with no token | API-ROUTE-NO-AUTH, object authz |
|
||||
| cors-reflect | `cors-reflect` | a foreign origin was reflected with credentials | API-CORS-WILDCARD |
|
||||
| rate-limit | `rate-limit` | the burst saw no 429 | HOST-NO-RATE-LIMIT |
|
||||
| sourcemap | `sourcemap:<script>` | a source map with sources answered 200 for a page script, or the script carries an inline map | EXP-SOURCEMAP-PUBLIC |
|
||||
| sourcemap | `sourcemap:<script>` | a source map with sources answered 200 for a page script, or the script carries an inline map (a line-start `data:` directive is OPEN whatever its encoding) | EXP-SOURCEMAP-PUBLIC |
|
||||
| error-body | `error-body:<path>` | a 404 or a named error route returned a stack trace or an internal path | EXP-ERROR-STACK, EXP-DEBUG-ON |
|
||||
| fields | `fields:<path>` | a JSON 200 carried a password, salt, token, hash, key or secret-like key (`private` only as private_key; identifier-shaped names printed, never values) | EXP-RESPONSE-WIDE, EXP-HYDRATED-SENSITIVE |
|
||||
| fields | `fields:<path>` | a JSON 200 carried a password, salt, token, hash, key or secret-like key (`private` only as private_key; metadata names such as `token_type`, `has_password` or `next_page_token` are excluded; identifier-shaped names printed, never values) | EXP-RESPONSE-WIDE, EXP-HYDRATED-SENSITIVE |
|
||||
|
||||
A verdict is an observation, not a verdict on the project. OPEN is a returned
|
||||
200 or returned rows; CLOSED is a refusal or an empty body; SKIPPED is a
|
||||
missing key; ERROR is a transport failure. A static FAIL confirmed OPEN leads
|
||||
missing key or a body the probe could not read; ERROR is a transport
|
||||
failure or an exhausted budget. A static FAIL confirmed OPEN leads
|
||||
the report. A CLOSED probe on a static FAIL still needs the fix: the dev
|
||||
target may differ from production. An exposure target the probe could not observe (unreachable page, no same-host script, a refused or non-JSON route, a map fetch that failed) is SKIPPED or ERROR, never CLOSED. Run the exposure block against a production build or a staging URL: a dev server serves maps and tracebacks by design, and its OPEN verdicts are dev artefacts, not findings.
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ SOURCE_EXTS = {
|
||||
}
|
||||
|
||||
|
||||
def printable(text):
|
||||
"""Control characters of a remote string never reach the tty."""
|
||||
return re.sub(r"[\x00-\x1f\x7f-\x9f\udc80-\udcff]", "?", str(text))
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Rule:
|
||||
domain: str
|
||||
|
||||
@@ -22,6 +22,7 @@ SENSITIVE = (
|
||||
r"(?:token|accessToken|refreshToken|secret|apiKey|api_key|password"
|
||||
r"|passwordHash|password_hash|serviceRole|service_role|privateKey"
|
||||
r"|private_key|ssn|iban|stripeSecret|clientSecret)")
|
||||
EXPORT = re.compile(r"^export\b", re.M)
|
||||
LOADER = re.compile(
|
||||
r"getServerSideProps|getStaticProps"
|
||||
r"|export\s+(?:async\s+)?function\s+(?:loader|load)\b"
|
||||
@@ -35,10 +36,15 @@ COMMENT_WORDS = re.compile(
|
||||
r"\b(?:todo|fixme|hack|xxx|debug|password|passwd|secret|token"
|
||||
r"|api[-_ ]?key|internal|staging|localhost|admin|remove before"
|
||||
r"|do not commit|don'?t commit|temporary)\b", re.I)
|
||||
SENSITIVE_WORD = (r"(?:secret|api-?_?key|password|passwd|jwt|private"
|
||||
r"|credential|service-?role)")
|
||||
DATA_ATTR = re.compile(
|
||||
r"\b(data-[\w-]{0,60}(?:secret|api-?_?key|password|passwd|jwt|private"
|
||||
r"|credential|service-?role)[\w-]{0,60})\s*=", re.I)
|
||||
HIDDEN_INPUT = re.compile(r"<input\b[^>\n]{0,300}>", re.I)
|
||||
rf"\b(data-[\w-]{{0,60}}{SENSITIVE_WORD}[\w-]{{0,60}})\s*=", re.I)
|
||||
UI_ATTR = re.compile(
|
||||
rf"{SENSITIVE_WORD}-(?:toggle|visible|visibility|show|hide|reveal|mask"
|
||||
r"|strength|meter|hint|label|placeholder|confirm|error|required"
|
||||
r"|pattern)$", re.I)
|
||||
HIDDEN_INPUT = re.compile(r"<input\b[^>]{0,300}>", re.I)
|
||||
SENSITIVE_NAME = re.compile(
|
||||
r"secret|api[-_]?key|password|passwd|jwt|private|credential", re.I)
|
||||
SAFE_NAME = re.compile(r"csrf|xsrf|authenticity|nonce", re.I)
|
||||
@@ -76,7 +82,7 @@ VENDORED = re.compile(r"\.min\.|vendor|bootstrap|jquery", re.I)
|
||||
USERS = (r"(?:users|profiles|accounts|customers|members|employees"
|
||||
r"|patients|clients)")
|
||||
WIDE = re.compile(
|
||||
rf"\.from\(\s*['\"]{USERS}['\"]\s*\)\s*\.select\(\s*['\"]\*['\"]\s*\)"
|
||||
rf"\.from\(\s*['\"]{USERS}['\"]\s*\)\s*\.select\(\s*(?:['\"]\*['\"]\s*)?\)"
|
||||
rf"|select\s+\*\s+from\s+{USERS}\b"
|
||||
r"|\b(?:user|profile|account|customer|member)\.(?:findUnique|findFirst"
|
||||
r"|findMany)\(\s*\{(?![^\n]{0,300}\b(?:select|omit)\s*:)[^\n]{0,300}\}"
|
||||
@@ -124,7 +130,8 @@ def _map_config(project):
|
||||
out += hits(project, _named(project, "vite.config"), VITE_MAPS, fail,
|
||||
"build source maps enabled: use 'hidden' or false")
|
||||
prod = _named(project, "webpack.prod")
|
||||
other = [p for p in _named(project, "webpack") if p not in prod]
|
||||
other = [p for p in _named(project, "webpack")
|
||||
if p not in prod and not DEV_TOKEN.search(p.name)]
|
||||
out += hits(project, prod, WEBPACK_DEVTOOL, fail,
|
||||
"devtool emits readable source maps in production")
|
||||
out += hits(project, other, WEBPACK_DEVTOOL, warn,
|
||||
@@ -148,12 +155,13 @@ def _public_map(project, path):
|
||||
|
||||
|
||||
def _large_map(project, path):
|
||||
"""A large public .map whose first 4 KB already hold a mappings key."""
|
||||
"""A large public .map whose first 4 KB hold a mappings or sources key."""
|
||||
if path.suffix.lower() != ".map" or not _public_map(project, path):
|
||||
return False
|
||||
try:
|
||||
with path.open("rb") as handle:
|
||||
return b'"mappings"' in handle.read(4096)
|
||||
head = handle.read(4096)
|
||||
return b'"mappings"' in head or b'"sources"' in head
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
@@ -169,11 +177,27 @@ def _map_files(project):
|
||||
for p in small + large]
|
||||
|
||||
|
||||
def _hydrated_spans(text):
|
||||
"""(start, end) of each export chunk holding a loader, from its line."""
|
||||
bounds = sorted({0, *(m.start() for m in EXPORT.finditer(text))})
|
||||
spans = []
|
||||
for start, end in zip(bounds, bounds[1:] + [len(text)]):
|
||||
found = LOADER.search(text, start, end)
|
||||
if found:
|
||||
spans.append((text.rfind("\n", 0, found.start()) + 1, end))
|
||||
return spans
|
||||
|
||||
|
||||
def _hydrated(project, files):
|
||||
loaders = [p for p in files if LOADER.search(project.text(p))]
|
||||
return hits(project, loaders, HYDRATED,
|
||||
Rule(DOMAIN, "EXP-HYDRATED-SENSITIVE", "WARN"),
|
||||
"sensitive key in server-to-client state")
|
||||
rule = Rule(DOMAIN, "EXP-HYDRATED-SENSITIVE", "WARN")
|
||||
out = []
|
||||
for path in files:
|
||||
text = project.text(path)
|
||||
out += [project.found(rule, path, m.start(),
|
||||
"sensitive key in server-to-client state")
|
||||
for begin, end in _hydrated_spans(text)
|
||||
for m in HYDRATED.finditer(text, begin, end)]
|
||||
return dedupe_lines(out)
|
||||
|
||||
|
||||
def _markup_comments(project):
|
||||
@@ -202,7 +226,8 @@ def _data_attrs(project):
|
||||
out += [project.found(rule, path, m.start(),
|
||||
"sensitive value in a data-* attribute")
|
||||
for m in DATA_ATTR.finditer(text)
|
||||
if not SAFE_NAME.search(m.group(1))]
|
||||
if not SAFE_NAME.search(m.group(1))
|
||||
and not UI_ATTR.search(m.group(1))]
|
||||
out += [project.found(rule, path, m.start(),
|
||||
"sensitive value in a hidden input")
|
||||
for m in HIDDEN_INPUT.finditer(text)
|
||||
|
||||
@@ -32,7 +32,8 @@ CONCAT = {
|
||||
rf"(?<![\w$)\]>])`[^`]{{0,400}}?{STMT}[^`]{{0,400}}?\$\{{|"
|
||||
+ _quoted(r"\s*\+\s*[\w$(]"), re.I),
|
||||
(".py",): re.compile(
|
||||
rf"\bf['\"][^'\"\n]{{0,200}}?{STMT}|"
|
||||
rf"\b(?:rf|fr|f)['\"][^'\"\n]{{0,200}}?{STMT}"
|
||||
rf"|\b(?:rf|fr|f)(?:\"\"\"|''')\s{{0,40}}{STMT}|"
|
||||
+ _quoted(r"\s*(?:%\s*[\w(]|\.format\(|\+\s*[\w(])"), re.I),
|
||||
(".php",): re.compile(
|
||||
rf"\"{DQ}?{STMT}{DQ}\$[A-Za-z_]\w*|"
|
||||
@@ -40,11 +41,12 @@ CONCAT = {
|
||||
(".rb",): re.compile(
|
||||
rf"\"{DQ}?{STMT}{DQ}#\{{|\.where\(\s*\"{DQ}#\{{", re.I),
|
||||
(".rs",): re.compile(rf"format!\(\s*\"{DQ}?{STMT}", re.I),
|
||||
(".go",): re.compile(rf"fmt\.Sprintf\(\s*\"{DQ}?{STMT}", re.I),
|
||||
(".go",): re.compile(
|
||||
rf"fmt\.Sprintf\(\s*(?:\"{DQ}?{STMT}|`\s{{0,40}}{STMT})", re.I),
|
||||
}
|
||||
RAW = {
|
||||
JS_EXTS: re.compile(
|
||||
r"(?:\$queryRawUnsafe|\$executeRawUnsafe|\bknex\.raw"
|
||||
r"(?:\$queryRawUnsafe|\$executeRawUnsafe|\b(?:sql|db|trx|knex)\.raw"
|
||||
r"|\bsequelize\.query|\b[Ss]equelize\.literal)\s*\(\s*(?![\s'\"`)])"),
|
||||
(".py",): re.compile(
|
||||
r"\.objects\.raw\(\s*(?![\s'\"`)])|\.extra\(\s*(?![\s'\"`)])"),
|
||||
@@ -56,7 +58,8 @@ POSTGREST = re.compile(
|
||||
r"\.(?:or|filter|not|match|textSearch)\(\s*(?:`[^`\n]{0,200}\$\{"
|
||||
r"|['\"][^'\"\n]{0,200}['\"]\s*\+\s*[\w$])")
|
||||
NOSQL = re.compile(
|
||||
r"\$where\s*:\s*(?:['\"`]|\w)"
|
||||
r"\$where\s*:\s*(?!\w{0,64}_(?:bool_)?exp\b|[A-Z]\w{0,64}!?\s*[),])"
|
||||
r"(?:['\"`]|\w)"
|
||||
r"|\.(?:find|findOne|findOneAndUpdate|findOneAndDelete|updateOne"
|
||||
r"|updateMany|deleteOne|deleteMany|countDocuments|replaceOne)\(\s*"
|
||||
r"(?:req\.(?:body|query|params)\b"
|
||||
@@ -67,7 +70,8 @@ SHELL_DB_HEAD = (
|
||||
r"[^\n]{0,300}?\b(?:psql|mysql|mysqldump|pg_dump|pg_restore|mongosh"
|
||||
r"|mongo|mongodump|redis-cli|sqlite3|clickhouse-client)"
|
||||
r"\b(?![\"']\s*[,\]])[^\n]{0,300}?")
|
||||
SHELL_INTERP = r"(?:\$\{|\+\s*[\w$]|#\{|\{\w+\}|%s|"
|
||||
SHELL_INTERP = (r"(?:\$\{|\+\s*[\w$]|#\{|\{\w+\}|%s"
|
||||
r"|\{\}(?=[^\"{}\n]{0,12}\"\s*,)|")
|
||||
# An uppercase $NAME is a shell env reference, except in PHP where every
|
||||
# $name is a variable.
|
||||
SHELL_DB = re.compile(SHELL_DB_HEAD + SHELL_INTERP + r"\$[a-z_])")
|
||||
|
||||
@@ -31,12 +31,15 @@ import urllib.request
|
||||
from dataclasses import asdict, dataclass
|
||||
from urllib.parse import quote, urljoin, urlsplit
|
||||
|
||||
from checks.common import printable
|
||||
|
||||
READ_METHODS = {"GET", "HEAD", "OPTIONS"}
|
||||
FAKE_ORIGIN = "https://guardrails-probe.invalid"
|
||||
DEFAULT_BUDGET = 200
|
||||
BURST_CAP = 25
|
||||
BODY_CAP = 1_000_000
|
||||
SCRIPT_CAP = 10
|
||||
BUDGET_EXHAUSTED = "request budget exhausted"
|
||||
SCRIPT_SRC = re.compile(r"<script[^>]{1,300}src=[\"']?([^\"'\s>]+)", re.I)
|
||||
MAP_COMMENT = re.compile(
|
||||
r"^[ \t]*//[#@][ \t]*sourceMappingURL=(\S+)", re.M)
|
||||
@@ -50,6 +53,10 @@ SENSITIVE_KEY = re.compile(
|
||||
r"|service_?role"
|
||||
r"|private_?key|(?:access|refresh|id|auth|api|session)_token|jwt|ssn"
|
||||
r"|iban|cvv|card_?number)(?:$|_)")
|
||||
METADATA_KEY = re.compile(
|
||||
r"^(?:has|is|needs|requires)_"
|
||||
r"|_(?:type|count|length|url|expires?(?:_in)?|expiry|ttl|at)$"
|
||||
r"|^(?:next_page_token|page_token|cursor|csrf_?token|xsrf_?token)$")
|
||||
IDENT = re.compile(r"[A-Za-z_][\w-]{0,31}") # used with fullmatch
|
||||
|
||||
|
||||
@@ -84,12 +91,25 @@ def _stays_on_host(old_url, new_url):
|
||||
== ("http", "https"))
|
||||
|
||||
|
||||
class _BudgetExhausted(urllib.error.URLError):
|
||||
"""The shared request budget ran out in the middle of a redirect."""
|
||||
|
||||
|
||||
class _SameHost(urllib.request.HTTPRedirectHandler):
|
||||
"""Follow a same-host redirect, drop one that leaves the host."""
|
||||
"""Follow a same-host redirect, drop one that leaves the host.
|
||||
|
||||
Each followed hop is a request: it is charged to the session budget.
|
||||
"""
|
||||
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
|
||||
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
||||
if not _stays_on_host(req.full_url, newurl):
|
||||
return None
|
||||
if self.session.budget <= 0:
|
||||
raise _BudgetExhausted(BUDGET_EXHAUSTED)
|
||||
self.session.budget -= 1
|
||||
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
||||
|
||||
|
||||
@@ -97,7 +117,7 @@ class Session:
|
||||
"""Holds the redirect-guarded opener and the shared request budget."""
|
||||
|
||||
def __init__(self, timeout=8, budget=DEFAULT_BUDGET):
|
||||
self.opener = urllib.request.build_opener(_SameHost())
|
||||
self.opener = urllib.request.build_opener(_SameHost(self))
|
||||
self.timeout = timeout
|
||||
self.budget = budget
|
||||
|
||||
@@ -115,7 +135,7 @@ def _response_from(resp):
|
||||
|
||||
def fetch(session, method, url, headers=None, body=None):
|
||||
if session.budget <= 0:
|
||||
return Response(None, {}, b"", "request budget exhausted")
|
||||
return Response(None, {}, b"", BUDGET_EXHAUSTED)
|
||||
session.budget -= 1
|
||||
req = urllib.request.Request(
|
||||
url, data=body, method=method, headers=headers or {})
|
||||
@@ -124,6 +144,8 @@ def fetch(session, method, url, headers=None, body=None):
|
||||
return _response_from(resp)
|
||||
except urllib.error.HTTPError as exc:
|
||||
return Response(exc.code, exc.headers, _error_body(exc))
|
||||
except _BudgetExhausted:
|
||||
return Response(None, {}, b"", BUDGET_EXHAUSTED)
|
||||
except (urllib.error.URLError, OSError, ValueError,
|
||||
http.client.HTTPException) as exc:
|
||||
reason = str(exc)
|
||||
@@ -140,20 +162,37 @@ def _verdict(ctx, response, is_open, msgs):
|
||||
return Probe(domain, pid, verdict, target, note)
|
||||
|
||||
|
||||
def _nonempty_rows(body):
|
||||
try:
|
||||
data = json.loads(body or b"[]")
|
||||
except ValueError:
|
||||
return False
|
||||
return isinstance(data, list) and len(data) > 0
|
||||
def _rows_state(resp):
|
||||
"""rows | empty | unreadable: what a 200 body says about table rows."""
|
||||
if not resp.body or len(resp.body) >= BODY_CAP:
|
||||
return "unreadable"
|
||||
data, is_json = _json_body(resp)
|
||||
if not is_json:
|
||||
return "unreadable"
|
||||
return "rows" if isinstance(data, list) and data else "empty"
|
||||
|
||||
|
||||
def _rows_verdict(ctx, resp, msgs):
|
||||
"""ctx is (domain, id, target); msgs is (rows_note, empty_note)."""
|
||||
if resp.error or resp.status in (401, 403, 404):
|
||||
return _verdict(ctx, resp, False, msgs)
|
||||
domain, pid, target = ctx
|
||||
if resp.status != 200:
|
||||
note = f"HTTP {resp.status}: not confirmed"
|
||||
return Probe(domain, pid, "SKIPPED", target, note)
|
||||
state = _rows_state(resp)
|
||||
if state == "unreadable":
|
||||
note = (f"HTTP {resp.status}: body not readable as JSON rows, "
|
||||
"not confirmed")
|
||||
return Probe(domain, pid, "SKIPPED", target, note)
|
||||
return _verdict(ctx, resp, state == "rows", msgs)
|
||||
|
||||
|
||||
def _table_probe(session, base, table, headers):
|
||||
target = f"{base}/rest/v1/{quote(table)}?select=*&limit=1"
|
||||
resp = fetch(session, "GET", target, headers)
|
||||
return _verdict(
|
||||
return _rows_verdict(
|
||||
("supabase", f"anon-read:{table}", target), resp,
|
||||
resp.status == 200 and _nonempty_rows(resp.body),
|
||||
("anon request returned rows", "anon request returned no row"))
|
||||
|
||||
|
||||
@@ -173,9 +212,8 @@ def probe_supabase(session, plan):
|
||||
def _cross_user_probe(session, base, path, headers):
|
||||
target = base + path
|
||||
resp = fetch(session, "GET", target, headers)
|
||||
return _verdict(
|
||||
return _rows_verdict(
|
||||
("supabase", f"cross-user:{path}", target), resp,
|
||||
resp.status == 200 and _nonempty_rows(resp.body),
|
||||
("second user's token returned these rows",
|
||||
"second user's token returned nothing"))
|
||||
|
||||
@@ -239,9 +277,13 @@ def _burst_codes(session, url, method, body, count):
|
||||
return codes
|
||||
|
||||
|
||||
def _rate_verdict(target, codes):
|
||||
def _rate_verdict(target, codes, count):
|
||||
sent = len([c for c in codes if c is not None])
|
||||
throttled = 429 in codes
|
||||
if not throttled and sent < count:
|
||||
return Probe("hosting", "rate-limit", "SKIPPED", target,
|
||||
"burst cut short (budget or transport), "
|
||||
"rate limit not confirmed")
|
||||
note = (f"sent {sent}, {'got a 429' if throttled else 'no 429'}: "
|
||||
+ ("throttled" if throttled else "no 429 seen on this route"))
|
||||
return Probe("hosting", "rate-limit",
|
||||
@@ -253,10 +295,11 @@ def probe_rate_limit(session, plan):
|
||||
if not cfg:
|
||||
return []
|
||||
target = plan["base_url"].rstrip("/") + cfg["path"]
|
||||
count = min(cfg.get("count", 20), BURST_CAP)
|
||||
codes = _burst_codes(
|
||||
session, target, cfg.get("method", "GET").upper(),
|
||||
cfg.get("body"), min(cfg.get("count", 20), BURST_CAP))
|
||||
return [_rate_verdict(target, codes)]
|
||||
cfg.get("body"), count)
|
||||
return [_rate_verdict(target, codes, count)]
|
||||
|
||||
|
||||
def _same_host(context, url):
|
||||
@@ -292,30 +335,47 @@ def _map_candidates(script_url, resp):
|
||||
return list(dict.fromkeys(urls))
|
||||
|
||||
|
||||
def _status_outcome(resp, target):
|
||||
"""Outcome of a fetched map candidate that answered with a status."""
|
||||
if resp.status == 200 and len(resp.body) >= BODY_CAP:
|
||||
return ("note", target, "map answered 200 but its body is over "
|
||||
"1 MB: sources not confirmed, fetch it by hand")
|
||||
if resp.status == 200 and b'"sources"' in resp.body:
|
||||
return "open", target, "source map served with its sources"
|
||||
if resp.status in (200, 404, 410):
|
||||
return "negative", target, ""
|
||||
return ("note", target,
|
||||
f"HTTP {resp.status}: map not readable, not confirmed")
|
||||
|
||||
|
||||
def _map_outcome(session, script_url, url):
|
||||
"""(kind, target, note), kind in open | negative | note | error."""
|
||||
if url.startswith("data:"):
|
||||
return "open", script_url, "inline source map in the script"
|
||||
target = _same_host(script_url, url)
|
||||
if not target:
|
||||
return "note", url, "map url on another host, not fetched"
|
||||
resp = fetch(session, "GET", target)
|
||||
if resp.error or resp.status is None:
|
||||
return "error", target, resp.error or "no response"
|
||||
return _status_outcome(resp, target)
|
||||
|
||||
|
||||
def _map_verdict(session, script_url, candidates):
|
||||
"""(verdict, target, note) over the candidate map urls, fail closed."""
|
||||
"""(verdict, target, note) over every candidate map url, fail closed."""
|
||||
seen, notes = set(), []
|
||||
for url in candidates:
|
||||
if url.startswith("data:"):
|
||||
if "base64," not in url:
|
||||
continue
|
||||
return "OPEN", script_url, "inline source map in the script"
|
||||
target = _same_host(script_url, url)
|
||||
if not target:
|
||||
return "SKIPPED", url, "map url on another host, not fetched"
|
||||
resp = fetch(session, "GET", target)
|
||||
if resp.error or resp.status is None:
|
||||
return "ERROR", target, resp.error or "no response"
|
||||
if 300 <= resp.status < 400:
|
||||
return ("SKIPPED", target, f"HTTP {resp.status}: map redirect "
|
||||
"dropped (off host or downgraded), not followed")
|
||||
if resp.status == 403 or (resp.status or 0) >= 500:
|
||||
return ("SKIPPED", target,
|
||||
f"HTTP {resp.status}: map not readable, not confirmed")
|
||||
if resp.status == 200 and len(resp.body) >= BODY_CAP:
|
||||
return ("SKIPPED", target, "map answered 200 but its body is "
|
||||
"over 1 MB: sources not confirmed, fetch it by hand")
|
||||
if resp.status == 200 and b'"sources"' in resp.body:
|
||||
return "OPEN", target, "source map served with its sources"
|
||||
key = _same_host(script_url, url) or url
|
||||
if key in seen:
|
||||
continue
|
||||
seen.add(key)
|
||||
kind, target, note = _map_outcome(session, script_url, url)
|
||||
if kind in ("open", "error"):
|
||||
return kind.upper(), target, note
|
||||
if kind == "note":
|
||||
notes.append(("SKIPPED", target, note))
|
||||
if notes:
|
||||
return notes[0]
|
||||
return "CLOSED", script_url, "no source map served for this script"
|
||||
|
||||
|
||||
@@ -379,8 +439,13 @@ def _snake(key):
|
||||
return re.sub(r"(?<=[a-z0-9])(?=[A-Z])", "_", key).replace("-", "_").lower()
|
||||
|
||||
|
||||
def _is_sensitive(key):
|
||||
name = _snake(key)
|
||||
return bool(SENSITIVE_KEY.search(name)) and not METADATA_KEY.search(name)
|
||||
|
||||
|
||||
def _sensitive_keys(data):
|
||||
return sorted({k for k in _keys(data) if SENSITIVE_KEY.search(_snake(k))})
|
||||
return sorted({k for k in _keys(data) if _is_sensitive(k)})
|
||||
|
||||
|
||||
def _key_note(keys):
|
||||
@@ -447,15 +512,10 @@ def _tally(results):
|
||||
for v in ("OPEN", "CLOSED", "SKIPPED", "ERROR")}
|
||||
|
||||
|
||||
def _printable(text):
|
||||
"""Control characters of a remote or plan string never reach the tty."""
|
||||
return re.sub(r"[\x00-\x1f\x7f-\x9f]", "?", str(text))
|
||||
|
||||
|
||||
def _probe_row(probe):
|
||||
return (f" {probe.verdict:<8} {probe.domain:<9} "
|
||||
f"{_printable(probe.id)} {_printable(probe.target)}\n"
|
||||
f" {_printable(probe.message)}")
|
||||
f"{printable(probe.id)} {printable(probe.target)}\n"
|
||||
f" {printable(probe.message)}")
|
||||
|
||||
|
||||
def _summary(results):
|
||||
@@ -466,7 +526,7 @@ def _summary(results):
|
||||
|
||||
def _render_text(plan, results):
|
||||
body = [_probe_row(p) for p in results]
|
||||
head = [_printable(f"guardrails live probe: {plan['base_url']}"),
|
||||
head = [printable(f"guardrails live probe: {plan['base_url']}"),
|
||||
f"probes: {len(results)} (read-only, bounded budget)"]
|
||||
return "\n".join(head + [""] + body + [_summary(results)])
|
||||
|
||||
@@ -527,6 +587,23 @@ def _exposure_error(cfg):
|
||||
return ""
|
||||
|
||||
|
||||
def _supabase_error(plan):
|
||||
cfg = plan.get("supabase")
|
||||
if cfg is None:
|
||||
return ""
|
||||
if not isinstance(cfg, dict):
|
||||
return "supabase must be an object"
|
||||
paths, tables = cfg.get("cross_user_paths"), cfg.get("tables")
|
||||
if paths is not None and not isinstance(paths, list):
|
||||
return "supabase.cross_user_paths must be a list"
|
||||
if tables is not None and not (isinstance(tables, list) and all(
|
||||
isinstance(t, str) for t in tables)):
|
||||
return "supabase.tables must be a list of strings"
|
||||
if (tables or paths) and not _http_url(cfg.get("url")):
|
||||
return "supabase.url must be an http(s) url"
|
||||
return ""
|
||||
|
||||
|
||||
def _shape_error(plan):
|
||||
rate = plan.get("rate_limit", {})
|
||||
if not isinstance(rate, dict):
|
||||
@@ -536,13 +613,7 @@ def _shape_error(plan):
|
||||
if plan.get("routes") is not None and \
|
||||
not isinstance(plan["routes"], list):
|
||||
return "routes must be a list"
|
||||
if plan.get("supabase") is not None and \
|
||||
not isinstance(plan["supabase"], dict):
|
||||
return "supabase must be an object"
|
||||
paths = _obj(plan, "supabase").get("cross_user_paths")
|
||||
if paths is not None and not isinstance(paths, list):
|
||||
return "supabase.cross_user_paths must be a list"
|
||||
return ""
|
||||
return _supabase_error(plan)
|
||||
|
||||
|
||||
def _plan_error(plan):
|
||||
@@ -567,17 +638,25 @@ def parse_args(argv):
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def _refusal(plan):
|
||||
hosts = [plan["base_url"]]
|
||||
supabase_url = _obj(plan, "supabase").get("url")
|
||||
if supabase_url:
|
||||
hosts.append(supabase_url)
|
||||
owned = " and ".join(printable(h) for h in hosts)
|
||||
return ("refused: pass --authorized to confirm you own "
|
||||
f"{owned} and may probe {'them' if len(hosts) > 1 else 'it'}")
|
||||
|
||||
|
||||
def main(argv):
|
||||
args = parse_args(argv)
|
||||
plan, error = _load_plan(args.plan)
|
||||
error = error or _plan_error(plan or {})
|
||||
if error:
|
||||
print(f"usage error: {error}", file=sys.stderr)
|
||||
print(f"usage error: {printable(error)}", file=sys.stderr)
|
||||
return 2
|
||||
if not args.authorized:
|
||||
print("refused: pass --authorized to confirm you own "
|
||||
f"{_printable(plan['base_url'])} and may probe it",
|
||||
file=sys.stderr)
|
||||
print(_refusal(plan), file=sys.stderr)
|
||||
return 2
|
||||
results = run_probes(Session(), plan)
|
||||
render = _render_json if args.json else _render_text
|
||||
|
||||
@@ -19,7 +19,7 @@ from collections import Counter
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from checks.common import Project
|
||||
from checks.common import Project, printable
|
||||
|
||||
SEVERITY_RANK = {"FAIL": 0, "WARN": 1, "MANUAL": 2}
|
||||
GATED = ("FAIL", "WARN")
|
||||
@@ -101,6 +101,11 @@ def _summary_line(findings):
|
||||
f"{n} {sev}" for sev, n in totals.items())
|
||||
|
||||
|
||||
def _safe_text(text):
|
||||
"""Control characters from file names and messages never reach the tty."""
|
||||
return "\n".join(printable(line) for line in text.split("\n"))
|
||||
|
||||
|
||||
def render_text(project, cat, result):
|
||||
lines = [
|
||||
f"{cat.name} scan: {project.root} ({len(project.files)} files)",
|
||||
@@ -110,7 +115,7 @@ def render_text(project, cat, result):
|
||||
lines.append("not applicable: " + ", ".join(result.skipped))
|
||||
for domain in result.applicable:
|
||||
lines += _domain_lines(domain, result.findings)
|
||||
return "\n".join(lines + [_summary_line(result.findings)])
|
||||
return _safe_text("\n".join(lines + [_summary_line(result.findings)]))
|
||||
|
||||
|
||||
def render_json(project, result):
|
||||
@@ -236,7 +241,7 @@ def _scan(cat, args):
|
||||
print(text)
|
||||
return 1 if any(f.severity == "FAIL" for f in result.findings) else 0
|
||||
for _, lines in checks:
|
||||
print("\n".join(lines))
|
||||
print(_safe_text("\n".join(lines)))
|
||||
return 0 if all(ok for ok, _ in checks) else 1
|
||||
|
||||
|
||||
@@ -244,6 +249,6 @@ def main(argv, cat):
|
||||
args = parse_args(argv, cat)
|
||||
error = _usage_error(cat, args)
|
||||
if error:
|
||||
print(f"usage error: {error}", file=sys.stderr)
|
||||
print(_safe_text(f"usage error: {error}"), file=sys.stderr)
|
||||
return 2
|
||||
return _scan(cat, args)
|
||||
Reference in new issue
Block a user