Merge feature/a11y-split-inj-exp into develop
This commit is contained in:
commit
f586304ba1
50 files changed
+2303
-394
No files matched your search
@@ -51,6 +51,7 @@ rules:
|
||||
| BLK-029 | 2026-10-08 | Claude Code mods (2.1.294): alias → id resolution for a model set by a hook lags the Agent tool's (`sonnet` → `claude-sonnet-5`, 404); Agent tool schema refuses full ids | upstream |
|
||||
| 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 |
|
||||
|
||||
---
|
||||
|
||||
@@ -329,3 +330,7 @@ rules:
|
||||
- **Solution**: c11cd3b drops `!call.moved` guard: model decision lands on (moved or kept) probed once if table id, unverified, not held. Fail → markDown 'probe', one re-decision → leaveDown → opus, stand-in effort +1. Cost ~1.3 s healthy / ≤8 s dead, 1st decision per process. Test `probe: a session model that never answers leaves for opus on the first step`.
|
||||
- **Status**: resolved. Open: leaveDown follows classifier `wanted` (implement → sonnet), not opus; "context size unknown" likely document attachment → `promptSize` unknown.
|
||||
- **Reference**: [[BLK-030]], [[LRN-218]], contract `.claude/tasks/contracts/2026-10-16-router-probe-session-model-1850.md`.
|
||||
|
||||
## 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]].
|
||||
@@ -139,6 +139,7 @@ rules:
|
||||
| BDR-119 | 2026-10-16 | impeccable = Build path for all UI; GATE-BLOCK swaps frontend-design for impeccable | accepted |
|
||||
| BDR-120 | 2026-10-18 | Secure-by-default guardrails: always-on rule file + /guardrails stdlib scanner, passwords in api domain | accepted |
|
||||
| BDR-121 | 2026-10-18 | Guardrails fix loop reuses bugfix circuit; scanner = contract oracle, baseline re-pass | accepted |
|
||||
| BDR-122 | 2026-10-19 | Guardrails split: /a11y standalone on shared scan engine, injection + exposure domains, exposure proven live by read-only probe | accepted |
|
||||
|
||||
---
|
||||
|
||||
@@ -1462,3 +1463,9 @@ Branch feature/user-writing-web-rules, UNMERGED (human gate).
|
||||
- **Why**: user ask. Proof by deterministic scanner, never executor's word; no new circuit to maintain.
|
||||
- **Alternatives rejected**: guardrails edits code itself (skips fresh gates); chain to /bugfix per finding (one interview + contract per hit, too heavy for 60 labels); LLM verifier as sole proof (verdict without execution).
|
||||
- **Refs**: feature/secure-by-default 73c25d7. Links [[BDR-120]].
|
||||
|
||||
## BDR-122 — Guardrails split: /a11y standalone on the shared scan engine, injection + exposure domains, exposure proven live by the read-only probe [accepted] (2026-10-19)
|
||||
- **Decision**: a11y out of /guardrails → `skills/a11y` (own SKILL, Tab-only walk, report `.claude/audits/A11Y.md`, fix loop = bugfixer + verify-secure gates, scanner oracle A11Y-CLEAR / A11Y-NO-NEW). Shared engine `skills/guardrails/scripts/scanner.py` `Catalogue(name, domains, rule_domains, manual_rules)`, marker = name upper; a11y `scan.py` loads it via `importlib.import_module` after `sys.path` insert (no noqa). Guardrails = 7 domains: api, hosting, supabase, messaging, functions, injection (INJ-*, 6 rules), exposure (EXP-*, 9 rules). `rules/secure-by-default.md` six numbered domains; a11y doctrine → lazy `rules/a11y.md` (`paths:` globs), `rules/web-building.md` points at it. Probe exposure block sourcemap / error-body / fields: fail-closed (unobserved = SKIPPED or ERROR, never CLOSED), every plan path starts with `/`, same scheme+host only, production build target (dev-server OPEN = dev artefact). security-auditor gate keeps `--domain api,supabase`. INJ-SQL-RAW-UNSAFE = WARN (variable ≠ proof), INJ-SQL-CONCAT = FAIL.
|
||||
- **Why**: user ask 2026-10-18 (keyboard/alt/labels as own skill; SQL/DB injection; browser-visible info). One engine = one CLI contract, two catalogues, no drift. Lazy a11y rule keeps CLAUDE.global.md at 320.
|
||||
- **Alternatives rejected**: a11y as a `--domain` flag only (user wanted own report + walk); engine copied into skills/a11y (two CLIs drift); exposure probe against dev server (dev artefacts = false OPEN); semgrep-only (blind to live responses, policies).
|
||||
- **Refs**: branch feature/a11y-split-inj-exp, contract `.claude/tasks/contracts/2026-10-18-guardrails-a11y-split-inj-exp-2210.md`; spec + plan purged at finish (`git show 988038c:docs/superpowers/...`). Supersedes the domain list of [[BDR-120]]; links [[BDR-121]].
|
||||
@@ -626,3 +626,6 @@ rules:
|
||||
- Passwords added on user question ("stockés en clair ?"): gap, rule had none. `checks/passwords.py` (api domain): clear column w/o hash lib, `==` or SQL compare, fast hash, log call, literal. Calibrated 7 projects: zero noise after htpasswd volume-mount FP. Suite 89/89, `make test` green.
|
||||
- Live probe added (user: "est-ce qu'il attaque de l'exterieur ?"). `probe.py` read-only, `--authorized`, env secrets, same-host redirect only, budget-capped. 5 probes confirm a hole from outside (OPEN/CLOSED). Suite 16/16 on a localhost fixture. Classifier blocked edits/tests carrying exploit-language and the SSRF-shaped redirect fixture; full-file Write passed, so probe strings are neutral and interpretation lives in checks.md.
|
||||
- Fix loop added (user: propose fixes via Fable, user accepts, re-pass proves). Reused bugfix circuit: contract criteria with scanner oracle (`--assert-absent`, GUARDRAILS-CLEAR) run by gates.sh, bugfixer executor, verify-secure gates, re-pass `--baseline` (GUARDRAILS-NO-NEW), 2 rounds max. Proposals on route plan (best tier = fable first). Model gate added, census locks updated.
|
||||
|
||||
## 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.
|
||||
@@ -210,6 +210,9 @@ rules:
|
||||
| LRN-188 | 2026-09-30 | Contract oracle tied to code shape (`grep -A6` line window) breaks on the first refactor while the property still holds; assert the property over the whole unit | writing CHECK oracles |
|
||||
| LRN-189 | 2026-10-06 | `cmd \| grep -q` under pipefail = SIGPIPE false negative (rc 141); `>/dev/null` is NOT a fix (GNU grep treats it like -q); portable = producer out of the pipeline | any bash under `set -o pipefail`, tests and prod |
|
||||
| LRN-190 | 2026-10-06 | Contract oracles: join `\\` line continuations before regex; "lint clean" = no finding beyond base, not zero; never `rm -rf "$var"` inside a CHECK | writing CHECK: lines |
|
||||
| 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 |
|
||||
|
||||
---
|
||||
|
||||
@@ -1814,3 +1817,14 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s
|
||||
- **Context**: model-router bugfix 2026-10-14/15, live scratch mod (`claude -p --plugin-dir`). `complete({model:'claude-opus-5-5', prompt:'ok', maxTokens:1})` resolved 1308 ms with OBJECT `{ isAnswered, text, usage }` (d.ts says string; maxTokens not honored, 43 output tokens). Same call on `claude-fable-5-1` without credits: no settle, no rejection after 900 s (client retries the 429). Plan r1 probed in a loop before deciding → BLOCKERs: unbounded spin on explicit alias, cur probed.
|
||||
- **Apply**: availability check via `complete()` = race vs own timeout, treat timeout + rejection as down, any resolved shape as up; never read `isAnswered:false` as failure (unobserved). Decide first, probe only the move target, once, skip cur and held ids, one re-decision without probe. No hook signal on the probe (Esc must not mark model down); probe sleep counts against 10 s `turn.step` budget. Links [[BLK-030]], [[LRN-207]].
|
||||
|
||||
## LRN-219 — Scanner regex over untrusted trees: bound every repeat, cap every comment blanker, lock with a timing test on an adversarial file
|
||||
- **Context**: guardrails split 2026-10-19. Challenge + 3 review rounds found quadratic COMMENT / env regexes, unbounded `[^>]*` and `\S+`. Fixes: DATA_ATTR `[\w-]{0,60}`, SCRIPT_SRC `[^>]{1,300}`, TRACE_MARKERS `[^)\n]{0,200}`, SQL_COMMENT `/\*[\s\S]{0,4000}?\*/`, MARKUP_COMMENT tempered `<!--(?:[^<]|<(?!!--)){0,4000}?-->`. Residual ~1.4 s on adversarial 200k file, accepted.
|
||||
- **Apply**: whole-file regex = bounded repeats, tempered dot for nested delimiters, timing lock in the suite (`guardrails-scan.test.sh`), files > 1 MB listed by path (`Project.large`), `.map` head 4 KB only. Links [[BDR-122]].
|
||||
|
||||
## LRN-220 — Live probe verdicts fail closed by construction: every negative branch needs its own fixture route, a 3xx reaching a verdict = dropped redirect = SKIPPED, a depth or size limit hit = SKIPPED never CLOSED
|
||||
- **Context**: same run. GATE 1 verifier: `fields` probe had OPEN + SKIPPED assertions, no CLOSED route. Opus review: three false verdicts (embedded `sourceMappingURL` string → OPEN; off-host map redirect dropped by `_SameHost` → 302 → CLOSED; sensitive key below depth 4 → CLOSED). Each = a code path no fixture route exercised.
|
||||
- **Apply**: per probe, fixture routes for OPEN, CLOSED, unobservable (SKIPPED), dropped redirect, truncated, oversize; anchor marker comments at line start and take the last; walk bounded bodies fully (iterative). Links [[BDR-122]], [[LRN-219]].
|
||||
|
||||
## 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]].
|
||||
@@ -1,5 +1,11 @@
|
||||
# TODO
|
||||
|
||||
## 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).
|
||||
- [ ] 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)
|
||||
User ask: hosting, a11y, Supabase, SMS/email consent, cloud functions must be baseline on every project, API and access secured systematically, plus a skill that tests all of it.
|
||||
Language call: scanner is Python stdlib, not Rust (default-language contraindication: skill scripts here are interpreted, no build step, same as explain-diff checker).
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
# CONTRACT — guardrails-a11y-split-inj-exp
|
||||
- date: 2026-10-18 | flow: ship-feature | branch: develop (feature branch at STEP 4)
|
||||
- status: active
|
||||
|
||||
## REQUEST (verbatim — IMMUTABLE)
|
||||
User message (typed):
|
||||
"en vrai sur le skill guardrails , on va separer l'Accessibilite : Tout au clavier (focus visible), un texte alternatif a chaque image, un label sur chaque champs. ET on va ajouter aux guardrails la recherche de faille sql / injections sur bdd et aussi faire attention a ce que pas trop d'info soit visible sur le navigateur (console, network, dnas inspecter l'element"
|
||||
|
||||
Pre-brainstorm answers (AskUserQuestion, same turn):
|
||||
- "Séparer a11y" → Skill autonome /a11y: nouveau skill avec son propre rapport et son parcours clavier; reprend les règles A11Y du scanner; /guardrails ne les contrôle plus; /web-validate garde le WCAG complet.
|
||||
- "Noms" → injection + exposure: domaines `injection` (règles INJ-*) et `exposure` (règles EXP-*).
|
||||
- "Portée exposure" → Statique + sonde en direct: le scanner repère dans le code les console.log de données, source maps publiques, état hydraté (__NEXT_DATA__) avec champs sensibles, commentaires et attributs data-* internes, erreurs détaillées renvoyées au client. La sonde GET existante vérifie aussi les réponses réelles (en-têtes, source maps servies, corps des erreurs, champs en trop).
|
||||
|
||||
Skill arguments ($ARGUMENTS to /ship-feature):
|
||||
"Evolve the guardrails skill (skills/guardrails). Decisions already made by the user, do not re-ask: (1) Accessibility becomes a standalone skill /a11y: it takes over the A11Y-* rules and the Tab-only keyboard walk-through (keyboard reachability with visible focus, alt text on every image, a label on every field), has its own report and fix loop, and /guardrails stops checking the a11y domain (secure-by-default.md section 2, guardrails description and --domain list, scan.py DOMAINS, tests and docs updated; /web-validate keeps full WCAG). (2) Two new guardrails domains named `injection` (rule prefix INJ-) and `exposure` (rule prefix EXP-). `injection`: static search for SQL injection and DB injection (string concatenation or interpolation into SQL, raw query calls, unparameterized ORM raw escapes, NoSQL operator injection, shell/command injection into DB tooling), with proof via the existing fix loop. `exposure`: make sure not too much information is visible in the browser (console, network tab, element inspector): static rules for console.log of data, public source maps, hydrated state such as __NEXT_DATA__ carrying sensitive fields, internal comments and data-* attributes, verbose errors or stack traces returned to the client, over-wide API responses; PLUS extend the read-only GET probe (probe.py) to check real responses (source maps served, error bodies, extra fields). Update rules/secure-by-default.md, references/checks.md, SKILL.md, test-prompts.json, tests (lib/tests/guardrails-scan.test.sh and probe test), README/CHANGELOG, profiles and model-router rows if citers need it. Current git state: on develop with two pre-existing uncommitted changes (mods/model-router/routing.json, settings.json) that are not part of this task."
|
||||
|
||||
## CLARIFICATIONS
|
||||
Q: Separate a11y how? / A: standalone skill /a11y (own report, own keyboard walk, own fix loop); /guardrails drops the domain; /web-validate keeps full WCAG.
|
||||
Q: New domain names? / A: `injection` (INJ-*) and `exposure` (EXP-*).
|
||||
Q: Exposure scope? / A: static rules + the existing read-only GET probe extended to real responses.
|
||||
Pass B (STEP 2 PLAN, 2026-10-18): none. The design approved at the brainstorm gate settled every visible, public-name and scope choice: rule ids and severities, `skills/a11y/scripts/a11y_checks.py`, markers A11Y-CLEAR / A11Y-NO-NEW, report `.claude/audits/A11Y.md`, `rules/a11y.md` (lazy), probe plan keys `exposure.scripts` / `exposure.error_routes`, GUARDRAILS_JWT2 reused as bearer by the fields probe, profiles audit/dev/web/web-full/full/max, CHANGELOG bullet amended in place plus a new /a11y bullet. [gated 2026-10-18]
|
||||
Amendment 2026-10-19 (after the plan challenge, before implementation; shown at the validation gate): criteria 4, 5 and 11 read the real module path `skills/a11y/scripts/a11y_checks.py`, require the file to exist and require a non-zero rule count, so an empty glob can no longer pass them vacuously.
|
||||
|
||||
## ACCEPTANCE CRITERIA
|
||||
1. `skills/a11y/SKILL.md` exists, with frontmatter `name: a11y` and an `effort:` matching its routing.json row.
|
||||
CHECK: test -f 'skills/a11y/SKILL.md' && grep -q '^name: a11y$' 'skills/a11y/SKILL.md' && echo A11Y-SKILL-PRESENT
|
||||
EXPECT: A11Y-SKILL-PRESENT
|
||||
EVIDENCE: MET exit=0 marker-found :: A11Y-SKILL-PRESENT
|
||||
2. /guardrails no longer scans a11y: `scan.py --domain a11y` is a usage error (exit 2) and the default run lists no `[a11y]` block.
|
||||
CHECK: python3 -B 'skills/guardrails/scripts/scan.py' 'lib/tests/fixtures/guardrails-good' --domain a11y >/dev/null 2>&1; [ $? -eq 2 ] && ! python3 -B 'skills/guardrails/scripts/scan.py' 'lib/tests/fixtures/guardrails-good' | grep -q '^\[a11y\]' && echo A11Y-DOMAIN-GONE
|
||||
EXPECT: A11Y-DOMAIN-GONE
|
||||
EVIDENCE: MET exit=0 marker-found :: A11Y-DOMAIN-GONE
|
||||
3. /guardrails scans `injection` and `exposure`: both appear in the `scanned:` line on the clean fixture, and the clean fixture still reports ` 0 FAIL, 0 WARN`.
|
||||
CHECK: out=$(python3 -B 'skills/guardrails/scripts/scan.py' 'lib/tests/fixtures/guardrails-good'); echo "$out" | grep '^scanned:' | grep -q 'injection' && echo "$out" | grep '^scanned:' | grep -q 'exposure' && echo "$out" | grep -q ' 0 FAIL, 0 WARN' && echo INJ-EXP-SCANNED-CLEAN
|
||||
EXPECT: INJ-EXP-SCANNED-CLEAN
|
||||
EVIDENCE: MET exit=0 marker-found :: INJ-EXP-SCANNED-CLEAN
|
||||
4. Every INJ-* and EXP-* rule the scanner can emit has a mutant in `lib/tests/guardrails-scan.test.sh` (one `mutant` call per rule id found in the checks modules).
|
||||
CHECK: n=0; missing=0; for r in $(grep -ho '"\(INJ\|EXP\)-[A-Z0-9-]*"' skills/guardrails/scripts/checks/*.py | tr -d '"' | sort -u); do n=$((n+1)); grep -q "$r" lib/tests/guardrails-scan.test.sh || { echo "no mutant: $r"; missing=1; }; done; [ $n -ge 15 ] && [ $missing -eq 0 ] && echo INJ-EXP-MUTANTS-PRESENT
|
||||
EXPECT: INJ-EXP-MUTANTS-PRESENT
|
||||
EVIDENCE: MET exit=0 marker-found :: INJ-EXP-MUTANTS-PRESENT
|
||||
5. The A11Y-* rules still run, from the /a11y skill's scanner (`skills/a11y/scripts/a11y_checks.py`), on the a11y fixture, and each A11Y rule keeps a mutant in the a11y test suite. [amended 2026-10-19: real path, file must exist, at least 5 rules]
|
||||
CHECK: test -f 'skills/a11y/scripts/a11y_checks.py' && { n=0; missing=0; for r in $(grep -ho '"A11Y-[A-Z0-9-]*"' skills/a11y/scripts/a11y_checks.py | tr -d '"' | sort -u); do n=$((n+1)); grep -q "$r" lib/tests/a11y-scan.test.sh || { echo "no mutant: $r"; missing=1; }; done; [ $n -ge 5 ] && [ $missing -eq 0 ] && echo A11Y-MUTANTS-PRESENT; }
|
||||
EXPECT: A11Y-MUTANTS-PRESENT
|
||||
EVIDENCE: MET exit=0 marker-found :: A11Y-MUTANTS-PRESENT
|
||||
6. probe.py has exposure probes and the probe suite exercises OPEN and CLOSED for each one.
|
||||
CHECK: grep -q 'def probe_exposure' 'skills/guardrails/scripts/probe.py' && grep -c 'exposure' 'lib/tests/guardrails-probe.test.sh' | awk '$1>=2{exit 0} {exit 1}' && echo EXP-PROBE-TESTED
|
||||
EXPECT: EXP-PROBE-TESTED
|
||||
EVIDENCE: MET exit=0 marker-found :: EXP-PROBE-TESTED
|
||||
7. Guardrails scan and probe suites, and the new a11y suite, are green.
|
||||
CHECK: make test suite='lib/tests/guardrails-scan.test.sh lib/tests/guardrails-probe.test.sh lib/tests/a11y-scan.test.sh' >/dev/null 2>&1 && echo GUARDRAILS-SUITES-GREEN
|
||||
EXPECT: GUARDRAILS-SUITES-GREEN
|
||||
EVIDENCE: MET exit=0 marker-found :: GUARDRAILS-SUITES-GREEN
|
||||
8. Censuses that bite on a new skill are green: effort-routing, profile-census, skill-routing-census, model-routing, loops-light.
|
||||
CHECK: make test suite='lib/tests/effort-routing.test.sh lib/tests/profile-census.test.sh lib/tests/skill-routing-census.test.sh lib/tests/model-routing.test.sh lib/tests/loops-light.test.sh' >/dev/null 2>&1 && echo CENSUS-GREEN
|
||||
EXPECT: CENSUS-GREEN
|
||||
EVIDENCE: MET exit=0 marker-found :: CENSUS-GREEN
|
||||
9. No stale six-domain list or "five domains" wording survives in the skill, rules, agents, README, USAGE or CHANGELOG Unreleased.
|
||||
CHECK: ! grep -rn 'api,hosting,a11y,supabase,messaging,functions' skills/guardrails rules agents README.md USAGE.md >/dev/null && ! grep -n 'five domains\|five guardrail\|five baseline' rules/secure-by-default.md agents/interviewer.md README.md >/dev/null && echo NO-STALE-DOMAIN-LIST
|
||||
EXPECT: NO-STALE-DOMAIN-LIST
|
||||
EVIDENCE: MET exit=0 marker-found :: NO-STALE-DOMAIN-LIST
|
||||
10. shellcheck clean on the shell surface.
|
||||
CHECK: shellcheck *.sh hooks/*.sh lib/*.sh && echo SHELLCHECK-CLEAN
|
||||
EXPECT: SHELLCHECK-CLEAN
|
||||
EVIDENCE: MET exit=0 marker-found :: SHELLCHECK-CLEAN
|
||||
11. `references/checks.md` documents every INJ-* and EXP-* rule the scanner emits, and the a11y skill has its own rule reference for every A11Y-* rule. [amended 2026-10-19: real a11y path, file must exist, at least 5 rules]
|
||||
CHECK: missing=0; for r in $(grep -ho '"\(INJ\|EXP\)-[A-Z0-9-]*"' skills/guardrails/scripts/checks/*.py | tr -d '"' | sort -u); do grep -q "$r" skills/guardrails/references/checks.md || { echo "undocumented: $r"; missing=1; }; done; test -f 'skills/a11y/scripts/a11y_checks.py' && { n=0; for r in $(grep -ho '"A11Y-[A-Z0-9-]*"' skills/a11y/scripts/a11y_checks.py | tr -d '"' | sort -u); do n=$((n+1)); grep -rq "$r" skills/a11y/references/ || { echo "undocumented: $r"; missing=1; }; done; [ $n -ge 5 ] && [ $missing -eq 0 ] && echo RULES-DOCUMENTED; }
|
||||
EXPECT: RULES-DOCUMENTED
|
||||
EVIDENCE: MET exit=0 marker-found :: RULES-DOCUMENTED
|
||||
12. The two pre-existing diffs (mods/model-router/routing.json dialog decisions, settings.json env-key move) are not swept into a feature commit: a routing.json commit on the branch contains only the a11y row. (judgement: read `git log -p develop..HEAD -- mods/model-router/routing.json settings.json`)
|
||||
13. The scanner stays read-only, stdlib-only, FAIL/WARN/MANUAL only; the probe stays GET/HEAD/OPTIONS plus the opt-in POST burst, never fuzzes, same-host redirects only (judgement against BDR-120 invariants and probe doctrine).
|
||||
14. The /a11y keyboard walk-through, report and fix loop are specified in its SKILL.md, with the walk marked "not done" when no browser tool is available (judgement).
|
||||
15. Rule/heading/label citers patched in the same change: secure-by-default.md section numbering and title, guardrails description and argument-hint, interviewer.md domain count, README/USAGE/CHANGELOG, web-validate/guardrails routing boundaries (judgement, grep-by-discipline per BDR-100).
|
||||
16. Both CLIs run on the shared engine: `skills/guardrails/scripts/scanner.py` defines `class Catalogue`, and both `scan.py` files import it (the a11y one through `importlib.import_module` after its `sys.path` insert, so no `noqa` suppression; oracle amended 2026-10-19 at GATE 1 iteration 1). [gated 2026-10-19]
|
||||
CHECK: grep -q '^class Catalogue' 'skills/guardrails/scripts/scanner.py' && grep -q '^import scanner' 'skills/guardrails/scripts/scan.py' && grep -Eq '^(import scanner|scanner = importlib\.import_module\("scanner"\))' 'skills/a11y/scripts/scan.py' && echo SHARED-ENGINE
|
||||
EXPECT: SHARED-ENGINE
|
||||
EVIDENCE: MET exit=0 marker-found :: SHARED-ENGINE
|
||||
17. The guardrails and a11y descriptions are 1024 bytes or fewer (BDR-014). [gated 2026-10-19]
|
||||
CHECK: g=$(awk 'NR==4' skills/guardrails/SKILL.md | sed 's/^description: //' | wc -c); a=$(awk 'NR==4' skills/a11y/SKILL.md | sed 's/^description: //' | wc -c); [ "$g" -le 1024 ] && [ "$a" -le 1024 ] && echo "DESC-$g-$a-OK"
|
||||
EXPECT: -OK
|
||||
EVIDENCE: MET exit=0 marker-found :: DESC-1005-906-OK
|
||||
18. The accessibility doctrine is a lazy rule: `rules/a11y.md` carries a `paths:` frontmatter, `rules/web-building.md` points at it, and `rules/secure-by-default.md` no longer has an Accessibility section. [gated 2026-10-19]
|
||||
CHECK: grep -q '^paths:' 'rules/a11y.md' && grep -q 'rules/a11y.md' 'rules/web-building.md' && ! grep -qi '^## [0-9]*\. Accessibility' 'rules/secure-by-default.md' && echo A11Y-RULE-LAZY
|
||||
EXPECT: A11Y-RULE-LAZY
|
||||
EVIDENCE: MET exit=0 marker-found :: A11Y-RULE-LAZY
|
||||
19. The exposure probe fails closed: the probe suite asserts SKIPPED for a refused fields route and for a listed script answering 404, and the probe source validates every plan path. [gated 2026-10-19]
|
||||
CHECK: grep -q 'fields on a 401 is SKIPPED' 'lib/tests/guardrails-probe.test.sh' && grep -q 'answers 404 is SKIPPED' 'lib/tests/guardrails-probe.test.sh' && grep -q 'def _plan_paths' 'skills/guardrails/scripts/probe.py' && echo PROBE-FAIL-CLOSED
|
||||
EXPECT: PROBE-FAIL-CLOSED
|
||||
EVIDENCE: MET exit=0 marker-found :: PROBE-FAIL-CLOSED
|
||||
20. The security-auditor keeps its scanner scope at `api,supabase` (no gate widening). [gated 2026-10-19]
|
||||
CHECK: grep -q -- '--domain api,supabase' 'agents/security-auditor.md' && echo AUDITOR-SCOPE-KEPT
|
||||
EXPECT: AUDITOR-SCOPE-KEPT
|
||||
EVIDENCE: MET exit=0 marker-found :: AUDITOR-SCOPE-KEPT
|
||||
21. `/a11y` is registered: routing row `"a11y": "reflect"`, present in the full and max profiles, `effort: high` in its frontmatter. [gated 2026-10-19]
|
||||
CHECK: grep -q '"a11y": "reflect"' 'mods/model-router/routing.json' && grep -q '^a11y ' 'lib/profiles/full.profile' && grep -q '^a11y ' 'lib/profiles/max.profile' && grep -q '^effort: high$' 'skills/a11y/SKILL.md' && echo A11Y-REGISTERED
|
||||
EXPECT: A11Y-REGISTERED
|
||||
EVIDENCE: MET exit=0 marker-found :: A11Y-REGISTERED
|
||||
22. `CLAUDE.global.md` stays at 320 lines and its routing line reads "W3C + WCAG conformance → web-validate". [gated 2026-10-19]
|
||||
CHECK: [ "$(wc -l < CLAUDE.global.md)" -eq 320 ] && grep -q 'W3C + WCAG conformance → web-validate' CLAUDE.global.md && echo GLOBAL-320
|
||||
EXPECT: GLOBAL-320
|
||||
EVIDENCE: MET exit=0 marker-found :: GLOBAL-320
|
||||
23. The exposure probe is documented as a production-build check with dev-server OPENs marked as dev artefacts, in the guardrails skill and its reference. [gated 2026-10-19]
|
||||
CHECK: grep -q 'dev artefact' 'skills/guardrails/SKILL.md' && grep -q 'dev artefact' 'skills/guardrails/references/checks.md' && echo PROD-BUILD-CAVEAT
|
||||
EXPECT: PROD-BUILD-CAVEAT
|
||||
EVIDENCE: MET exit=0 marker-found :: PROD-BUILD-CAVEAT
|
||||
24. `/web-validate` no longer carries the bare "a11y" and "accessibility" triggers and points the basics at /a11y. [gated 2026-10-19]
|
||||
CHECK: ! grep -q '"a11y"' 'skills/web-validate/SKILL.md' && grep -q '/a11y' 'skills/web-validate/SKILL.md' && echo WEB-VALIDATE-BOUNDARY
|
||||
EXPECT: WEB-VALIDATE-BOUNDARY
|
||||
EVIDENCE: MET exit=0 marker-found :: WEB-VALIDATE-BOUNDARY
|
||||
|
||||
## FILE SCOPE
|
||||
- skills/guardrails/SKILL.md, scripts/scanner.py (new engine), scripts/scan.py, scripts/probe.py, scripts/checks/{common,injection,exposure,supabase,passwords}.py, scripts/checks/a11y.py (moved to skills/a11y/scripts/a11y_checks.py), references/checks.md, test-prompts.json
|
||||
- skills/a11y/** (new: SKILL.md, scripts/scan.py, scripts/a11y_checks.py, references/checks.md, test-prompts.json)
|
||||
- rules/secure-by-default.md, rules/a11y.md (new, lazy), rules/web-building.md (two fragments point at rules/a11y.md)
|
||||
- skills/seo/SKILL.md, skills/harden/SKILL.md (routing citers)
|
||||
- lib/tests/guardrails-scan.test.sh, lib/tests/guardrails-probe.test.sh, lib/tests/a11y-scan.test.sh (new), lib/tests/fixtures/guardrails-good/**, lib/tests/fixtures/a11y-good/** (new, if split)
|
||||
- lib/tests/model-routing.test.sh, lib/tests/loops-light.test.sh (lock lists), lib/profiles/*.profile, mods/model-router/routing.json (a11y row only)
|
||||
- agents/interviewer.md, agents/security-auditor.md (if the domain subset changes), agents/bugfixer.md (if /a11y reuses it)
|
||||
- lib/verify-secure-loop.md, lib/contract-interview.md (flow enum, if /a11y gets the guardrails circuit)
|
||||
- README.md, USAGE.md, CHANGELOG.md, CLAUDE.global.md (routing line, only within the 320 budget)
|
||||
- skills/web-validate/SKILL.md (trigger boundary), skills/onboard/SKILL.md (a11y dispatch, if rerouted)
|
||||
- docs/superpowers/specs/2026-10-18-guardrails-a11y-split-design.md, docs/superpowers/plans/2026-10-18-guardrails-a11y-split.md (ship-feature transient artifacts, committed during the run for the SDD reviewers, auto-purged by `gitflow finish`, BDR-065; the plan was approved at the STEP 3 validation gate) [gated 2026-10-19]
|
||||
+2
-1
@@ -7,7 +7,8 @@ Format follows [Keep a Changelog](https://keepachangelog.com/) and this project
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- **Secure-by-default guardrails**: `rules/secure-by-default.md` (always on) makes five domains baseline on every project, plus systematic API and access hygiene (auth on every route, CORS, secrets, passwords hashed with argon2id or bcrypt, never compared in clear, logged or hardcoded): hosting (rate limit, CDN and firewall, hard spend cap), accessibility (keyboard, visible focus, alt text, field labels), Supabase (RLS on every table, owner-scoped policies, no service role key client-side), SMS and email (recorded consent, unsubscribe, STOP), cloud functions (no self-trigger, instance cap, budget stop). `/guardrails` audits them: a stdlib Python scanner (`skills/guardrails/scripts/scan.py`, FAIL / WARN / MANUAL, exit 1 on FAIL) then judgment, report in `.claude/audits/GUARDRAILS.md`. The security-auditor gate runs the scanner's `api` and `supabase` domains and blocks on FAIL. Items only a provider dashboard can set stay MANUAL, never claimed done. An optional read-only live probe (`skills/guardrails/scripts/probe.py`, `--live`) confirms a finding from outside on a target the user owns and names: anon-read, cross-user, no-auth route, CORS reflection and a capped rate-limit burst, verdicts OPEN / CLOSED / SKIPPED / ERROR. It sends GET, HEAD and OPTIONS only (one opt-in POST burst, capped at 25), requires `--authorized`, takes secrets from the environment never the command line, never follows a redirect to another host, and stops at a request budget. After the report, `/guardrails` proposes fixes (plan phase, so Fable when the router can switch), applies only the ones the user accepts through the `bugfixer` executor and the `lib/verify-secure-loop.md` gates, then re-scans: each accepted fix is a contract criterion whose oracle is the scanner (`--assert-absent RULE:path`, marker `GUARDRAILS-CLEAR`), and a full pass against the pre-fix baseline (`--baseline`, marker `GUARDRAILS-NO-NEW`) catches regressions; a live probe replays on the user's go; two rounds at most, residuals reported open; `--report-only` keeps the audit alone. Suites: `lib/tests/guardrails-scan.test.sh` (clean fixture plus one mutant per rule, check modes, `gates.sh` integration) and `lib/tests/guardrails-probe.test.sh` (probe logic against a localhost fixture server).
|
||||
- **Secure-by-default guardrails**: `rules/secure-by-default.md` (always on) makes six domains baseline on every project, plus systematic API and access hygiene (auth on every route, CORS, secrets, passwords hashed with argon2id or bcrypt, never compared in clear, logged or hardcoded): hosting (rate limit, CDN and firewall, hard spend cap), Supabase (RLS on every table, owner-scoped policies, no service role key client-side), SMS and email (recorded consent, unsubscribe, STOP), cloud functions (no self-trigger, instance cap, budget stop), injection (bound values in raw escapes, `format()` for dynamic SQL, allowlisted filters, no shell into a DB tool), exposure (no data in the console, no production source map, no debug flag, no secret in hydrated state, data attributes, hidden fields or shipped comments). `/guardrails` audits them: a stdlib Python scanner (`skills/guardrails/scripts/scan.py`, FAIL / WARN / MANUAL, exit 1 on FAIL) then judgment, report in `.claude/audits/GUARDRAILS.md`. The security-auditor gate runs the scanner's `api` and `supabase` domains and blocks on FAIL. Items only a provider dashboard can set stay MANUAL, never claimed done. An optional read-only live probe (`skills/guardrails/scripts/probe.py`, `--live`) confirms a finding from outside on a target the user owns and names: anon-read, cross-user, no-auth route, CORS reflection and a capped rate-limit burst, verdicts OPEN / CLOSED / SKIPPED / ERROR. An `exposure` block in the plan adds three read-only probes, meant for a production build or a staging URL: a served or inline source map for the page's scripts, a stack trace in a 404 or a user-named error route, sensitive keys in a JSON response (identifier-shaped names printed, never values); a target the probe could not observe is SKIPPED or ERROR, never CLOSED, and every plan path must start with `/`. It sends GET, HEAD and OPTIONS only (one opt-in POST burst, capped at 25), requires `--authorized`, takes secrets from the environment never the command line, never follows a redirect to another host, and stops at a request budget. After the report, `/guardrails` proposes fixes (plan phase, so Fable when the router can switch), applies only the ones the user accepts through the `bugfixer` executor and the `lib/verify-secure-loop.md` gates, then re-scans: each accepted fix is a contract criterion whose oracle is the scanner (`--assert-absent RULE:path`, marker `GUARDRAILS-CLEAR`), and a full pass against the pre-fix baseline (`--baseline`, marker `GUARDRAILS-NO-NEW`) catches regressions; a live probe replays on the user's go; two rounds at most, residuals reported open; `--report-only` keeps the audit alone. Suites: `lib/tests/guardrails-scan.test.sh` (clean fixture plus one mutant per rule, check modes, `gates.sh` integration) and `lib/tests/guardrails-probe.test.sh` (probe logic against a localhost fixture server).
|
||||
- **/a11y skill**: accessibility leaves `/guardrails` and becomes its own skill. Same A11Y-* rules (img alt, field label, click without keyboard, focus outline removed, positive tabindex) on the shared scan engine (`skills/guardrails/scripts/scanner.py`, a `Catalogue` per CLI; `skills/a11y/scripts/scan.py`, markers `A11Y-CLEAR` / `A11Y-NO-NEW`), a Tab-only walk of the main flow on `--live` through `/browse` (marked not done otherwise), report `.claude/audits/A11Y.md`, fixes proposed with the alt and label wording as the user's choice, applied through the bugfix circuit (`bugfixer`, verify-secure gates, `bugfix/a11y-<date>`), re-pass against a baseline. The keyboard, alt and label doctrine moves from `rules/secure-by-default.md` to the lazy `rules/a11y.md` (loads on UI files only; `rules/web-building.md` points at it). `/guardrails` scans `injection` (INJ-*) and `exposure` (EXP-*) instead, with per-language SQL patterns, shared `code_files` / `hits` / `dedupe_lines` / `client_reachable` helpers and a walker that lists files over 1 MB by path; `--domain a11y` is a usage error there. `/web-validate` keeps full WCAG conformance. Suite `lib/tests/a11y-scan.test.sh`; routing row `reflect`; profiles audit, dev, web, web-full, full, max.
|
||||
- **model-router mod**: `mods/model-router/`, a Claude Code mod (function-hooks plugin), routes every repo skill and agent from phase rows (`plan`, `reflect`, `orchestrate`, `escalate`, `judge`, `implement`, `write`, `verify`, `explore`, `apply`, `mechanical`; built-ins Explore on sonnet/medium, Plan on opus/xhigh). A typed skill routes the main loop to its row, and a best-tier row holds across turns in a run slot until `/route clear`, `/route off`, a user `/model` or a typed skill on a non-best row. Agents get their row's model at spawn (within the tier, upward only) and its effort on every step; explicit Agent params win. Orchestrators declare their phases through the `mcp__model-router__route` tool. `ultrathink` in a prompt sets the turn's minimum effort and `/route effort=max` holds until `/route clear`; the built-in `/effort` is not a lever inside a run. `/route show` names the run slot (`main: run <phase>`), and a `null` row in the override drops a default row. The model gets a `route` tool and the user a `/route` command (`show|clear|off|on|reload|pending|ask on|off|forget <name|all|projects>|<phase>|model=<alias|id> effort=<level>|switch on|off|verbose on|off`). Optional per-machine config `~/.claude/model-router.json`, where `"enabled": false` turns it off on that machine. The spinner suffix and the status line show the route in force. It loads in every session through the tracked symlink `skills/model-router` (`model-router@skills-dir`). `make doctor` gains a Mods section; suite `make test suite=lib/tests/mods.test.sh`. Known limits: a main-loop switch runs only while the cold read it costs (the context minus what the target model's prompt cache holds) fits `upgradeMaxTokens` (200000) or `downgradeMaxTokens` (120000), and a downgrade also needs `mainModelSwitch` (on by default, off on any non-boolean value); the hooks send full model ids, so the `models` table has to follow new versions.
|
||||
- **model-router first-use confirmation**: `mods/model-router/routing.json` (tracked) is the single source of the phase table and of every skill and agent row, and keeps the decisions: `confirmed`, `changed` (`from`/`to`), `projects` exceptions keyed by the origin remote reduced to `host/path` (credentials and local paths never stored), and `ask`. The first use of a rowed typed skill, a rowed agent spawn or a main-loop phase declared through the `route` tool opens a dialog with context: the skill's description (first sentence of its `SKILL.md` frontmatter) or the agent's, the phase with its `about` line (a new field on each of the 11 phases) and the model id and effort the next step really runs on. A row offers Later, Keep or Change; a main-loop phase Later or Keep. Change asks the model (fable, opus, sonnet, haiku with their tier), then the effort among those the phases of that model use (skipped when there is only one), then Everywhere or This project only; the pair maps to an existing phase (rows stay phase names, the same phase counts as Keep, a pair no phase offers is added by hand as a new phase). A skill-row change toasts the model and effort it now runs on, with the `/route switch on` hint when the main loop holds back a downgrade; a free-text answer counts as Later. One dialog at a time, never in headless (`-p`) runs or inside a sub-agent. Only a dialog answer, `/route ask on|off` or `/route forget` (which takes decisions back; a changed row returns to its shipped phase, the frontmatter floors stay yours to realign) writes the file (serialized, 64 KiB cap, never created when absent); each write asks you to commit it from the config repo. `/route pending` lists unconfirmed rows and phases. Layers: routing.json < `~/.claude/model-router.json` (its `ask` wins); a project's `.claude/model-router.json` is never read. Tests: `mods/model-router/hooks/register.test.ts`.
|
||||
- **Manual-push mode**: `git config gitflow.autopush false` (human-set) now stops every push the gitflow lib makes, not only the post-commit / post-merge hooks. `gitflow start` and `finish` branch, commit and merge locally and push nothing; `gitflow delete` leaves the `origin/` copy in place and prints `git push origin --delete <br>` for the user to run. `hooks/unpushed-guard.sh` stays silent at turn end in this mode and opens each session with one `ℹ manual push mode:` line counting the commits no remote holds across every local branch; an unparseable or unreadable `gitflow.autopush` value is treated as manual push mode too, and that line names it. `hooks/push-guard.sh` (PreToolUse, `Bash|Monitor`) refuses any `git push` Claude types while `gitflow.autopush` reads false in the session cwd or in a literal `-C`/`cd` directory the command names (global config counts outside a repo); the refusal tells the user to run it with `! git push`. It reads the mode through the same lib verb as every other reader and fails closed: an unparseable or unreadable value reads as manual, and an internal error, a missing `lib/gitflow.sh`, more than 20 distinct directory tokens in one command (capped before any token is classified), a `cd`/`-C` directory token mixing quoted and unquoted parts, or a payload jq cannot parse whose raw text looks like a push refuse the push (these pathological cases fire in auto mode too). Directory tokens are read as whole shell words, adjacent quoted segments and backslash escapes included. Once the text looks like a push, the command is split into simple commands (quotes, escapes, separators, heredoc bodies dropped) and a push must be git's own subcommand in one of them: `grep "git push"`, `git log -S "git push"`, `git config --get push.default`, `git stash push`, a heredoc quoting a push or a commit message naming one are allowed; `bash -c` scripts are re-checked, wrappers (`sudo`, `env`, `eval`, `xargs`, `timeout`, `git subtree`...) and assignments keep the text verdict. The misses listed in its header fall to a new `autoMode.soft_deny` rule that no request in the turn clears. The session banner adds `🔒 push : manual (autopush=false) — ! git push` when the key reads false, and `🔒 push : manual (autopush bad) — ! git push` when the value is invalid. Skills read the mode through a new lib verb, `bash ~/.claude/lib/gitflow.sh push-mode`: it prints `auto`, `manual` or `invalid` (rc 0) and names an invalid value on stderr (printable characters only, 64 at most). It is the one reader a skill may call, since the `git config` read of the key is denied to Claude. Skills push nothing on their own, except the `/release-candidate` tag in auto-push mode on an explicit go. Every "on origin" or "not pushed" line they print comes from `git rev-list --count origin/<br>..<br>` read after the fact, with the complete `! git …` command when something is left for the user to push. An invalid value (anything but unset, true or false, or a read that fails) is manual push mode for every reader and is named where it is read (see Fixed). Tests: `lib/gitflow-test.sh` T11b (push-mode verb), T18m and T18q blocks, `lib/tests/unpushed-guard.test.sh` T10-T16, `lib/tests/push-guard.test.sh` (98 checks).
|
||||
|
||||
+1
-1
@@ -273,7 +273,7 @@ cryptic names.
|
||||
finishing-a-development-branch → `gitflow finish` (human signal)
|
||||
systematic-debugging → bugfix
|
||||
verification-before-completion → the verifier gates
|
||||
- SEO+GEO → seo (GEO only → geo); W3C + WCAG a11y → web-validate;
|
||||
- SEO+GEO → seo (GEO only → geo); W3C + WCAG conformance → web-validate;
|
||||
security audit (secrets, CVE, OWASP) → cso
|
||||
- Media generation (image, video, audio, brand kit), explicit ask →
|
||||
Higgsfield pack, off by default: `bash ~/.claude/lib/toggle-external.sh
|
||||
|
||||
@@ -72,10 +72,10 @@ commands, settings, secrets, maintenance.
|
||||
Doctrine: the session model (Fable) does main-loop reflection ONLY —
|
||||
brainstorm, plan, contract, audit judgment, gates, loop decisions — enforced
|
||||
by a blocking gate (`lib/model-gate.md`) at the entry
|
||||
of the 15 reflection skills (the orchestrators plus `/analyze`): the skill
|
||||
calls the model-router `route` tool and its answer, which names the model
|
||||
id the main loop runs on, is the witness. A non-Fable/Opus id or the mod
|
||||
off stops the skill (`/route on` resumes the mod). Nothing dispatched
|
||||
of the 17 reflection skills (the orchestrators, `/analyze`, `/guardrails` and
|
||||
`/a11y`): the skill calls the model-router `route` tool and its answer, which
|
||||
names the model id the main loop runs on, is the witness. A non-Fable/Opus id or
|
||||
the mod off stops the skill (`/route on` resumes the mod). Nothing dispatched
|
||||
inherits silently: typed agents run on their model-router row, their
|
||||
`model:` frontmatter being the off-state floor; built-ins get an explicit
|
||||
`model=` at every call site.
|
||||
@@ -228,10 +228,11 @@ a different package, ships its own conflicting `graphify` bin) — see
|
||||
| `/reconcile` | Confront declared status (TODO, registries) against real git/fs state — surface stale items |
|
||||
| `/pdf-translate` | Translate a PDF to another language, output as HTML (via Vision) |
|
||||
| `/explain-diff` | Explain a diff, commit, branch or PR as one self-contained HTML page (background, intuition, code walkthrough, 5-question quiz), saved outside the repo |
|
||||
| `/guardrails` | Audit the five baseline guardrails (hosting, a11y, Supabase RLS, SMS/email consent, cloud functions) plus API hygiene (auth, CORS, secrets, password storage): deterministic scanner, then judgment, report in `.claude/audits/GUARDRAILS.md`. Then proposes fixes, applies the ones you accept and re-scans to prove each one. `--live <url you own>` adds a read-only probe that confirms a hole from outside |
|
||||
| `/guardrails` | Audit the six baseline guardrails (hosting, Supabase RLS, SMS/email consent, cloud functions, injection, browser exposure) plus API hygiene (auth, CORS, secrets, password storage): deterministic scanner, then judgment, report in `.claude/audits/GUARDRAILS.md`. Then proposes fixes, applies the ones you accept and re-scans to prove each one. `--live <url you own>` adds a read-only probe that confirms a hole from outside (routes, CORS, rate limit, and against a production build: source maps served, error bodies, sensitive keys) |
|
||||
| `/a11y` | Accessibility baseline: keyboard reachability with a visible focus, an alt on every image, a label on every field. Deterministic scanner, Tab walk on `--live`, report in `.claude/audits/A11Y.md`, fixes proposed with the wording as your choice, applied on acceptance and re-scanned to prove them. Full WCAG → `/web-validate` |
|
||||
| `/close` | End-of-session ritual — alias for `/capitalize --ritual` (dedup + TODO reconcile + 3-question reflection) |
|
||||
| `/harden` | Web hardening audit — HTTPS/TLS, HSTS, CSP, security headers |
|
||||
| `/web-validate` | W3C HTML/CSS validity + WCAG 2.1 accessibility audit |
|
||||
| `/web-validate` | W3C HTML/CSS validity + WCAG 2.1 conformance audit (keyboard/alt/label basics → /a11y) |
|
||||
| `/geo` | GEO-only audit — AI-search visibility (ChatGPT, Perplexity, Claude, Gemini…) |
|
||||
| `/client-handover` | Final project delivery — audits + branded deliverable (Markdown / HTML / PDF) |
|
||||
| `/profile` | Activate a skill profile (web / seo / web-full / full / max / backend / design / dev / qa / audit / minimal) (default: full) |
|
||||
|
||||
@@ -115,12 +115,13 @@ Tu veux...
|
||||
| État réel du travail ouvert | `/reconcile` |
|
||||
| Fin de session (= /capitalize --ritual) | `/close` |
|
||||
| Audit web (TLS, CSP, headers) | `/harden` |
|
||||
| Validité HTML/CSS + a11y | `/web-validate` |
|
||||
| Validité HTML/CSS + conformité WCAG | `/web-validate` |
|
||||
| Accessibilité de base (clavier, alt, labels) puis corriger | `/a11y` |
|
||||
| Visibilité IA (GEO seul) | `/geo` |
|
||||
| Livraison client finale | `/client-handover` |
|
||||
| Traduire un PDF | `/pdf-translate` |
|
||||
| Comprendre un changement pas suivi | `/explain-diff` |
|
||||
| Auditer garde-fous (RLS, a11y, consentement, fonctions, mots de passe) puis corriger | `/guardrails` |
|
||||
| Auditer garde-fous (RLS, consentement, fonctions, mots de passe, injection SQL, fuites navigateur) puis corriger | `/guardrails` |
|
||||
| Sonder le projet en direct (lecture seule, cible à toi) | `/guardrails --live <url>` |
|
||||
| Changer profil skills | `/profile` |
|
||||
| Audit/polish design (anti-slop) | `/impeccable` |
|
||||
@@ -161,11 +162,12 @@ Tu veux...
|
||||
| `/reconcile` | Connaître l'état réel du travail ouvert (TODO/registres douteux) | Confronte statut déclaré vs git/fs réel |
|
||||
| `/close` | Fin de session | Alias de /capitalize --ritual — dedup + TODO + réflexion 3 questions |
|
||||
| `/harden` | Audit sécurité web (SSL, CSP, HSTS) | Projet web avec config HTTP |
|
||||
| `/web-validate` | Audit W3C + WCAG a11y | Avant livraison projet web |
|
||||
| `/web-validate` | Audit W3C + conformité WCAG | Avant livraison projet web ; bases clavier/alt/labels → /a11y |
|
||||
| `/a11y` | Vérifier clavier, focus visible, alt, labels puis corriger | Scanner déterministe, parcours Tab sur `--live`, rapport `.claude/audits/A11Y.md`, propositions à valider (textes d'alt et de label = ton choix), re-passe qui prouve chaque correction |
|
||||
| `/client-handover` | Livraison client | Audits finaux + livrable brandé |
|
||||
| `/pdf-translate` | Traduire un PDF vers une autre langue | Sortie HTML fidèle (images, layout, style préservés) |
|
||||
| `/explain-diff` | Comprendre un commit, une branche ou une PR qu'on n'a pas suivis | Page HTML autonome hors du repo : contexte, intuition, code, quiz de 5 questions |
|
||||
| `/guardrails` | Vérifier hébergement, a11y, Supabase RLS, consentement SMS/email, fonctions cloud, stockage des mots de passe | Scanner déterministe, jugement, rapport `.claude/audits/GUARDRAILS.md`, propositions de correction à valider, re-passe qui prouve chaque correction ; `--live <url à toi>` sonde en lecture seule |
|
||||
| `/guardrails` | Vérifier hébergement, Supabase RLS, consentement SMS/email, fonctions cloud, stockage des mots de passe, injection SQL, exposition navigateur | Scanner déterministe, jugement, rapport `.claude/audits/GUARDRAILS.md`, propositions de correction à valider, re-passe qui prouve chaque correction ; `--live <url à toi>` sonde en lecture seule ; sonde `exposure` sur un build de production (source maps, corps d'erreur, clés sensibles) |
|
||||
| `/impeccable` | Audit/polish design + détecteur anti-slop déterministe | 23 verbes ; `npx impeccable detect` (exit 0/2) |
|
||||
| `/tour` | Sweep groupé sur un ou plusieurs projets | Sécu + nettoyage + reconcile + doc, boucle jusqu'à un pass propre |
|
||||
| `/route` | Voir ou fixer la route du mod model-router | show / clear / off / on / reload / pending / ask on\|off / <phase> / model=… effort=… / switch on\|off / classify on\|off (classifieur de prompt) / verbose on\|off (transitions seules) |
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: bugfixer
|
||||
description: Bug-fix EXECUTOR — dispatched by /bugfix (or /guardrails for accepted fixes) with a closed DIAGNOSIS + FIX PLAN + contract. Applies the fix and a regression test, runs the suite, reports. No investigation, no questions, no commit.
|
||||
description: Bug-fix EXECUTOR — dispatched by /bugfix (or /guardrails and /a11y for accepted fixes) with a closed DIAGNOSIS + FIX PLAN + contract. Applies the fix and a regression test, runs the suite, reports. No investigation, no questions, no commit.
|
||||
tools: Read, Edit, Write, Bash, Grep, Glob
|
||||
model: sonnet
|
||||
effort: medium
|
||||
|
||||
@@ -24,7 +24,7 @@ Gather context. Produce complete PROJECT BRIEF as single source of truth.
|
||||
| "I don't know / you decide" | Propose ONE concrete default + why, ask yes/no | Take the default, mark `(assumed)`, list in OPEN DECISIONS |
|
||||
| Contradictory answers (e.g. embedded runtime + managed cloud DB) | Name the contradiction, ask which side wins | Put BOTH options in OPEN DECISIONS; do not silently pick one |
|
||||
| Language not stated (new project / from scratch / whole-project rewrite) | Propose Rust + why (`rules/default-language.md`); name the contraindication if another language fits better (browser frontend, mandated platform, missing ecosystem) | Rust, marked `(assumed)`, listed in OPEN DECISIONS |
|
||||
| Project has an API, a database, messaging, cloud functions or a UI | Apply `rules/secure-by-default.md`: note under QUALITY which of the five guardrail domains apply, and list each dashboard-only item (spend cap, WAF, budget alert) in OPEN DECISIONS as manual | A domain applies and nothing is planned: list it in OPEN DECISIONS, never drop it silently |
|
||||
| Project has an API, a database, messaging, cloud functions or a UI | Apply `rules/secure-by-default.md`: note under QUALITY which of the six guardrail domains apply, and whether the accessibility baseline (`rules/a11y.md`) applies, and list each dashboard-only item (spend cap, WAF, budget alert) in OPEN DECISIONS as manual | A domain applies and nothing is planned: list it in OPEN DECISIONS, never drop it silently |
|
||||
| Partial answer to the block | Re-ask ONLY the missing items in the follow-up round | Missing fields → `none stated` + OPEN DECISIONS entry |
|
||||
| Feature list balloons (>10) | Keep the 10 the user ranks first as V1 | Overflow goes to OUT OF SCOPE with a `(deferred by budget)` tag |
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ Template:
|
||||
|
||||
```markdown
|
||||
# CONTRACT — <slug>
|
||||
- date: <YYYY-MM-DD> | flow: <ship-feature|feat|bugfix|hotfix|init-project|onboard|guardrails> | branch: <branch>
|
||||
- date: <YYYY-MM-DD> | flow: <ship-feature|feat|bugfix|hotfix|init-project|onboard|guardrails|a11y> | branch: <branch>
|
||||
- status: active
|
||||
|
||||
## REQUEST (verbatim — IMMUTABLE)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
cso
|
||||
harden personal
|
||||
guardrails personal
|
||||
a11y personal
|
||||
analyze personal
|
||||
|
||||
# SEO / GEO / web standards
|
||||
|
||||
@@ -19,6 +19,7 @@ code-clean personal
|
||||
commit-change personal
|
||||
explain-diff personal
|
||||
guardrails personal
|
||||
a11y personal
|
||||
|
||||
# Dev-lifecycle skills (agent-skills trio)
|
||||
observability-and-instrumentation external
|
||||
|
||||
@@ -46,6 +46,7 @@ geo personal
|
||||
web-validate personal
|
||||
harden personal
|
||||
guardrails personal
|
||||
a11y personal
|
||||
analyze personal
|
||||
cso
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ geo personal
|
||||
web-validate personal
|
||||
harden personal
|
||||
guardrails personal
|
||||
a11y personal
|
||||
analyze personal
|
||||
cso
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ geo personal
|
||||
web-validate personal
|
||||
harden personal
|
||||
guardrails personal
|
||||
a11y personal
|
||||
analyze personal
|
||||
|
||||
# === Perf + canary ===================================================
|
||||
|
||||
@@ -28,6 +28,7 @@ refactor personal
|
||||
|
||||
# Validation companion (basic W3C/a11y check during build)
|
||||
web-validate personal
|
||||
a11y personal
|
||||
|
||||
# External: design skills
|
||||
emil-design-eng external
|
||||
|
||||
Executable
+129
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env bash
|
||||
# lib/tests/a11y-scan.test.sh — floor of the /a11y scanner catalogue.
|
||||
# The clean fixture must scan with zero FAIL and zero WARN. Each mutant breaks
|
||||
# one rule on a copy of it and must raise that rule at the expected severity
|
||||
# (positive control). The A11Y-CLEAR / A11Y-NO-NEW markers, the gates.sh
|
||||
# contract wiring and the rejection of guardrails rules are checked too; the
|
||||
# shared engine itself is proven in guardrails-scan.test.sh.
|
||||
set -u
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
SCAN="$ROOT/skills/a11y/scripts/scan.py"
|
||||
GOOD="$ROOT/lib/tests/fixtures/a11y-good"
|
||||
WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
|
||||
PASS=0; FAIL=0; LAST_OUT=""
|
||||
|
||||
check() { # check <label> <got> <want>
|
||||
if [ "$2" = "$3" ]; then PASS=$((PASS+1)); echo " PASS $1"
|
||||
else FAIL=$((FAIL+1)); echo " FAIL $1 (got '$2', want '$3')"; fi
|
||||
}
|
||||
|
||||
scan() { python3 -B "$SCAN" "$@"; }
|
||||
|
||||
# edit <file> <sed-expr>: in-place edit without sed -i (BSD/GNU portable).
|
||||
edit() { sed "$2" "$1" > "$1.new" && mv "$1.new" "$1"; }
|
||||
|
||||
has() { # has <SEVERITY> <RULE>: the last scan raised it
|
||||
printf '%s\n' "$LAST_OUT" | grep -Eq "^ +$1 +$2 " && echo yes || echo no
|
||||
}
|
||||
|
||||
mutant() { # mutant <label> <SEVERITY> <RULE> <snippet run inside a copy>
|
||||
local label="$1" sev="$2" rule="$3" snippet="$4" dir
|
||||
dir="$WORK/$label"
|
||||
cp -R "$GOOD" "$dir" || { check "$label copy" failed ok; return; }
|
||||
if ! ( cd "$dir" && eval "$snippet" ) >/dev/null 2>&1; then
|
||||
check "$label setup" failed ok; return
|
||||
fi
|
||||
LAST_OUT=$(scan "$dir")
|
||||
check "$label raises $sev $rule" "$(has "$sev" "$rule")" yes
|
||||
}
|
||||
|
||||
benign() { # benign <label> <snippet>: a legitimate pattern raises nothing
|
||||
local label="$1" snippet="$2" dir="$WORK/$1" out
|
||||
cp -R "$GOOD" "$dir" || { check "$label copy" failed ok; return; }
|
||||
if ! ( cd "$dir" && eval "$snippet" ) >/dev/null 2>&1; then
|
||||
check "$label setup" failed ok; return
|
||||
fi
|
||||
out=$(scan "$dir")
|
||||
check "$label raises no FAIL or WARN" \
|
||||
"$(printf '%s\n' "$out" | grep -c ' 0 FAIL, 0 WARN')" 1
|
||||
}
|
||||
|
||||
TSX=src/components/ContactForm.tsx
|
||||
|
||||
echo "== clean fixture"
|
||||
out=$(scan "$GOOD"); rc=$?
|
||||
check "clean exit code" "$rc" 0
|
||||
check "clean has no FAIL or WARN" \
|
||||
"$(printf '%s\n' "$out" | grep -c ' 0 FAIL, 0 WARN')" 1
|
||||
check "report is titled a11y" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^a11y scan: ')" 1
|
||||
|
||||
echo "== rules"
|
||||
mutant img-alt FAIL A11Y-IMG-ALT "edit $TSX 's/ alt=\"Company logo\"//'"
|
||||
mutant field-label FAIL A11Y-FIELD-LABEL "edit $TSX '/<label htmlFor=\"email\">/d'"
|
||||
mutant click-keyboard FAIL A11Y-CLICK-NO-KEYBOARD "edit $TSX 's/ onKeyDown={go}//'"
|
||||
mutant tabindex-positive WARN A11Y-TABINDEX-POSITIVE \
|
||||
"edit $TSX 's/tabIndex={0}/tabIndex={2}/'"
|
||||
mutant focus-css-warn WARN A11Y-FOCUS-OUTLINE \
|
||||
"printf 'a:focus { outline: none; }\n' > src/styles.css"
|
||||
mutant focus-css-fail FAIL A11Y-FOCUS-OUTLINE \
|
||||
"printf 'a:focus { outline: none; }\n' > src/styles.css; edit $TSX 's/outline-none focus-visible:ring-2 focus-visible:ring-blue-500/x/'"
|
||||
mutant focus-tailwind FAIL A11Y-FOCUS-OUTLINE \
|
||||
"edit $TSX 's/outline-none focus-visible:ring-2 focus-visible:ring-blue-500/outline-none/'"
|
||||
|
||||
echo "== benign patterns stay silent"
|
||||
benign comment-with-img-tag \
|
||||
"printf '%s\n' '// the <img> below is decorative' >> $TSX"
|
||||
benign dialog-overlay-click \
|
||||
"printf '%s\n' '<div role=\"dialog\" aria-label=\"x\" onClick={go}>y</div>' >> $TSX"
|
||||
|
||||
echo "== check modes (contract oracle and re-pass baseline)"
|
||||
IMG="A11Y-IMG-ALT:$TSX"
|
||||
cp -R "$GOOD" "$WORK/cm"; edit "$WORK/cm/$TSX" 's/ alt="Company logo"//'
|
||||
out=$(scan "$WORK/cm" --assert-absent "$IMG"); rc=$?
|
||||
check "positive control: the oracle fails while the hit is there" "$rc" 1
|
||||
check "a failing oracle never prints the marker" \
|
||||
"$(printf '%s\n' "$out" | grep -c A11Y-CLEAR)" 0
|
||||
out=$(scan "$GOOD" --assert-absent "$IMG"); rc=$?
|
||||
check "the oracle passes once the hit is gone" "$rc" 0
|
||||
check "a passing oracle prints the marker" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^A11Y-CLEAR 1$')" 1
|
||||
scan "$GOOD" --assert-absent "HOST-NO-RATE-LIMIT:$TSX" >/dev/null 2>&1
|
||||
check "a guardrails rule is unknown here (exit 2)" "$?" 2
|
||||
scan "$WORK/cm" --json > "$WORK/cm-before.json"
|
||||
out=$(scan "$GOOD" --baseline "$WORK/cm-before.json"); rc=$?
|
||||
check "baseline lists the fixed hit" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^ FIXED A11Y-IMG-ALT ')" 1
|
||||
check "baseline with no new hit exits 0 with the marker" \
|
||||
"$rc:$(printf '%s\n' "$out" | grep -c '^A11Y-NO-NEW$')" "0:1"
|
||||
scan "$GOOD" --json > "$WORK/clean-before.json"
|
||||
out=$(scan "$WORK/cm" --baseline "$WORK/clean-before.json"); rc=$?
|
||||
check "baseline with a new hit exits 1 without the marker" \
|
||||
"$rc:$(printf '%s\n' "$out" | grep -c A11Y-NO-NEW)" "1:0"
|
||||
|
||||
# contract <dir> <file>: a fix contract whose oracle is the scanner itself
|
||||
contract() {
|
||||
cat > "$2" <<EOC
|
||||
# CONTRACT — a11y-oracle-test
|
||||
## ACCEPTANCE CRITERIA
|
||||
1. every image in the contact form has an alt
|
||||
CHECK: python3 -B '$SCAN' '$1' --assert-absent '$IMG'
|
||||
EXPECT: A11Y-CLEAR
|
||||
EVIDENCE: pending
|
||||
## FILE SCOPE
|
||||
$TSX
|
||||
EOC
|
||||
}
|
||||
contract "$WORK/cm" "$WORK/c-unfixed.md"
|
||||
bash "$ROOT/lib/gates.sh" run "$WORK/c-unfixed.md" >/dev/null 2>&1
|
||||
check "gates.sh: the oracle is UNMET before the fix" "$?" 2
|
||||
contract "$GOOD" "$WORK/c-fixed.md"
|
||||
bash "$ROOT/lib/gates.sh" run "$WORK/c-fixed.md" >/dev/null 2>&1
|
||||
check "gates.sh: the oracle is MET after the fix" "$?" 0
|
||||
|
||||
echo "== cli"
|
||||
scan --domain api "$GOOD" >/dev/null 2>&1; check "a guardrails domain exits 2" "$?" 2
|
||||
|
||||
echo "---"
|
||||
echo "passed: $PASS failed: $FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
@@ -0,0 +1,31 @@
|
||||
export function ContactForm({ go }: { go: () => void }) {
|
||||
return (
|
||||
<form>
|
||||
<label htmlFor="email">Email</label>
|
||||
<input id="email" type="email" />
|
||||
<label>
|
||||
Message
|
||||
<textarea name="msg" />
|
||||
</label>
|
||||
<input type="hidden" name="token" value="x" />
|
||||
<img src="/logo.png" alt="Company logo" />
|
||||
<img src="/divider.png" alt="" />
|
||||
<button
|
||||
type="submit"
|
||||
className="btn outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
<div role="button" tabIndex={0} onClick={go} onKeyDown={go}>
|
||||
Open
|
||||
</div>
|
||||
<div role="presentation" onClick={go}>
|
||||
<div role="dialog" aria-modal="true" onClick={(e) => e.stopPropagation()}>
|
||||
Dialog
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" className="hidden" />
|
||||
<div className="backdrop" onClick={go} />
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Vendored
File renamed without changes.
@@ -39,9 +39,9 @@ class H(BaseHTTPRequestHandler):
|
||||
|
||||
def do_OPTIONS(self):
|
||||
origin = self.headers.get("Origin", "")
|
||||
self._send(204, b"", {
|
||||
"Access-Control-Allow-Origin": origin,
|
||||
"Access-Control-Allow-Credentials": "true"})
|
||||
upper = ("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")
|
||||
names = tuple(n.lower() for n in upper) if self.path == "/lower" else upper
|
||||
self._send(204, b"", {names[0]: origin, names[1]: "true"})
|
||||
|
||||
def do_GET(self):
|
||||
path = self.path.split("?")[0]
|
||||
@@ -58,6 +58,80 @@ class H(BaseHTTPRequestHandler):
|
||||
return self._send(429 if HITS["rl"] > 5 else 200, b"")
|
||||
if path == "/nolimit":
|
||||
return self._send(200, b"")
|
||||
if path == "/":
|
||||
return self._send(200, b'<html><script src="/app.js"></script>'
|
||||
b'<script src="/clean.js"></script>'
|
||||
b'<script src=/inline.js></script>'
|
||||
b'<script src="/biginline.js"></script>'
|
||||
b'<script src="/err.js"></script>'
|
||||
b'<script src="https://cdn.invalid/x.js"></script>'
|
||||
b'</html>')
|
||||
if path == "/app.js":
|
||||
return self._send(200, b"console.log(1);\n//# sourceMappingURL=app.js.map\n")
|
||||
if path == "/app.js.map":
|
||||
return self._send(200, b'{"version":3,"sources":["src/app.ts"],"mappings":""}')
|
||||
if path == "/clean.js":
|
||||
return self._send(200, b"console.log(2);\n")
|
||||
if path == "/inline.js":
|
||||
return self._send(200, b"console.log(3);\n//# sourceMappingURL="
|
||||
b"data:application/json;base64,eyJ2ZXJzaW9uIjozfQ==\n")
|
||||
if path == "/biginline.js":
|
||||
return self._send(200, b"console.log(4);\n//# sourceMappingURL="
|
||||
b"data:application/json;base64," + b"A" * 20000)
|
||||
if path == "/err.js":
|
||||
return self._send(200, b"console.log(5);\n//# sourceMappingURL=err.js.map\n")
|
||||
if path == "/err.js.map":
|
||||
return self._send(503, b"")
|
||||
if path == "/api/session":
|
||||
return self._send(200, b'{"id": 2, "token": "t", "profile": {"private": false}}',
|
||||
{"Content-Type": "application/json"})
|
||||
if path == "/api/clean":
|
||||
return self._send(200, b'{"id": 7, "name": "Ada", "role": "member"}',
|
||||
{"Content-Type": "application/json"})
|
||||
if path == "/embed.js":
|
||||
return self._send(200, b'var s="//# sourceMappingURL=data:'
|
||||
b'application/json;base64,"+btoa(m);\n')
|
||||
if path == "/redir.js":
|
||||
return self._send(200, b"console.log(6);\n")
|
||||
if path == "/redir.js.map":
|
||||
return self._send(302, b"", {"Location": "http://other.invalid/m"})
|
||||
if path == "/hdr.js":
|
||||
return self._send(200, b"console.log(7);\n",
|
||||
{"SourceMap": "/hdr.real.map"})
|
||||
if path == "/hdr.real.map":
|
||||
return self._send(200, b'{"version":3,"sources":["a.ts"]}')
|
||||
if path == "/cmt.js":
|
||||
return self._send(200, b"console.log(8);\n//# sourceMappingURL="
|
||||
b"cmt.real.map\n")
|
||||
if path == "/cmt.real.map":
|
||||
return self._send(200, b'{"version":3,"sources":["b.ts"]}')
|
||||
if path == "/offhost.js":
|
||||
return self._send(200, b"x();\n//# sourceMappingURL="
|
||||
b"http://other.invalid/o.map\n")
|
||||
if path == "/badmap.js":
|
||||
return self._send(200, b"z();\n//# sourceMappingURL=http://[x\n")
|
||||
if path == "/trunc.js":
|
||||
return self._send(200, b"a" * 1_000_001)
|
||||
if path == "/bigmap.js":
|
||||
return self._send(200, b"y();\n")
|
||||
if path == "/bigmap.js.map":
|
||||
return self._send(200, b'{"sources":["c.ts"],"x":"' + b"A" * 1_000_001)
|
||||
if path == "/api/echo":
|
||||
bearer = self.headers.get("Authorization", "")
|
||||
body = b'{"id": 1, "password_hash": "x"}' if bearer else b'{"id": 1}'
|
||||
return self._send(200, body, {"Content-Type": "application/json"})
|
||||
if path == "/api/graphql":
|
||||
return self._send(200, b'{"data": {"users": {"edges": [{"node": '
|
||||
b'{"passwordHash": "x"}}]}}}',
|
||||
{"Content-Type": "application/json"})
|
||||
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 == "/api/me":
|
||||
return self._send(200, b'{"id": 1, "email": "t@t.io", '
|
||||
b'"password_hash": "x", "profile": {"api_key": "y"}, '
|
||||
b'"next_page_token": "abc", "hashtags": []}',
|
||||
{"Content-Type": "application/json"})
|
||||
return self._send(404, b"")
|
||||
|
||||
|
||||
@@ -146,6 +220,176 @@ printf '{"base_url": "%s", "rate_limit": {"path": "/x", "method": "DELETE"}}\n'
|
||||
probe --authorized "$WORK/bad.json" >/dev/null 2>&1
|
||||
check "a write method in the plan exits 2" "$?" 2
|
||||
|
||||
echo "== exposure probes"
|
||||
cat > "$WORK/exposure.json" <<EOF
|
||||
{"base_url": "$BASE",
|
||||
"routes": [{"path": "/api/me"}, {"path": "/api/guarded"}, {"path": "/api/private"},
|
||||
{"path": "/api/session"}, {"path": "/api/clean"}],
|
||||
"exposure": {"error_routes": ["/boom"]}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/exposure.json")"
|
||||
check "a served source map is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/app.js')" OPEN
|
||||
check "an inline data: source map is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/inline.js')" OPEN
|
||||
check "a large inline source map is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/biginline.js')" OPEN
|
||||
check "a script with no map is CLOSED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/clean.js')" CLOSED
|
||||
check "a foreign-host script is never probed" \
|
||||
"$(printf '%s\n' "$OUT" | grep -c 'cdn.invalid')" 0
|
||||
check "a traceback in an error body is OPEN" \
|
||||
"$(verdict "$OUT" 'error-body:/boom')" OPEN
|
||||
check "the random 404 path is CLOSED" \
|
||||
"$(verdict "$OUT" 'error-body:/guardrails-probe-')" 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
|
||||
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" \
|
||||
"$(printf '%s\n' "$OUT" | grep -A1 'fields:/api/session' | grep -c 'token$')" 1
|
||||
check "a clean JSON response is CLOSED" \
|
||||
"$(verdict "$OUT" 'fields:/api/clean')" CLOSED
|
||||
check "a 503 map answer is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/err.js')" SKIPPED
|
||||
check "fields on a 401 is SKIPPED, never CLOSED" \
|
||||
"$(verdict "$OUT" 'fields:/api/guarded')" SKIPPED
|
||||
check "fields on a non-JSON body is SKIPPED" \
|
||||
"$(verdict "$OUT" 'fields:/api/private')" SKIPPED
|
||||
cat > "$WORK/unreachable.json" <<EOF
|
||||
{"base_url": "http://127.0.0.1:1", "exposure": {}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/unreachable.json")"
|
||||
check "an unreachable base page gives a SKIPPED sourcemap row" \
|
||||
"$(verdict "$OUT" 'sourcemap')" SKIPPED
|
||||
printf '{"base_url": "%s", "exposure": {"error_routes": ["boom"]}}\n' "$BASE" > "$WORK/badexp.json"
|
||||
probe --authorized "$WORK/badexp.json" >/dev/null 2>&1
|
||||
check "an error route not starting with / exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "exposure": []}\n' "$BASE" > "$WORK/badexp2.json"
|
||||
probe --authorized "$WORK/badexp2.json" >/dev/null 2>&1
|
||||
check "a non-object exposure block exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "exposure": {"scripts": "/app.js"}}\n' "$BASE" > "$WORK/badexp3.json"
|
||||
probe --authorized "$WORK/badexp3.json" >/dev/null 2>&1
|
||||
check "a scripts string instead of a list exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "routes": [{"path": ".evil.invalid/x"}]}\n' "$BASE" > "$WORK/badroute.json"
|
||||
probe --authorized "$WORK/badroute.json" >/dev/null 2>&1
|
||||
check "a route path that could leave the host exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "routes": ["/x"]}\n' "$BASE" > "$WORK/badroute2.json"
|
||||
probe --authorized "$WORK/badroute2.json" >/dev/null 2>&1
|
||||
check "a route that is not an object exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "exposure": true}\n' "$BASE" > "$WORK/badexp4.json"
|
||||
probe --authorized "$WORK/badexp4.json" >/dev/null 2>&1
|
||||
check "a boolean exposure block exits 2 without a traceback" "$?" 2
|
||||
printf '{"base_url": "%s", "exposure": {"scripts": ["/does-not-exist.js"]}}\n' "$BASE" > "$WORK/stale.json"
|
||||
OUT="$(probe --authorized "$WORK/stale.json")"
|
||||
check "a listed script that answers 404 is SKIPPED, never CLOSED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/does-not-exist.js')" SKIPPED
|
||||
printf '{"base_url": "%s", "exposure": {"scripts": []}}\n' "$BASE" > "$WORK/noscript.json"
|
||||
OUT="$(probe --authorized "$WORK/noscript.json")"
|
||||
check "an empty scripts list still gives a SKIPPED sourcemap row" \
|
||||
"$(verdict "$OUT" 'sourcemap')" SKIPPED
|
||||
printf '{"base_url": "%s", "rate_limit": null}\n' "$BASE" > "$WORK/badrl.json"
|
||||
probe --authorized "$WORK/badrl.json" >/dev/null 2>&1
|
||||
check "a null rate_limit exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "routes": 5}\n' "$BASE" > "$WORK/badroutes.json"
|
||||
probe --authorized "$WORK/badroutes.json" >/dev/null 2>&1
|
||||
check "a non-list routes exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "supabase": {"url": "%s", "cross_user_paths": "/x"}}\n' \
|
||||
"$BASE" "$BASE" > "$WORK/badcu.json"
|
||||
probe --authorized "$WORK/badcu.json" >/dev/null 2>&1
|
||||
check "a string cross_user_paths exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "supabase": 5}\n' "$BASE" > "$WORK/badsb.json"
|
||||
probe --authorized "$WORK/badsb.json" >/dev/null 2>&1
|
||||
check "a non-object supabase block exits 2" "$?" 2
|
||||
cat > "$WORK/lower.json" <<EOF
|
||||
{"base_url": "$BASE", "cors": true, "cors_path": "/lower"}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/lower.json")"
|
||||
check "lowercase CORS header names are still read" \
|
||||
"$(verdict "$OUT" 'cors-reflect')" OPEN
|
||||
|
||||
echo "== exposure probes: map channels and fail-closed paths"
|
||||
cat > "$WORK/maps.json" <<EOF
|
||||
{"base_url": "$BASE",
|
||||
"exposure": {"scripts": ["/embed.js", "/redir.js", "/hdr.js", "/cmt.js",
|
||||
"/offhost.js", "/trunc.js", "/bigmap.js", "/badmap.js"], "error_routes": []}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/maps.json")"
|
||||
check "a sourceMappingURL string inside code is CLOSED, not an inline map" \
|
||||
"$(verdict "$OUT" 'sourcemap:/embed.js')" CLOSED
|
||||
check "a map that redirects off host is SKIPPED, never CLOSED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/redir.js')" SKIPPED
|
||||
check "a map named by the SourceMap header is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/hdr.js')" OPEN
|
||||
check "a map named by the trailing comment is OPEN" \
|
||||
"$(verdict "$OUT" 'sourcemap:/cmt.js')" OPEN
|
||||
check "a map url on another host is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/offhost.js')" SKIPPED
|
||||
check "a malformed map url is SKIPPED, no traceback" \
|
||||
"$(verdict "$OUT" 'sourcemap:/badmap.js')" SKIPPED
|
||||
check "the message line keeps its newline and 11-space indent" \
|
||||
"$(printf '%s\n' "$OUT" | grep -A1 'sourcemap:/offhost.js' | tail -1 | grep -c '^ [^ ]')" 1
|
||||
check "a truncated script is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/trunc.js')" SKIPPED
|
||||
check "an oversize map is SKIPPED" \
|
||||
"$(verdict "$OUT" 'sourcemap:/bigmap.js')" SKIPPED
|
||||
|
||||
echo "== fields probe: depth and bearer"
|
||||
cat > "$WORK/fields.json" <<EOF
|
||||
{"base_url": "$BASE",
|
||||
"routes": [{"path": "/api/echo"}, {"path": "/api/graphql"}],
|
||||
"exposure": {"scripts": [], "error_routes": []}}
|
||||
EOF
|
||||
OUT="$(probe --authorized "$WORK/fields.json")"
|
||||
check "a sensitive key nested past four levels is OPEN" \
|
||||
"$(verdict "$OUT" 'fields:/api/graphql')" OPEN
|
||||
check "the fields probe sends the bearer (key seen only with it)" \
|
||||
"$(verdict "$OUT" 'fields:/api/echo')" OPEN
|
||||
OUT="$(env -u GUARDRAILS_JWT2 python3 -B "$PROBE" --authorized "$WORK/fields.json")"
|
||||
check "without the bearer the same route is CLOSED" \
|
||||
"$(verdict "$OUT" 'fields:/api/echo')" CLOSED
|
||||
|
||||
echo "== plan validation and host guard"
|
||||
printf '{"base_url": "file:///tmp"}\n' > "$WORK/file.json"
|
||||
probe --authorized "$WORK/file.json" >/dev/null 2>&1
|
||||
check "a file:// base_url exits 2" "$?" 2
|
||||
printf '{"base_url": "http://[x"}\n' > "$WORK/v6.json"
|
||||
probe --authorized "$WORK/v6.json" >/dev/null 2>&1
|
||||
check "a malformed base_url exits 2" "$?" 2
|
||||
printf '{"base_url": 5}\n' > "$WORK/num.json"
|
||||
ERR="$(probe --authorized "$WORK/num.json" 2>&1 >/dev/null)"
|
||||
check "a non-string base_url exits 2 without a traceback" \
|
||||
"$(printf '%s\n' "$ERR" | grep -c 'Traceback')" 0
|
||||
probe --authorized "$WORK/num.json" >/dev/null 2>&1
|
||||
check "a non-string base_url exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "rate_limit": {"count": 5}}\n' "$BASE" > "$WORK/nopath.json"
|
||||
ERR="$(probe --authorized "$WORK/nopath.json" 2>&1 >/dev/null)"
|
||||
check "a rate_limit with no path gives a usage message, no traceback" \
|
||||
"$(printf '%s\n' "$ERR" | grep -c 'rate_limit.path must be a string')" 1
|
||||
probe --authorized "$WORK/nopath.json" >/dev/null 2>&1
|
||||
check "a rate_limit with no path exits 2" "$?" 2
|
||||
printf '{"base_url": "%s", "routes": [{"path": "/a\\u001b[31mb"}]}\n' "$BASE" > "$WORK/ctl.json"
|
||||
check "a control character in a path is an ERROR row, no traceback" \
|
||||
"$(probe --authorized "$WORK/ctl.json" 2>&1 | grep -c 'Traceback')" 0
|
||||
check "control characters of a target never reach the output" \
|
||||
"$(probe --authorized "$WORK/ctl.json" | LC_ALL=C grep -c "$(printf '\033')")" 0
|
||||
same_host() { python3 -B -c '
|
||||
import sys
|
||||
sys.path.insert(0, sys.argv[1])
|
||||
import probe
|
||||
print(bool(probe._same_host(sys.argv[2], sys.argv[3])))' \
|
||||
"$ROOT/skills/guardrails/scripts" "$1" "$2"; }
|
||||
check "an https to http move is not the same host" \
|
||||
"$(same_host https://a.test/x http://a.test/y)" False
|
||||
check "a different port is not the same host" \
|
||||
"$(same_host http://a.test/x http://a.test:81/y)" False
|
||||
check "a same-scheme same-host url is kept" \
|
||||
"$(same_host http://a.test/x /y)" True
|
||||
check "an http to https upgrade on the host is kept" \
|
||||
"$(same_host http://a.test/x https://a.test/y)" True
|
||||
|
||||
echo "== JSON output"
|
||||
check "json reports the open count" \
|
||||
"$(probe --authorized --json "$WORK/plan.json" \
|
||||
|
||||
@@ -52,12 +52,14 @@ SQL=supabase/migrations/0001_init.sql
|
||||
TSX=src/components/ContactForm.tsx
|
||||
NOTIFY=supabase/functions/notify/index.ts
|
||||
SMS=supabase/functions/sms/index.ts
|
||||
API=src/pages/api/notes.ts
|
||||
|
||||
echo "== clean fixture"
|
||||
out=$(scan "$GOOD"); rc=$?
|
||||
check "clean exit code" "$rc" 0
|
||||
check "clean has no FAIL or WARN" \
|
||||
"$(printf '%s\n' "$out" | grep -c ' 0 FAIL, 0 WARN')" 1
|
||||
check "a11y is not scanned" "$(printf '%s\n' "$out" | grep -c '^\[a11y\]')" 0
|
||||
|
||||
echo "== supabase"
|
||||
mutant rls-missing FAIL SB-RLS-MISSING \
|
||||
@@ -134,19 +136,6 @@ mutant no-rate-limit FAIL HOST-NO-RATE-LIMIT "rm src/middleware.ts"
|
||||
mutant origin-exposed WARN HOST-ORIGIN-EXPOSED \
|
||||
"printf 'app = \"x\"\n' > fly.toml; edit docs/DEPLOY.md 's/Cloudflare/an edge proxy/'"
|
||||
|
||||
echo "== a11y"
|
||||
mutant img-alt FAIL A11Y-IMG-ALT "edit $TSX 's/ alt=\"Company logo\"//'"
|
||||
mutant field-label FAIL A11Y-FIELD-LABEL "edit $TSX '/<label htmlFor=\"email\">/d'"
|
||||
mutant click-keyboard FAIL A11Y-CLICK-NO-KEYBOARD "edit $TSX 's/ onKeyDown={go}//'"
|
||||
mutant tabindex-positive WARN A11Y-TABINDEX-POSITIVE \
|
||||
"edit $TSX 's/tabIndex={0}/tabIndex={2}/'"
|
||||
mutant focus-css-warn WARN A11Y-FOCUS-OUTLINE \
|
||||
"printf 'a:focus { outline: none; }\n' > src/styles.css"
|
||||
mutant focus-css-fail FAIL A11Y-FOCUS-OUTLINE \
|
||||
"printf 'a:focus { outline: none; }\n' > src/styles.css; edit $TSX 's/outline-none focus-visible:ring-2 focus-visible:ring-blue-500/x/'"
|
||||
mutant focus-tailwind FAIL A11Y-FOCUS-OUTLINE \
|
||||
"edit $TSX 's/outline-none focus-visible:ring-2 focus-visible:ring-blue-500/outline-none/'"
|
||||
|
||||
echo "== messaging"
|
||||
mutant no-consent FAIL MSG-NO-CONSENT-RECORD \
|
||||
"for f in $SQL $NOTIFY $SMS; do edit \$f 's/consent_at/seen_at/g;s/consent_source/seen_src/g'; done"
|
||||
@@ -175,6 +164,96 @@ mutant firebase-loop WARN FN-SELF-TRIGGER \
|
||||
mutant key-body FAIL API-SECRET-LITERAL \
|
||||
'printf -- "-----BEGIN %s KEY-----\n%s\n" PRIVATE "$(head -c 40 /dev/zero | tr "\0" A)" > src/key.ts'
|
||||
|
||||
echo "== injection"
|
||||
mutant sql-template FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'const q = \`select id from notes where owner = \${owner}\`;' >> $API"
|
||||
mutant sql-concat FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'const q = \"select id from notes where owner = \" + owner;' >> $API"
|
||||
mutant sql-fstring FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'cur.execute(f\"delete from notes where id = {note_id}\")' > src/lib/cleanup.py"
|
||||
mutant sql-php-interpolation FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' '<?php \$r = \$db->query(\"select id from notes where owner = \$owner\");' > src/lib/notes.php"
|
||||
mutant sql-py-concat FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'cur.execute(\"select id from notes where owner = \" + owner)' > src/lib/cleanup.py"
|
||||
mutant sql-quoted-value FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' \$'const q = \"select id from notes where owner = \\'\" + owner + \"\\'\";' >> $API"
|
||||
mutant sql-php-dot FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' \$'<?php \$r = \$db->query(\"select id from notes where owner = \\'\" . \$owner . \"\\'\");' > src/lib/notes.php"
|
||||
mutant sql-raw-unsafe WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'const rows = await prisma.\$queryRawUnsafe(statement);' >> $API"
|
||||
mutant sql-sqla-text-var WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'import sqlalchemy' 'conn.execute(text(query))' > src/lib/db.py"
|
||||
mutant shell-db-os-system FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' 'os.system(\"psql \" + url)' > src/lib/backup.py"
|
||||
mutant shell-db-template FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' 'exec(\`psql \${db}\`);' > src/lib/backup.ts"
|
||||
mutant sql-ruby-where-interp FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'User.where(\"name = #{name}\")' > src/lib/users.rb"
|
||||
mutant shell-db-php-upper-var FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' '<?php shell_exec(\"mysqldump --host=\$Host app\");' > src/lib/dump.php"
|
||||
mutant concat-in-sqla-text FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'import sqlalchemy' 'conn.execute(text(f\"select id from notes where owner = {owner}\"))' > src/lib/db.py"
|
||||
mutant concat-in-objects-raw FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'User.objects.raw(f\"select id from notes where owner = {name}\")' > src/lib/db.py"
|
||||
mutant concat-in-knex-raw FAIL INJ-SQL-CONCAT \
|
||||
"printf '%s\n' 'knex.raw(base + \" where id = \" + id);' >> $API"
|
||||
mutant sql-sqla-sa-text WARN INJ-SQL-RAW-UNSAFE \
|
||||
"printf '%s\n' 'import sqlalchemy as sa' 'conn.execute(sa.text(q))' > src/lib/db.py"
|
||||
mutant sql-dynamic-exec WARN INJ-SQL-DYNAMIC-EXEC \
|
||||
"printf '%s\n' \"execute 'select count(*) from ' || tbl into n;\" >> $SQL"
|
||||
mutant postgrest-filter WARN INJ-POSTGREST-FILTER \
|
||||
"printf '%s\n' 'const { data } = await supabase.from(\"notes\").select().or(\`owner.eq.\${who}\`);' >> $API"
|
||||
mutant nosql-operator WARN INJ-NOSQL-OPERATOR \
|
||||
"printf '%s\n' 'const doc = await Notes.findOne({ owner: req.body.owner });' >> $API"
|
||||
mutant shell-db-tool FAIL INJ-SHELL-DB-TOOL \
|
||||
"printf '%s\n' 'execSync(\`pg_dump --table=\${table} app > backup.sql\`);' > src/lib/backup.ts"
|
||||
|
||||
echo "== exposure"
|
||||
mutant console-data-public-dir WARN EXP-CONSOLE-DATA \
|
||||
"mkdir -p public/js; printf '%s\n' 'console.log(user);' > public/js/app.js"
|
||||
mutant data-attr-hidden-input WARN EXP-DATA-ATTR-SENSITIVE \
|
||||
"printf '%s\n' '<input type=\"hidden\" name=\"api_key\" value={k} />' >> $TSX"
|
||||
mutant debug-errorhandler FAIL EXP-DEBUG-ON \
|
||||
"printf '%s\n' 'app.use(errorhandler());' >> $API"
|
||||
mutant console-data WARN EXP-CONSOLE-DATA \
|
||||
"printf '%s\n' 'console.log(\"saved\", session);' >> $TSX"
|
||||
mutant sourcemap-next FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
"printf '%s\n' 'module.exports = { productionBrowserSourceMaps: true };' > next.config.js"
|
||||
mutant sourcemap-vite-inline FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
"printf '%s\n' 'export default { build: { sourcemap: \"inline\" } };' > vite.config.ts"
|
||||
mutant sourcemap-webpack-warn WARN EXP-SOURCEMAP-PUBLIC \
|
||||
"printf '%s\n' 'module.exports = { devtool: \"eval-source-map\" };' > webpack.config.js"
|
||||
mutant sourcemap-public-dir FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
"mkdir -p public/assets; printf '%s\n' '{\"version\":3,\"sources\":[\"src/app.ts\"],\"mappings\":\"AAAA\"}' > public/assets/app.js.map"
|
||||
mutant sourcemap-large-map FAIL EXP-SOURCEMAP-PUBLIC \
|
||||
"mkdir -p public; { printf '%s' '{\"version\":3,\"sources\":[\"src/app.ts\"],\"mappings\":\"'; head -c 1100000 /dev/zero | tr '\\0' A; printf '%s\n' '\"}'; } > public/app.js.map"
|
||||
mutant hydrated-sensitive WARN EXP-HYDRATED-SENSITIVE \
|
||||
"printf '%s\n' 'export async function getServerSideProps() { return { props: { accessToken: process.env.CRM_TOKEN } }; }' > src/pages/account.tsx"
|
||||
mutant markup-comment WARN EXP-MARKUP-COMMENT \
|
||||
"printf '%s\n' '<!-- staging login: see the internal wiki before release -->' > src/pages/index.html"
|
||||
mutant data-attr-sensitive WARN EXP-DATA-ATTR-SENSITIVE \
|
||||
"printf '%s\n' '<div data-api-key={key}>x</div>' >> $TSX"
|
||||
mutant error-stack FAIL EXP-ERROR-STACK \
|
||||
"printf '%s\n' 'export function onError(err: Error) { return new Response(err.stack, { status: 500 }); }' >> $API"
|
||||
mutant error-message WARN EXP-ERROR-MESSAGE \
|
||||
"printf '%s\n' 'export function onFail(err: Error) { return Response.json({ error: err.message }, { status: 500 }); }' >> $API"
|
||||
mutant debug-on FAIL EXP-DEBUG-ON \
|
||||
"printf '%s\n' 'DEBUG = True' > src/settings.py"
|
||||
mutant debug-env FAIL EXP-DEBUG-ON \
|
||||
"printf '%s\n' 'APP_DEBUG=true' > .env.production"
|
||||
mutant response-wide WARN EXP-RESPONSE-WIDE \
|
||||
"printf '%s\n' 'const { data } = await db.from(\"profiles\").select(\"*\");' >> $API"
|
||||
mutant response-wide-prisma WARN EXP-RESPONSE-WIDE \
|
||||
"printf '%s\n' 'const u = await prisma.user.findUnique({ where: { id } });' >> $API"
|
||||
mutant response-wide-sql WARN EXP-RESPONSE-WIDE \
|
||||
"printf '%s\n' 'const q = \"select * from users where id = \$1\";' >> $API"
|
||||
mutant error-stack-single-file FAIL EXP-ERROR-STACK \
|
||||
"printf '%s\n' 'app.use((err, req, res, next) => res.status(500).send(err.stack));' > server.js"
|
||||
mutant hydrated-identifier WARN EXP-HYDRATED-SENSITIVE \
|
||||
"printf '%s\n' 'export async function getServerSideProps() { const token = await crm(); return { props: { accessToken: token } }; }' > src/pages/account.tsx"
|
||||
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 "== benign patterns stay silent"
|
||||
benign() { # benign <label> <snippet>: a legitimate pattern raises nothing
|
||||
local label="$1" snippet="$2" dir="$WORK/$1"
|
||||
@@ -186,10 +265,8 @@ benign() { # benign <label> <snippet>: a legitimate pattern raises nothing
|
||||
check "$label raises no FAIL or WARN" \
|
||||
"$(printf '%s\n' "$out" | grep -c ' 0 FAIL, 0 WARN')" 1
|
||||
}
|
||||
benign comment-with-img-tag \
|
||||
"printf '%s\n' '// the <img> below is decorative' >> $TSX"
|
||||
benign dialog-overlay-click \
|
||||
"printf '%s\n' '<div role=\"dialog\" aria-label=\"x\" onClick={go}>y</div>' >> $TSX"
|
||||
benign large-level-map \
|
||||
"mkdir -p public/levels; head -c 1100000 /dev/zero | tr '\\0' x > public/levels/big.map"
|
||||
benign helper-under-api \
|
||||
"mkdir -p src/pages/api/helpers; printf '%s\n' 'export const fmt = () => 1;' > src/pages/api/helpers/format.ts"
|
||||
benign mailer-test-file \
|
||||
@@ -228,6 +305,94 @@ ENVKEY='printf "SUPABASE_SERVICE_ROLE_KEY=%s.%s.signaturepart\n" "$(b64 "{\"alg\
|
||||
benign env-worker-ignored "printf '.env.*\n' >> .gitignore; $ENVKEY"
|
||||
mutant env-worker-tracked FAIL SB-SERVICE-ROLE-LITERAL "$ENVKEY"
|
||||
|
||||
benign parameterized-query \
|
||||
"printf '%s\n' 'const r = await db.query(\"select id from notes where owner = \$1\", [owner]);' >> $API"
|
||||
benign tagged-sql-template \
|
||||
"printf '%s\n' 'const r = await sql\`select id from notes where owner = \${owner}\`;' >> $API"
|
||||
benign typed-sql-tag \
|
||||
"printf '%s\n' 'const r = await sql<Note[]>\`select id from notes where owner = \${owner}\`;' >> $API"
|
||||
benign express-raw-webhook \
|
||||
"printf '%s\n' 'app.post(\"/hook\", express.raw({ type: \"application/json\" }), onHook);' >> $API"
|
||||
benign ui-copy-select \
|
||||
"printf '%s\n' 'const hint = \`Select a plan from the list, \${name}\`;' >> $TSX"
|
||||
benign ui-copy-delete \
|
||||
"printf '%s\n' 'const label = \"Delete from favorites \" + item.title;' >> $TSX"
|
||||
benign jquery-not \
|
||||
"printf '%s\n' 'const rows = \$(\".row\").not(\".row-\" + id);' >> $TSX"
|
||||
benign argv-db-tool \
|
||||
"printf '%s\n' 'spawnSync(\"pg_dump\", [\"--table\", table, \"app\"]);' > src/lib/backup.ts"
|
||||
benign format-dynamic-exec \
|
||||
"printf '%s\n' \"execute format('select count(*) from %I', tbl) into n;\" >> $SQL"
|
||||
benign test-path-sql \
|
||||
"mkdir -p src/__tests__; printf '%s\n' 'const q = \`select id from notes where owner = \${owner}\`;' > src/__tests__/notes.test.ts"
|
||||
benign minified-bundle \
|
||||
"printf '%s\n' 'const q=\`select id from notes where owner = \${o}\`;' > src/lib/app.min.js"
|
||||
benign long-line-bundle \
|
||||
"head -c 6000 /dev/zero | tr '\\0' x > src/lib/bundle.js; printf '%s\n' ' const q=\`select id from notes where owner = \${o}\`;' >> src/lib/bundle.js"
|
||||
|
||||
benign sqla-text-method \
|
||||
"printf '%s\n' 'import sqlalchemy' 'label = project.text(path)' > src/lib/db.py"
|
||||
benign sqla-resp-text \
|
||||
"printf '%s\n' 'import sqlalchemy' 'body = resp.text(x)' > src/lib/db.py"
|
||||
benign shell-db-argv-spawn \
|
||||
"printf '%s\n' 'spawn(\"psql\", [\"-f\", file], {env});' > src/lib/backup.ts"
|
||||
benign shell-db-argv-python \
|
||||
"printf '%s\n' 'subprocess.run([\"psql\", f\"--dbname={url}\"])' > src/lib/backup.py"
|
||||
benign shell-db-env-ref \
|
||||
"printf '%s\n' 'execSync(\"psql \$DATABASE_URL -f schema.sql\");' > src/lib/backup.ts"
|
||||
benign ruby-where-placeholder \
|
||||
"printf '%s\n' 'User.where(\"name = ?\", name)' 'User.where(name: value)' > src/lib/users.rb"
|
||||
benign console-public-minified \
|
||||
"mkdir -p public/js; printf '%s\n' 'console.log(user);' > public/js/app.min.js"
|
||||
benign console-plain-string \
|
||||
"printf '%s\n' 'console.log(\"ready\");' >> $TSX"
|
||||
benign console-string-data \
|
||||
"printf '%s\n' 'console.log(\"loading data\");' >> $TSX"
|
||||
benign console-server-file \
|
||||
"printf '%s\n' 'console.log(\"saved\", session);' >> $API"
|
||||
benign logger-stack \
|
||||
"printf '%s\n' 'logger.error(\`notes failed \${res.statusCode}\`, err.stack);' >> $API"
|
||||
benign client-console-stack \
|
||||
"printf '%s\n' 'console.warn(\"load failed\", err.stack);' >> $TSX"
|
||||
benign vite-hidden-sourcemap \
|
||||
"printf '%s\n' 'export default { build: { sourcemap: \"hidden\" } };' > vite.config.ts"
|
||||
benign vendored-map \
|
||||
"mkdir -p static/css; printf '%s\n' '{\"version\":3,\"mappings\":\"AAAA\"}' > static/css/bootstrap.min.css.map"
|
||||
benign level-map \
|
||||
"mkdir -p public/levels; printf '%s\n' 'tiles 10x10' > public/levels/1.map"
|
||||
benign debug-from-env \
|
||||
"printf '%s\n' 'DEBUG = os.environ.get(\"DEBUG\") == \"1\"' > src/settings.py"
|
||||
benign debug-local-settings \
|
||||
"printf '%s\n' 'DEBUG = True' > src/settings_local.py"
|
||||
benign debug-lowercase-elsewhere \
|
||||
"printf '%s\n' ' debug = True' > src/lib/tools.py"
|
||||
benign errorhandler-dev-guard \
|
||||
"printf '%s\n' 'if (process.env.NODE_ENV === \"development\") app.use(errorhandler());' >> $API"
|
||||
benign errorhandler-dev-guard-multiline \
|
||||
"printf '%s\n' 'if (process.env.NODE_ENV === \"development\") {' ' app.use(errorhandler());' '}' >> $API"
|
||||
benign flask-config-class \
|
||||
"printf '%s\n' 'class DevelopmentConfig(Config):' ' DEBUG = True' > src/config.py"
|
||||
benign error-generic-message \
|
||||
"printf '%s\n' 'export function onFail() { return Response.json({ error: \"internal error\" }, { status: 500 }); }' >> $API"
|
||||
benign ts-type-token \
|
||||
"printf '%s\n' 'export async function getServerSideProps() { return { props: {} }; }' 'type Session = { token: string; };' > src/pages/account.tsx"
|
||||
benign no-semicolon-type \
|
||||
"printf '%s\n' 'export async function getServerSideProps() { return { props: {} }; }' 'interface Props {' ' token: string' '}' > src/pages/account.tsx"
|
||||
benign prisma-multiline-select \
|
||||
"printf '%s\n' 'const u = await prisma.user.findUnique({' ' where: { id },' ' select: { id: true },' '});' >> $API"
|
||||
benign csrf-hidden-input \
|
||||
"printf '%s\n' '<input type=\"hidden\" name=\"csrf_secret\" value={csrf} />' >> $TSX"
|
||||
benign csrf-data-attr \
|
||||
"printf '%s\n' '<form data-csrf-secret={csrf}>x</form>' >> $TSX"
|
||||
# A committed .env.development trips the api domain's API-ENV-NOT-IGNORED by
|
||||
# design (the fixture's .gitignore lists .env only), so this lock is scoped
|
||||
# to the exposure domain: a dev env file must raise no EXP finding.
|
||||
cp -R "$GOOD" "$WORK/env-dev"
|
||||
printf '%s\n' 'APP_DEBUG=true' 'GENERATE_SOURCEMAP=true' > "$WORK/env-dev/.env.development"
|
||||
out=$(scan --domain exposure "$WORK/env-dev")
|
||||
check "a dev env file raises no exposure finding" \
|
||||
"$(printf '%s\n' "$out" | grep -c ' 0 FAIL, 0 WARN')" 1
|
||||
|
||||
echo "== transactional versus marketing senders"
|
||||
solo tx-only src/contact.ts 'import nodemailer from "nodemailer";'
|
||||
check "transactional-only mail exits 0" "$LAST_RC" 0
|
||||
@@ -253,37 +418,37 @@ check "a subscribers table makes the same senders fail" \
|
||||
"$(has FAIL MSG-NO-CONSENT-RECORD)" yes
|
||||
|
||||
echo "== check modes (contract oracle and re-pass baseline)"
|
||||
IMG="A11Y-IMG-ALT:$TSX"
|
||||
cp -R "$GOOD" "$WORK/cm"; edit "$WORK/cm/$TSX" 's/ alt="Company logo"//'
|
||||
out=$(scan "$WORK/cm" --assert-absent "$IMG"); rc=$?
|
||||
INJ="INJ-SQL-CONCAT:$API"
|
||||
cp -R "$GOOD" "$WORK/cm"; printf '%s\n' 'const q = `select id from notes where owner = ${owner}`;' >> "$WORK/cm/$API"
|
||||
out=$(scan "$WORK/cm" --assert-absent "$INJ"); rc=$?
|
||||
check "positive control: the oracle fails while the hit is there" "$rc" 1
|
||||
check "a failing oracle never prints the marker" \
|
||||
"$(printf '%s\n' "$out" | grep -c GUARDRAILS-CLEAR)" 0
|
||||
out=$(scan "$GOOD" --assert-absent "$IMG"); rc=$?
|
||||
out=$(scan "$GOOD" --assert-absent "$INJ"); rc=$?
|
||||
check "the oracle passes once the hit is gone" "$rc" 0
|
||||
check "a passing oracle prints the marker" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^GUARDRAILS-CLEAR 1$')" 1
|
||||
out=$(scan "$GOOD" --domain api --assert-absent "$IMG"); rc=$?
|
||||
out=$(scan "$GOOD" --domain api --assert-absent "$INJ"); rc=$?
|
||||
check "an unscanned domain proves nothing" "$rc" 1
|
||||
check "the control failure is named" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^ CONTROL ')" 1
|
||||
mkdir "$WORK/cm-empty"
|
||||
scan "$WORK/cm-empty" --assert-absent "$IMG" >/dev/null
|
||||
scan "$WORK/cm-empty" --assert-absent "$INJ" >/dev/null
|
||||
check "an empty tree proves nothing" "$?" 1
|
||||
scan "$GOOD" --assert-absent HOST-SPEND-CAP:. >/dev/null 2>&1
|
||||
check "a MANUAL rule cannot be asserted (exit 2)" "$?" 2
|
||||
scan "$GOOD" --assert-absent A11Y-IMG-ALT >/dev/null 2>&1
|
||||
scan "$GOOD" --assert-absent INJ-SQL-CONCAT >/dev/null 2>&1
|
||||
check "an item without a path is a usage error" "$?" 2
|
||||
scan "$WORK/cm" --json > "$WORK/cm-before.json"
|
||||
out=$(scan "$GOOD" --baseline "$WORK/cm-before.json"); rc=$?
|
||||
check "baseline lists the fixed hit" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^ FIXED A11Y-IMG-ALT ')" 1
|
||||
"$(printf '%s\n' "$out" | grep -c '^ FIXED INJ-SQL-CONCAT ')" 1
|
||||
check "baseline with no new hit exits 0 with the marker" \
|
||||
"$rc:$(printf '%s\n' "$out" | grep -c '^GUARDRAILS-NO-NEW$')" "0:1"
|
||||
scan "$GOOD" --json > "$WORK/clean-before.json"
|
||||
out=$(scan "$WORK/cm" --baseline "$WORK/clean-before.json"); rc=$?
|
||||
check "baseline lists a new hit" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^ NEW A11Y-IMG-ALT ')" 1
|
||||
"$(printf '%s\n' "$out" | grep -c '^ NEW INJ-SQL-CONCAT ')" 1
|
||||
check "baseline with a new hit exits 1 without the marker" \
|
||||
"$rc:$(printf '%s\n' "$out" | grep -c GUARDRAILS-NO-NEW)" "1:0"
|
||||
printf 'not json' > "$WORK/bad.json"
|
||||
@@ -295,12 +460,12 @@ contract() {
|
||||
cat > "$2" <<EOF
|
||||
# CONTRACT — guardrails-oracle-test
|
||||
## ACCEPTANCE CRITERIA
|
||||
1. every image in the contact form has an alt
|
||||
CHECK: python3 -B '$SCAN' '$1' --assert-absent '$IMG'
|
||||
1. no SQL built from input in the notes route
|
||||
CHECK: python3 -B '$SCAN' '$1' --assert-absent '$INJ'
|
||||
EXPECT: GUARDRAILS-CLEAR
|
||||
EVIDENCE: pending
|
||||
## FILE SCOPE
|
||||
$TSX
|
||||
$API
|
||||
EOF
|
||||
}
|
||||
contract "$WORK/cm" "$WORK/c-unfixed.md"
|
||||
@@ -315,17 +480,18 @@ check "gates.sh writes the evidence back" \
|
||||
echo "== cli"
|
||||
scan "$WORK/does-not-exist" >/dev/null 2>&1; check "bad path exits 2" "$?" 2
|
||||
scan --domain nope "$GOOD" >/dev/null 2>&1; check "bad domain exits 2" "$?" 2
|
||||
scan --domain a11y "$GOOD" >/dev/null 2>&1; check "a11y is no longer a guardrails domain (exit 2)" "$?" 2
|
||||
check "json is valid and counts FAIL" \
|
||||
"$(scan --json "$GOOD" | python3 -B -c 'import json,sys; print(json.load(sys.stdin)["summary"]["FAIL"])')" 0
|
||||
out=$(scan --domain a11y "$GOOD")
|
||||
check "domain filter keeps a11y" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^\[a11y\]')" 1
|
||||
out=$(scan --domain injection "$GOOD")
|
||||
check "domain filter keeps injection" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^\[injection\]')" 1
|
||||
check "domain filter drops supabase" \
|
||||
"$(printf '%s\n' "$out" | grep -c '^\[supabase\]')" 0
|
||||
cp -R "$GOOD" "$WORK/excl"
|
||||
edit "$WORK/excl/$TSX" 's/ alt="Company logo"//'
|
||||
printf '%s\n' 'const q = `select id from notes where owner = ${owner}`;' >> "$WORK/excl/$API"
|
||||
scan "$WORK/excl" >/dev/null 2>&1; check "mutated copy fails" "$?" 1
|
||||
scan --exclude src/components "$WORK/excl" >/dev/null 2>&1
|
||||
scan --exclude src/pages "$WORK/excl" >/dev/null 2>&1
|
||||
check "--exclude drops the finding" "$?" 0
|
||||
mkdir "$WORK/empty"
|
||||
out=$(scan "$WORK/empty")
|
||||
@@ -336,6 +502,33 @@ out=$(scan "$WORK/linked")
|
||||
check "symlinked directory is not followed" \
|
||||
"$(printf '%s\n' "$out" | grep -c '(0 files)')" 1
|
||||
|
||||
echo "== regex timing"
|
||||
FAST="$(cd "$ROOT" && python3 -B - <<'PY'
|
||||
import importlib.util, sys, time
|
||||
sys.path.insert(0, "skills/guardrails/scripts")
|
||||
from checks import common, exposure
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"probe", "skills/guardrails/scripts/probe.py")
|
||||
probe = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(probe)
|
||||
cases = [
|
||||
(exposure.DATA_ATTR, "data-secret" * 20000),
|
||||
(common.MARKUP_COMMENT, "<!--" * 50000),
|
||||
(common.SQL_COMMENT, "/*" * 100000),
|
||||
(probe.SCRIPT_SRC, "<script " * 25000),
|
||||
(probe.TRACE_MARKERS, b"at a ( " * 28000),
|
||||
]
|
||||
slow = 0
|
||||
for pattern, text in cases:
|
||||
start = time.perf_counter()
|
||||
pattern.search(text)
|
||||
slow += time.perf_counter() - start >= 1.0
|
||||
print("REGEX-FAST" if not slow else "REGEX-SLOW")
|
||||
PY
|
||||
)"
|
||||
check "adversarial inputs finish each regex under one second" \
|
||||
"$(printf '%s\n' "$FAST" | grep -c 'REGEX-FAST')" 1
|
||||
|
||||
echo "---"
|
||||
echo "passed: $PASS failed: $FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
@@ -15,6 +15,7 @@ BSK="$REPO/skills/bugfix/SKILL.md"
|
||||
HOT="$REPO/agents/hotfixer.md"
|
||||
HSK="$REPO/skills/hotfix/SKILL.md"
|
||||
GSK="$REPO/skills/guardrails/SKILL.md"
|
||||
ASK="$REPO/skills/a11y/SKILL.md"
|
||||
HSKL="$REPO/skills/hotfix/SKILL.md"
|
||||
PASS=0; FAIL=0
|
||||
|
||||
@@ -79,6 +80,15 @@ tf "guardrails positive control" "$GSK" "Positive control"
|
||||
tf "guardrails approval gate" "$GSK" "Nothing is applied without the user's explicit acceptance"
|
||||
tf "guardrails re-pass baseline" "$GSK" "GUARDRAILS-NO-NEW"
|
||||
|
||||
echo "── skills/a11y/SKILL.md (fix loop reuses the bugfix circuit) ──"
|
||||
tf "a11y contract include" "$ASK" "lib/contract-interview.md"
|
||||
tf "a11y uses shared include" "$ASK" "lib/verify-secure-loop.md"
|
||||
tf "a11y dispatches bugfixer" "$ASK" 'subagent_type="bugfixer"'
|
||||
tf "a11y scanner is the oracle" "$ASK" "EXPECT: A11Y-CLEAR"
|
||||
tf "a11y positive control" "$ASK" "Positive control"
|
||||
tf "a11y approval gate" "$ASK" "Nothing is applied without the user's explicit acceptance"
|
||||
tf "a11y re-pass baseline" "$ASK" "A11Y-NO-NEW"
|
||||
|
||||
echo "── agents/bugfixer.md (bugfix executor — sonnet, no Agent) ──"
|
||||
tn "bugfixer lacks Agent tool" "$BUG" "Agent"
|
||||
tf "bugfixer model sonnet" "$BUG" "model: sonnet"
|
||||
|
||||
@@ -9,8 +9,8 @@ has() { if grep -qF "$2" "$R/$1"; then ok; else ko "$1 missing: $2"; fi; }
|
||||
lacks() { if grep -qF "$2" "$R/$1"; then ko "$1 must NOT contain: $2"; else ok; fi; }
|
||||
fm_lacks() { if awk 'NR<=10' "$R/$1" | grep -qF "$2"; then ko "$1 frontmatter must NOT contain: $2"; else ok; fi; }
|
||||
|
||||
# 1) gate wired in the 16 reflection skills (orchestrators, /analyze, /guardrails)
|
||||
for s in ship-feature init-project feat bugfix onboard seo geo web-validate harden audit-delta tour code-clean hotfix client-handover analyze guardrails; do
|
||||
# 1) gate wired in the 17 reflection skills (orchestrators, /analyze, /guardrails, /a11y)
|
||||
for s in ship-feature init-project feat bugfix onboard seo geo web-validate harden audit-delta tour code-clean hotfix client-handover analyze guardrails a11y; do
|
||||
has "skills/$s/SKILL.md" 'lib/model-gate.md'
|
||||
done
|
||||
# 2) gate NOT wired in the pure-execution/read-only skills (exclusion list)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Verify + secure loop — shared orchestrator include (feat, bugfix, guardrails)
|
||||
# Verify + secure loop — shared orchestrator include (feat, bugfix, guardrails, a11y)
|
||||
|
||||
Runs in the ORCHESTRATOR MAIN LOOP after the dev step completes. Turns a
|
||||
finished diff into a verified, security-cleared change through two fresh
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
"refactor": "reflect",
|
||||
"explain-diff": "reflect",
|
||||
"guardrails": "reflect",
|
||||
"a11y": "reflect",
|
||||
"web-validate": "reflect",
|
||||
"harden": "reflect",
|
||||
"seo": "reflect",
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
paths: ["**/*.tsx", "**/*.jsx", "**/*.vue", "**/*.svelte", "**/*.astro", "**/*.html", "**/*.css", "**/*.scss"]
|
||||
---
|
||||
|
||||
# Accessibility baseline (audit and fix: `/a11y`)
|
||||
|
||||
- Everything reachable and usable by keyboard, focus always visible.
|
||||
`:focus-visible` styled, never `outline: none` without a replacement.
|
||||
- Every image has an `alt` (empty when decorative). Every field has a label;
|
||||
a placeholder is not a label.
|
||||
@@ -1,4 +1,4 @@
|
||||
# Secure by default: five domains and every API
|
||||
# Secure by default: six domains and every API
|
||||
|
||||
Scope: any project that has a public surface, an API, a database, messaging,
|
||||
a cloud function or a UI. Applies at design, scaffolding, implementation and
|
||||
@@ -25,13 +25,20 @@ never claimed done: write it as a manual step in the project's deploy notes.
|
||||
- Hard spend cap if the host offers one. Otherwise a budget alert plus a
|
||||
written kill-switch step.
|
||||
|
||||
## 2. Accessibility
|
||||
- Everything reachable and usable by keyboard, focus always visible.
|
||||
`:focus-visible` styled, never `outline: none` without a replacement.
|
||||
- Every image has an `alt` (empty when decorative). Every field has a label;
|
||||
a placeholder is not a label.
|
||||
## 2. Injection
|
||||
- Raw escapes (`$queryRawUnsafe`, `knex.raw`, `text()`, `.raw()`) take
|
||||
bound values only; dynamic SQL in a function goes through `format()`
|
||||
with `%I` / `%L` and `USING`.
|
||||
- A filter object never comes straight from the request: allowlist the
|
||||
fields, cast the values. No shell command carries input into a DB tool.
|
||||
|
||||
## 3. Supabase
|
||||
## 3. Exposure (what the browser can see)
|
||||
- No data in the browser console, no source map in production, no debug
|
||||
flag in a committed config.
|
||||
- Hydrated state, `data-*` attributes, hidden fields and shipped HTML
|
||||
comments carry no token, hash, key or secret.
|
||||
|
||||
## 4. Supabase
|
||||
- RLS enabled on every table, in the migration that creates it.
|
||||
- Policies limited to the owner: `(select auth.uid())` per operation, role
|
||||
`authenticated`. No `using (true)` on writes, no anon write.
|
||||
@@ -40,13 +47,13 @@ never claimed done: write it as a manual step in the project's deploy notes.
|
||||
- Views `security_invoker`. `security definer` functions pin `search_path`
|
||||
and revoke execute from anon. Buckets private by default.
|
||||
|
||||
## 4. SMS and email
|
||||
## 5. SMS and email
|
||||
- Prior consent recorded per contact: who, when, channel, source, wording.
|
||||
No send without a consent row; check the suppression list before each send.
|
||||
- Every email has an unsubscribe link and `List-Unsubscribe`. Every marketing
|
||||
SMS says STOP, and a STOP reply is processed and stored automatically.
|
||||
|
||||
## 5. Cloud functions
|
||||
## 6. Cloud functions
|
||||
- No function re-triggers itself: never write to the resource that fires it,
|
||||
never invoke itself. If unavoidable, guard with an idempotency flag.
|
||||
- Max instances (or reserved concurrency) and a timeout on every function.
|
||||
|
||||
@@ -27,7 +27,7 @@ paths: ["**/*.html", "**/*.astro", "**/*.css", "**/*.scss", "**/*.tsx", "**/*.js
|
||||
- Motion: transform and opacity only; feedback under 200 ms, ease-out on
|
||||
entrances, never from scale(0); `will-change` only during an active
|
||||
animation; pause loops off-screen; honor `prefers-reduced-motion`.
|
||||
- Touch targets 44 px minimum; visible `:focus-visible` ring; status never
|
||||
- Touch targets 44 px minimum; keyboard and focus per `rules/a11y.md`; status never
|
||||
by color alone, add text or an icon.
|
||||
- Errors next to the field; empty state = one clear action; destructive
|
||||
action confirmed first.
|
||||
@@ -36,7 +36,7 @@ paths: ["**/*.html", "**/*.astro", "**/*.css", "**/*.scss", "**/*.tsx", "**/*.js
|
||||
## Before declaring a public site done
|
||||
Check: custom 404 · call to action in the first viewport · per-page
|
||||
title + description · share/OG image · favicons · robots.txt · sitemap ·
|
||||
alt text on images · layout tested at 375 px · loading states · form
|
||||
accessibility baseline (`rules/a11y.md`) · layout tested at 375 px · loading states · form
|
||||
error messages · confirmation page · real legal mentions · cookie banner
|
||||
with a working refuse option · audience measurement · contact address ·
|
||||
compressed images.
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
---
|
||||
name: a11y
|
||||
effort: high
|
||||
description: 'Use when a web project needs its accessibility baseline checked and fixed: everything reachable by keyboard with a visible focus, an alt on every image, a label on every field. Full WCAG conformance (axe, pa11y, W3C) → /web-validate; security guardrails → /guardrails. Deterministic scanner (A11Y-* rules: img alt, field label, click without keyboard, focus outline removed, positive tabindex), judgment, a Tab-only walk of the main flow on --live (through /browse, else marked not done), report .claude/audits/A11Y.md, then fixes proposed with the alt and label wording as visible choices, applied only on acceptance (bugfixer executor, fresh verifier and security gates, the scanner as oracle) and re-scanned to prove each one. Triggers: "a11y", "accessibilité", "accessibility basics", "clavier", "focus visible", "alt manquant", "label sur les champs", "tab order", "corrige l''accessibilité".'
|
||||
argument-hint: '[project path] [--exclude paths] [--live <url you own>] [--report-only]'
|
||||
---
|
||||
|
||||
# /a11y
|
||||
|
||||
Checks a project's accessibility baseline (`rules/a11y.md`), then fixes what
|
||||
the user accepts and proves each fix. A scanner reads the tree as data and
|
||||
finds what text can prove: a missing alt, an unlabeled field, a click with no
|
||||
keyboard path, a focus outline removed, a positive tabindex. This skill judges
|
||||
the hits, walks the main flow with the keyboard when a browser is available,
|
||||
proposes fixes, applies the accepted ones and scans again until every accepted
|
||||
fix is proven.
|
||||
|
||||
The scanner proves absence of a baseline, never presence of accessibility. A
|
||||
clean scan means "no static finding", and the report says exactly that. Full
|
||||
WCAG conformance (contrast, structure, ARIA semantics, axe or pa11y runs) is
|
||||
`/web-validate`'s job.
|
||||
|
||||
## MODEL GATE (blocking, before any other step)
|
||||
|
||||
Run `$HOME/.claude/lib/model-gate.md`. Judging hits and writing alt and label
|
||||
text requires Fable or Opus. Verdict `small` → STOP: the gate prints the
|
||||
remedy. ROUTING: follow `$HOME/.claude/lib/effort-shift.md` (phases via
|
||||
`mcp__model-router__route`); each step below names its phase.
|
||||
|
||||
## STEP 1: Scope
|
||||
|
||||
Work in the project the user names, else the current directory. Say in one
|
||||
line what you will scan. `--report-only` stops after STEP 5: audit, no fix.
|
||||
|
||||
## STEP 2: Run the scanner
|
||||
|
||||
```
|
||||
python3 -B "$HOME/.claude/skills/a11y/scripts/scan.py" <path>
|
||||
```
|
||||
|
||||
Add `--exclude a/b,c` to skip copies or vendored code, `--json` for machine
|
||||
output. Exit 0 means no FAIL, 1 means at least one, 2 is a usage error. It
|
||||
never executes project code. Severities: **FAIL**, the baseline is provably
|
||||
missing; **WARN**, a pattern that is often wrong, judgment needed.
|
||||
|
||||
## STEP 3: Judge every FAIL and WARN
|
||||
|
||||
Read the file around each line. Label it CONFIRMED, FALSE POSITIVE (say why)
|
||||
or ACCEPTED RISK (the user decides, never you). The scanner already
|
||||
stays silent on a decorative `alt=""`, a `role="presentation"` overlay and an
|
||||
outline swapped for a border or ring; the hits that are often false are a
|
||||
label wired through `aria-labelledby` in another file and an outline removal
|
||||
that a `:focus-visible` rule elsewhere covers (WARN); `references/checks.md` lists the blind
|
||||
spots. Check them before calling a hit false.
|
||||
|
||||
## STEP 4: Keyboard walk (on `--live`, read-only)
|
||||
|
||||
With a dev server the user names, walk the main flow with Tab only through
|
||||
`/browse`: every control reached in a sensible order, the focus visible at
|
||||
each stop, Enter and Space working on what looks clickable, Escape closing
|
||||
what opened. Record each stop that fails with the page and the element.
|
||||
Without a browser tool, or without `--live`, the report marks the walk
|
||||
"not done": a static scan cannot see a keyboard trap, a focus order or a
|
||||
modal that loses focus.
|
||||
|
||||
## STEP 5: Report
|
||||
|
||||
Write `.claude/audits/A11Y.md`: one table with status PASS, FAIL, WARN or
|
||||
N/A per rule, the evidence, the fix in one line, and the keyboard walk's
|
||||
result (done, with its stops, or not done). PASS means "no static finding".
|
||||
Keep it short; no filler sections. `--report-only`, or nothing CONFIRMED:
|
||||
reply with counts, the FAILs with file:line and the walk's stops, then stop.
|
||||
|
||||
## STEP 6: Propose fixes
|
||||
|
||||
`mcp__model-router__route(phase="plan")`: wording is the deepest thinking in
|
||||
this run, it goes to the plan row.
|
||||
|
||||
One proposal per CONFIRMED finding, grouped by rule and file; merge pairs
|
||||
that one change closes (one `:focus-visible` rule closes every outline
|
||||
removal in a stylesheet). FALSE POSITIVE and ACCEPTED RISK get no proposal.
|
||||
Each proposal:
|
||||
|
||||
- **number, rule, file(s)**, and the problem in one line;
|
||||
- **the fix**, concrete: file:line and the change. A missing alt gets a
|
||||
description of what the image shows, or `alt=""` when it is decorative; an
|
||||
unlabeled field gets a `label for`, a wrapping label or `aria-label`; a
|
||||
clickable `div` becomes a `button`, or gains `role`, `tabindex` and a key
|
||||
handler; a removed outline gets a `:focus-visible` style;
|
||||
- **choices the user sees**: the alt text and the label wording, each with
|
||||
your proposed value, named so the user can change it. These are content,
|
||||
never invented silently: they ship only with the user's acceptance;
|
||||
- **risk**: what it can break (`button` reset styles, a changed tab order).
|
||||
`DECISION` when no wording is defensible (an image you cannot describe);
|
||||
- **proof**: the scanner pairs that must disappear (`RULE:path`), and the
|
||||
walk stop that must pass when `--live` ran.
|
||||
|
||||
Save the proposals to `.claude/tasks/plans/<YYYY-MM-DD>-a11y-<HHMM>.md` and
|
||||
append them to the report. In the reply, show them as a numbered list, one or
|
||||
two lines each, DECISION marked.
|
||||
|
||||
## STEP 7: Approval (gate, ends the turn)
|
||||
|
||||
Nothing is applied without the user's explicit acceptance. Ask once, then
|
||||
stop the turn:
|
||||
|
||||
```
|
||||
Which fixes do I apply? "all" (every proposal except DECISION ones),
|
||||
numbers ("1,3,5-7"), "none", or an amendment ("2 with the alt 'Team photo'").
|
||||
A DECISION proposal needs its number plus your wording.
|
||||
```
|
||||
|
||||
On resume, `mcp__model-router__route(phase="reflect")`. "none" → stop,
|
||||
proposals stay in the report. An amendment rewrites that proposal in the plan
|
||||
file before anything else. Accepted set empty → stop.
|
||||
|
||||
## STEP 8: Apply
|
||||
|
||||
1. **Branch.** Not a git repository → stop: fixes need a diff to review.
|
||||
On `main`/`develop`, `bash ~/.claude/lib/gitflow.sh start bugfix
|
||||
a11y-<YYYY-MM-DD>`; on a working branch, stay. Never `finish`.
|
||||
2. **Baseline**, before any edit:
|
||||
`python3 -B <scan.py> <root> --json > .claude/audits/.a11y-baseline.json`.
|
||||
A derived file: never staged, never committed.
|
||||
3. **Contract** per `$HOME/.claude/lib/contract-interview.md` (STEP 4
|
||||
template, `flow: a11y`). REQUEST = the user's acceptance verbatim plus the
|
||||
accepted proposals. One criterion per accepted proposal, its oracle the
|
||||
scanner itself:
|
||||
```
|
||||
1. <proposal 1 in one line>
|
||||
CHECK: python3 -B "$HOME/.claude/skills/a11y/scripts/scan.py" '<abs root>' --assert-absent 'RULE:path,RULE:path'
|
||||
EXPECT: A11Y-CLEAR
|
||||
EVIDENCE: pending
|
||||
```
|
||||
Add one criterion for the project suite when one exists
|
||||
(`CHECK: <test command> && echo TESTS-GREEN`, `EXPECT: TESTS-GREEN`). The
|
||||
keyboard walk is a criterion without CHECK: STEP 9 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.
|
||||
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.
|
||||
5. **Dispatch the executor**, one fresh `bugfixer` for the accepted set
|
||||
(batches of 8 proposals at most, one after the other on the same branch):
|
||||
```
|
||||
mcp__model-router__route(phase="orchestrate") # send with the Agent call
|
||||
Agent(subagent_type="bugfixer")
|
||||
prompt: "CONTRACT: <path>
|
||||
DIAGNOSIS: <each accepted finding: rule, file:line, evidence>
|
||||
FIX PLAN: <the accepted proposals verbatim, with the user's wording; the
|
||||
regression check of each is its contract oracle, plus the project test
|
||||
the proposal names>
|
||||
BRANCH: <current branch>
|
||||
Apply to the letter. No commit, no branch ops, no security dispatch.
|
||||
Finish with the BUGFIX-EXEC REPORT."
|
||||
```
|
||||
`NEED-DECISION` routes per MID-RUN CLARIFICATION of the contract include:
|
||||
a wording, visible or scope question goes to the user verbatim.
|
||||
`BLOCKED` → surface it, stop.
|
||||
6. **Gates** per `$HOME/.claude/lib/verify-secure-loop.md`, `CONTRACT` the
|
||||
path above, `DIFF` the executor's working-tree diff, `TEST` the suite.
|
||||
GATE 0 runs every scanner oracle (the per-fix proof), GATE 1 a fresh
|
||||
verifier, GATE 2 a fresh security-auditor. Loop caps and escalation are
|
||||
the include's; loop decisions stay in this main loop.
|
||||
|
||||
## STEP 9: Re-pass (prove it all)
|
||||
|
||||
`mcp__model-router__route(phase="reflect")`. The gates proved each accepted
|
||||
fix on its own; this pass proves the whole tree.
|
||||
|
||||
1. Full scan against the baseline:
|
||||
```
|
||||
python3 -B <scan.py> <root> --baseline .claude/audits/.a11y-baseline.json
|
||||
```
|
||||
Every accepted pair must show `FIXED`, and the run must end on
|
||||
`A11Y-NO-NEW` (exit 0). A `NEW` hit is a regression the fix made.
|
||||
2. Live: when STEP 4 ran, walk the same flow again once the user has reloaded
|
||||
the dev server and says go. Each stop a proposal named must now pass.
|
||||
3. Add an "after" column to `.claude/audits/A11Y.md`: proposal, before,
|
||||
after, evidence.
|
||||
|
||||
Anything not fixed, or a NEW hit → one more round from STEP 6, limited to
|
||||
those items. Two rounds at most: after the second, stop with the residuals
|
||||
open and say so plainly. Never report a fix the re-pass did not prove.
|
||||
|
||||
## STEP 10: Commit and hand over
|
||||
|
||||
1. **Commit gate.** Show files, `git diff --stat` and the message, wait for
|
||||
the user's go:
|
||||
```
|
||||
A11Y: READY TO COMMIT
|
||||
FILES : <list>
|
||||
MESSAGE : fix(a11y): <rules fixed, one line>
|
||||
```
|
||||
Then `git add <files touched>` (never `-A`, never the baseline file) and
|
||||
commit, project convention else 50 words at most.
|
||||
2. `mcp__model-router__route(phase="apply")` for the tail. Reply with: fixed
|
||||
and proven (proposal, rule, file), still open and why, the walk's result,
|
||||
the branch name. Merge waits for the user's explicit signal.
|
||||
3. Offer to capitalize a reusable lesson (a false-positive class, a fix
|
||||
pattern), entry pre-filled, written only on approval.
|
||||
@@ -0,0 +1,44 @@
|
||||
# Accessibility checks
|
||||
|
||||
Rule ids the scanner emits, what each proves, and the fix. Severity is the
|
||||
default; a judged hit can be a false positive.
|
||||
|
||||
| Rule | Sev | Catches | Fix |
|
||||
|---|---|---|---|
|
||||
| A11Y-IMG-ALT | FAIL | `img` or `Image` without `alt` | describe it, or `alt=""` if decorative |
|
||||
| A11Y-FIELD-LABEL | FAIL | native input, select, textarea with no label | `label for`, wrapping label or `aria-label` |
|
||||
| A11Y-CLICK-NO-KEYBOARD | FAIL | click handler on a div or span lacking role, tabindex or key handler | use a `button` |
|
||||
| A11Y-FOCUS-OUTLINE | FAIL / WARN | focus outline removed; WARN when a `:focus-visible` style exists elsewhere | style `:focus-visible` instead |
|
||||
| A11Y-TABINDEX-POSITIVE | WARN | `tabindex` above 0 | use 0 or -1 and fix the DOM order |
|
||||
|
||||
## Blind spots
|
||||
|
||||
The scanner is regex over markup and styles. It cannot see:
|
||||
|
||||
- keyboard traps, focus order, a modal that keeps or loses focus, color
|
||||
contrast: the `--live` walk covers the first three, `/web-validate` the
|
||||
fourth
|
||||
- a label wired through `aria-labelledby` to an element in another file
|
||||
- components whose markup is built at runtime, minified bundles, anything
|
||||
over 1 MB
|
||||
- `.astro` files for the click rule (never flagged)
|
||||
|
||||
By design the scanner ignores: fields that are never rendered (`hidden`,
|
||||
`display: none`), click handlers that only stop propagation or sit on
|
||||
`role="presentation"`, focus styles that swap the outline for a border or
|
||||
shadow, and `img` tags inside comments.
|
||||
|
||||
## Fix loop: oracles and re-pass
|
||||
|
||||
Every accepted fix is proven by the scanner itself, never by the executor's
|
||||
word. Two check modes replace the report and its exit code:
|
||||
|
||||
| Mode | Passes when | Marker | Used by |
|
||||
|---|---|---|---|
|
||||
| `--assert-absent RULE:path,...` | none of these FAIL/WARN pairs remains, the domain was scanned, the tree is not empty | `A11Y-CLEAR <n>` | a contract `CHECK:` run by `lib/gates.sh` (GATE 0) |
|
||||
| `--baseline before.json` | no FAIL/WARN hit appeared since the earlier `--json` run | `A11Y-NO-NEW` | STEP 9 re-pass |
|
||||
|
||||
Pairs match on rule and file, not line: a fix moves lines. An empty tree
|
||||
fails the assertion, because absence there proves nothing. Run every oracle
|
||||
once before the fix: it must fail. The baseline lists `FIXED` and `NEW`
|
||||
pairs with their hit counts; a `NEW` hit after a fix is a regression.
|
||||
@@ -2,7 +2,7 @@
|
||||
import re
|
||||
from collections import namedtuple
|
||||
|
||||
from .common import Rule, blank_markup_comments
|
||||
from checks.common import Rule, blank_markup_comments
|
||||
|
||||
DOMAIN = "a11y"
|
||||
MARKUP_EXTS = (".html", ".htm", ".jsx", ".tsx", ".vue", ".svelte", ".astro")
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Static accessibility scan: keyboard, visible focus, alt text, labels.
|
||||
|
||||
Runs the guardrails scan engine (skills/guardrails/scripts/scanner.py) on
|
||||
the a11y catalogue. Same options and exit codes; markers A11Y-CLEAR and
|
||||
A11Y-NO-NEW.
|
||||
"""
|
||||
import importlib
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ENGINE = Path(__file__).resolve().parents[2] / "guardrails" / "scripts"
|
||||
if not ENGINE.is_dir():
|
||||
print(f"usage error: scan engine missing at {ENGINE} "
|
||||
"(the guardrails skill must be installed)", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
sys.path.insert(0, str(ENGINE))
|
||||
|
||||
scanner = importlib.import_module("scanner")
|
||||
a11y_checks = importlib.import_module("a11y_checks")
|
||||
|
||||
CATALOGUE = scanner.Catalogue(
|
||||
name="a11y",
|
||||
domains={"a11y": a11y_checks},
|
||||
rule_domains={"A11Y": "a11y"},
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(scanner.main(sys.argv[1:], CATALOGUE))
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{"id": 1, "prompt": "vérifie l'accessibilité de base de ~/Documents/faunosteo : clavier, alt, labels", "expected": "Runs the a11y scanner on the path, reads each A11Y FAIL and WARN in context, marks the keyboard walk not done (no --live), writes .claude/audits/A11Y.md, proposes fixes with alt and label wording as visible choices, stops for approval"},
|
||||
{"id": 2, "prompt": "il manque des alt sur les images du site, corrige", "expected": "Scans, confirms each A11Y-IMG-ALT hit, proposes one alt text per image (or alt=\"\" for decorative ones) as a named choice, applies only after acceptance on a bugfix branch with --assert-absent oracles, re-scans against the baseline"},
|
||||
{"id": 3, "prompt": "Walk my app at http://localhost:3000 with the keyboard only and tell me where focus gets lost", "expected": "Static scan first, then the Tab walk through /browse on the named localhost target, records each stop with no visible focus or unreachable control, reports them next to the static findings, fixes nothing without approval"},
|
||||
{"id": 4, "prompt": "est-ce que mon site passe les critères WCAG AA ?", "expected": "Routes to /web-validate for WCAG conformance; runs /a11y only if the user asks for the keyboard/alt/label baseline"},
|
||||
{"id": 5, "prompt": "a11y --report-only sur ce projet", "expected": "Scan and judgment only, report written, counts and file:line in the reply, no proposal, no branch, no edit"}
|
||||
]
|
||||
+20
-13
@@ -1,8 +1,8 @@
|
||||
---
|
||||
name: guardrails
|
||||
effort: high
|
||||
description: 'Use when auditing a project against the baseline guardrails and fixing what fails: hosting (rate limit, CDN and firewall, spend cap), accessibility (keyboard, visible focus, alt text, field labels), Supabase (RLS on every table, owner-scoped policies, no service_role key client-side), SMS and email (recorded consent, unsubscribe, STOP), cloud functions (no self-trigger, instance cap, budget stop), plus API and access hygiene (auth on every route, CORS, secrets, password storage). Runs a deterministic scanner, judges each hit, writes .claude/audits/GUARDRAILS.md, then proposes fixes, applies only the ones the user accepts (bugfixer executor, fresh verifier and security gates) and re-scans to prove each one fixed. Optional read-only live probe confirms a hole from outside on a target the user owns and names. Triggers: "guardrails", "garde-fous", "RLS activée ?", "audit supabase", "consentement sms", "plafond de dépense", "mots de passe en clair ?", "teste la sécurité de base du projet", "corrige les garde-fous", "teste-le en conditions réelles", "sonde le projet en direct". Headers and TLS → /harden; secrets, CVE, OWASP → /cso; full WCAG → /web-validate.'
|
||||
argument-hint: '[project path] [--domain api,hosting,a11y,supabase,messaging,functions] [--exclude paths] [--live <url you own>] [--report-only]'
|
||||
description: 'Use when auditing a project against the baseline guardrails and fixing what fails. Headers and TLS → /harden; secrets, CVE, dependencies → /cso; keyboard, alt, labels → /a11y. Domains: hosting (rate limit, CDN, spend cap), Supabase (RLS, owner policies, no service_role client-side), SMS and email (consent, unsubscribe, STOP), cloud functions (no self-trigger, instance cap, budget stop), injection (SQL from input, raw escapes, NoSQL, shell into DB tools), exposure (console data, source maps, hydrated state, error bodies, debug mode, wide responses), plus API hygiene (auth, CORS, secrets, passwords). Scanner, judgment, .claude/audits/GUARDRAILS.md, fixes applied only on acceptance (bugfixer, verifier and security gates), re-scanned to prove them; optional read-only probe of a target you own. Triggers: "guardrails", "garde-fous", "RLS activée ?", "faille sql", "fuite navigateur", "plafond de dépense", "mots de passe en clair ?", "corrige les garde-fous", "sonde le projet en direct".'
|
||||
argument-hint: '[project path] [--domain api,hosting,supabase,messaging,functions,injection,exposure] [--exclude paths] [--live <url you own>] [--report-only]'
|
||||
---
|
||||
|
||||
# /guardrails
|
||||
@@ -28,8 +28,8 @@ ROUTING: follow `$HOME/.claude/lib/effort-shift.md` (phases via
|
||||
## STEP 1: Scope
|
||||
|
||||
Work in the project the user names, else the current directory. Say in one
|
||||
line what you will scan. Domains: `api`, `hosting`, `a11y`, `supabase`,
|
||||
`messaging`, `functions`. The scanner skips the ones that do not apply.
|
||||
line what you will scan. Domains: `api`, `hosting`, `supabase`,
|
||||
`messaging`, `functions`, `injection`, `exposure`. The scanner skips the ones that do not apply.
|
||||
`--report-only` stops after STEP 7: audit, no fix.
|
||||
|
||||
## STEP 2: Run the scanner
|
||||
@@ -71,21 +71,27 @@ Read the code for the domains that apply and answer, with file:line evidence:
|
||||
wording? Is a STOP reply wired from the provider webhook to the store?
|
||||
- **Functions**: trace every trigger to the resource it writes, including
|
||||
queues, storage events, schedulers and third-party webhooks.
|
||||
- **A11y**: with a dev server running, walk the main flow with Tab only
|
||||
(`/browse`). Otherwise mark the keyboard walk-through as not done.
|
||||
- **Injection**: for each INJ hit, trace the interpolated value to its
|
||||
source. A constant, an allowlisted identifier or a value already cast to
|
||||
a number is a FALSE POSITIVE; anything that can come from a request,
|
||||
a file or another user's row is CONFIRMED.
|
||||
- **Exposure**: read the code behind each EXP hit: is the logged object,
|
||||
the hydrated key or the returned row really user data? With `--live`
|
||||
against a production build (STEP 5), the probe answers for served
|
||||
source maps, error bodies and sensitive keys; without it, say so.
|
||||
|
||||
## STEP 5: Live probe (only on `--live`, read-only)
|
||||
|
||||
The static scan shows a protection is missing in the code. A probe shows the
|
||||
door is actually open. Run it only when the user asks, and only against a
|
||||
target the user owns and names: their local dev server first, a staging or
|
||||
production URL only on an explicit, specific go. Never a URL you inferred,
|
||||
production URL only on an explicit, specific go. The `exposure` block runs against a production build or a staging URL (`next build && next start`, `vite preview`, framework debug off): a dev server serves source maps and tracebacks by design, so its exposure OPEN verdicts are dev artefacts, reported as such, with no proposal and no re-pass requirement. Never a URL you inferred,
|
||||
never a third party.
|
||||
|
||||
1. **Build the plan** `references/checks.md` describes. From the static
|
||||
findings fill a JSON plan: `base_url`, the Supabase `url` and `tables`,
|
||||
the `routes` (mark the ones meant to be public), `cors`, and a
|
||||
`rate_limit` route if the user wants that one burst. Secrets never go in
|
||||
`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`:
|
||||
@@ -100,7 +106,7 @@ never a third party.
|
||||
replays it.
|
||||
3. **Cross the verdicts with the static findings.** A verdict is an
|
||||
observation, not a conclusion: OPEN means the request returned data or a
|
||||
200, CLOSED means it was refused or empty. A static FAIL confirmed OPEN in
|
||||
200, CLOSED means it was refused or empty. SKIPPED and ERROR mean the target was not observed: never read either as proof of a fix. A static FAIL confirmed OPEN in
|
||||
the probe leads the report. A CLOSED probe on a static FAIL still needs the
|
||||
fix: the dev target may differ from production.
|
||||
4. **Guardrails on the probe itself**: read-only, test keys only, the
|
||||
@@ -137,9 +143,9 @@ route). FALSE POSITIVE and ACCEPTED RISK get no proposal. Each proposal:
|
||||
|
||||
- **number, rule, file(s)**, and the problem in one line;
|
||||
- **the fix**, concrete: file:line and the change, the SQL for a migration,
|
||||
the label text for a field. Root cause, never a mask: a missing RLS gets
|
||||
the parameter binding for a query. Root cause, never a mask: a missing RLS gets
|
||||
owner policies in the same migration, not a disabled check;
|
||||
- **choices the user sees** (label wording, CORS origins, owner column,
|
||||
- **choices the user sees** (allowlisted filter fields, CORS origins, owner column,
|
||||
rate-limit numbers), each with your proposed value, named so the user can
|
||||
change it;
|
||||
- **risk**: what it can break. `BREAKING` when it changes a contract a client
|
||||
@@ -150,7 +156,8 @@ route). FALSE POSITIVE and ACCEPTED RISK get no proposal. Each proposal:
|
||||
that must turn CLOSED, and a project test when one fits naturally.
|
||||
|
||||
MANUAL items stay user steps (STEP 6), never proposals. A live OPEN verdict
|
||||
with no static finding gets a proposal whose proof is the probe alone.
|
||||
with no static finding gets a proposal whose proof is the probe alone,
|
||||
unless STEP 5 marked it a dev artefact.
|
||||
|
||||
Save the proposals to `.claude/tasks/plans/<YYYY-MM-DD>-guardrails-<HHMM>.md`
|
||||
and append them to the report. In the reply, show them as a numbered list,
|
||||
@@ -163,7 +170,7 @@ stop the turn:
|
||||
|
||||
```
|
||||
Which fixes do I apply? "all" (every proposal except DECISION ones),
|
||||
numbers ("1,3,5-7"), "none", or an amendment ("2 with the label 'Email'").
|
||||
numbers ("1,3,5-7"), "none", or an amendment ("2 with the fields ['id','status']").
|
||||
A DECISION proposal needs its number plus your choice.
|
||||
```
|
||||
|
||||
|
||||
@@ -26,15 +26,37 @@ default; a judged hit can be a false positive.
|
||||
| HOST-WAF-DDOS | MANUAL | firewall, DDoS and bot rules are dashboard settings | enable and confirm in the dashboard |
|
||||
| HOST-SPEND-CAP | MANUAL | hard spend cap is a plan setting | enable the cap; else budget alert plus a written kill switch |
|
||||
|
||||
## a11y
|
||||
## injection
|
||||
|
||||
Patterns are per language: a Postgres `$1` placeholder, a tagged template
|
||||
(`sql\`…\``, `sql<T>\`…\``), an argv array and test or fixture paths are
|
||||
silent by design.
|
||||
|
||||
One finding per line: INJ-SQL-CONCAT wins over INJ-SQL-RAW-UNSAFE when both
|
||||
match (an interpolation inside a raw escape stays FAIL).
|
||||
|
||||
| Rule | Sev | Catches | Fix |
|
||||
|---|---|---|---|
|
||||
| A11Y-IMG-ALT | FAIL | `img` or `Image` without `alt` | describe it, or `alt=""` if decorative |
|
||||
| A11Y-FIELD-LABEL | FAIL | native input, select, textarea with no label | `label for`, wrapping label or `aria-label` |
|
||||
| A11Y-CLICK-NO-KEYBOARD | FAIL | click handler on a div or span lacking role, tabindex or key handler | use a `button` |
|
||||
| A11Y-FOCUS-OUTLINE | FAIL / WARN | focus outline removed; WARN when a `:focus-visible` style exists elsewhere | style `:focus-visible` instead |
|
||||
| A11Y-TABINDEX-POSITIVE | WARN | `tabindex` above 0 | use 0 or -1 and fix the DOM order |
|
||||
| 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-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 |
|
||||
|
||||
## 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-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-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 |
|
||||
|
||||
## supabase
|
||||
|
||||
@@ -85,7 +107,16 @@ The scanner is regex over text. It cannot see:
|
||||
- whether consent was actually collected before the stored timestamp
|
||||
- whether a STOP reply reaches your store from the provider webhook
|
||||
- loops through queues, storage events, schedulers or third-party webhooks
|
||||
- keyboard traps, focus order, modal focus handling, color contrast
|
||||
- a SQL string assembled across several lines, or passed through a
|
||||
variable before the query call (trace it by hand)
|
||||
- whether a template literal's tag parameterizes: tagged templates are
|
||||
trusted
|
||||
- built output (`dist/`, `.next/`) and runtime state such as
|
||||
`__NEXT_DATA__`: only the live probe sees a served map or a hydrated
|
||||
token
|
||||
- a multi-line Prisma call or a value object spread into state: the
|
||||
single-line rules stay silent
|
||||
- what the console or an XHR carries once the page runs: a browser walk
|
||||
- client-reachable code in unusual layouts (the rule uses path and
|
||||
`use client` heuristics, `.astro` is never flagged)
|
||||
- values built at runtime, minified bundles, anything over 1 MB
|
||||
@@ -105,11 +136,9 @@ project: a contact form beside it and no subscriber storage gives WARN.
|
||||
The scanner skips log files and cache directories, and never follows symlinks.
|
||||
|
||||
By design the scanner ignores: policies granted only to `service_role`,
|
||||
fields that are never rendered (`hidden`, `display: none`), click handlers
|
||||
that only stop propagation or sit on `role="presentation"`, focus styles
|
||||
that swap the outline for a border or shadow, UI route components, keys
|
||||
UI route components, keys
|
||||
inside git-ignored env files, and password literals in test, fixture and
|
||||
i18n files.
|
||||
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.
|
||||
|
||||
## Live Supabase checks (the user runs them in the SQL editor)
|
||||
|
||||
@@ -176,12 +205,14 @@ one opt-in POST burst for the rate-limit check, and stops at a request budget.
|
||||
"cors": true,
|
||||
"cors_path": "/api/v1/notes",
|
||||
"rate_limit": {"path": "/api/v1/auth/login", "method": "POST",
|
||||
"count": 20, "body": "{\"email\":\"t@t.io\",\"password\":\"x\"}"}
|
||||
"count": 20, "body": "{\"email\":\"t@t.io\",\"password\":\"x\"}"},
|
||||
"exposure": {"error_routes": ["/api/v1/notes/not-a-number"]}
|
||||
}
|
||||
```
|
||||
|
||||
Environment, from test keys only, never `service_role`:
|
||||
`GUARDRAILS_ANON_KEY` (anon-read), `GUARDRAILS_JWT2` (cross-user).
|
||||
The fields probe sends `GUARDRAILS_JWT2` as a bearer when it is set. Every path in the plan starts with `/`: a path that could leave the named host is a usage error.
|
||||
|
||||
| Probe | id | OPEN means | Read it against |
|
||||
|---|---|---|---|
|
||||
@@ -190,18 +221,21 @@ Environment, from test keys only, never `service_role`:
|
||||
| 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 |
|
||||
| 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 |
|
||||
|
||||
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
|
||||
the report. A CLOSED probe on a static FAIL still needs the fix: the dev
|
||||
target may differ from production.
|
||||
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.
|
||||
|
||||
Safety, enforced by the script and by the skill: `--authorized` is required;
|
||||
read-only methods only; the loopback or a URL the user named, never one you
|
||||
inferred; a login burst only with a throwaway test account on the user's go,
|
||||
because it can lock the user's own account; a redirect to another host is
|
||||
never followed, so a key never leaves the named host. Fuzzing, writes beyond
|
||||
never followed, so a key never leaves the named host. A script on another host is never fetched. An error route is a path you own and name; the probe never guesses one beyond its single random 404. Fuzzing, writes beyond
|
||||
the named login route, or probing a third party are out of scope: that is
|
||||
pentest, another contract.
|
||||
|
||||
|
||||
@@ -54,9 +54,10 @@ def redact(value):
|
||||
return value[:6] + "..."
|
||||
|
||||
|
||||
SQL_COMMENT = re.compile(r"--[^\n]*|/\*.*?\*/", re.S)
|
||||
SQL_COMMENT = re.compile(r"--[^\n]*|/\*[\s\S]{0,4000}?\*/")
|
||||
MARKUP_COMMENT = re.compile(
|
||||
r"<!--.*?-->|/\*.*?\*/|(?:^|(?<=\s))//[^\n]*", re.S | re.M)
|
||||
r"<!--(?:[^<]|<(?!!--)){0,4000}?-->|/\*[\s\S]{0,4000}?\*/"
|
||||
r"|(?:^|(?<=\s))//[^\n]*", re.M)
|
||||
|
||||
|
||||
def _blank(pattern, text):
|
||||
@@ -72,12 +73,19 @@ def blank_markup_comments(text):
|
||||
return _blank(MARKUP_COMMENT, text)
|
||||
|
||||
|
||||
def _is_scannable(path):
|
||||
def _candidate(path):
|
||||
"""A regular, non-symlink, non-binary file the walker may list."""
|
||||
if path.name in SKIP_FILES or path.suffix.lower() in BINARY_EXTS:
|
||||
return False
|
||||
try:
|
||||
return (path.is_file() and not path.is_symlink()
|
||||
and path.stat().st_size <= MAX_BYTES)
|
||||
return path.is_file() and not path.is_symlink()
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def _small(path):
|
||||
try:
|
||||
return path.stat().st_size <= MAX_BYTES
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
@@ -97,8 +105,8 @@ def _kept_dirs(root, base, dirs, prefixes):
|
||||
def _kept_files(root, base, names, prefixes):
|
||||
for name in names:
|
||||
path = Path(base) / name
|
||||
if _is_scannable(path) and not _excluded(root, path, prefixes):
|
||||
yield path
|
||||
if _candidate(path) and not _excluded(root, path, prefixes):
|
||||
yield path, _small(path)
|
||||
|
||||
|
||||
def _walk(root, prefixes):
|
||||
@@ -113,7 +121,9 @@ class Project:
|
||||
def __init__(self, root, exclude=()):
|
||||
self.root = Path(root).resolve()
|
||||
prefixes = [e.strip("/") for e in exclude if e.strip("/")]
|
||||
self.files = sorted(_walk(self.root, prefixes))
|
||||
listed = sorted(_walk(self.root, prefixes))
|
||||
self.files = [p for p, small in listed if small]
|
||||
self.large = [p for p, small in listed if not small]
|
||||
self._text = {}
|
||||
|
||||
def rel(self, path):
|
||||
@@ -161,3 +171,72 @@ def non_doc_files(project):
|
||||
"""Files that can hold behavior: everything except docs and samples."""
|
||||
skip = (".md", ".mdx", ".txt", ".example", ".sample", ".template")
|
||||
return [p for p in project.files if not p.name.endswith(skip)]
|
||||
|
||||
|
||||
TEST_PATH = re.compile(
|
||||
r"\.(?:test|spec|e2e|stories)\.|(?:^|/)(?:tests?|__tests__|spec|e2e"
|
||||
r"|fixtures?|mocks?)/", re.I)
|
||||
BUILT_SEGMENTS = {"public", "static", "www", "assets"}
|
||||
MINIFIED_NAME = re.compile(r"\.min\.|\.bundle\.", re.I)
|
||||
LONG_LINE = 5000
|
||||
|
||||
|
||||
def _minified(project, path):
|
||||
if MINIFIED_NAME.search(path.name):
|
||||
return True
|
||||
return any(len(line) > LONG_LINE
|
||||
for line in project.text(path).splitlines())
|
||||
|
||||
|
||||
def code_files(project, exts=SOURCE_EXTS, keep_built=False):
|
||||
"""Hand-written source: no tests, fixtures, built dirs, minified files.
|
||||
|
||||
keep_built keeps public/, static/, www/ and assets/: they also hold the
|
||||
hand-written browser scripts of server-rendered stacks."""
|
||||
skipped = set() if keep_built else BUILT_SEGMENTS
|
||||
return [p for p in non_doc_files(project)
|
||||
if p.suffix.lower() in exts
|
||||
and not TEST_PATH.search(project.rel(p))
|
||||
and not set(project.segments(p)) & skipped
|
||||
and not _minified(project, p)]
|
||||
|
||||
|
||||
def hits(project, files, regex, rule, message):
|
||||
"""One finding per match of a compiled regex over the given files."""
|
||||
return [project.found(rule, path, m.start(), message)
|
||||
for path in files
|
||||
for m in regex.finditer(project.text(path))]
|
||||
|
||||
|
||||
def dedupe_lines(findings):
|
||||
"""One finding per (path, line): the first emitted wins."""
|
||||
seen, out = set(), []
|
||||
for finding in findings:
|
||||
if (finding.path, finding.line) not in seen:
|
||||
seen.add((finding.path, finding.line))
|
||||
out.append(finding)
|
||||
return out
|
||||
|
||||
|
||||
SERVER_SEGMENTS = {
|
||||
"functions", "api", "server", "scripts", "tests", "test", "migrations",
|
||||
"seed", ".github", "supabase", "tools",
|
||||
}
|
||||
CLIENT_SEGMENTS = {
|
||||
"components", "public", "static", "client", "browser", "www", "islands",
|
||||
}
|
||||
CLIENT_EXTS = (".vue", ".svelte", ".html", ".htm")
|
||||
CLIENT_SCRIPT_EXTS = (".ts", ".tsx", ".js", ".jsx", ".mjs")
|
||||
|
||||
|
||||
def client_reachable(project, path):
|
||||
"""Heuristic: this file's text ends up in a browser bundle or page."""
|
||||
segments = set(project.segments(path))
|
||||
if segments & SERVER_SEGMENTS:
|
||||
return False
|
||||
if path.suffix.lower() in CLIENT_EXTS:
|
||||
return True
|
||||
if path.suffix.lower() not in CLIENT_SCRIPT_EXTS:
|
||||
return False
|
||||
head = project.text(path)[:300]
|
||||
return bool(segments & CLIENT_SEGMENTS) or "use client" in head
|
||||
@@ -0,0 +1,269 @@
|
||||
"""Exposure checks: what the browser can see that it should not."""
|
||||
import re
|
||||
|
||||
from . import passwords
|
||||
from .apis import ENV_NAME, ENV_SAMPLE, ignore_patterns, is_ignored_env
|
||||
from .apis import route_files
|
||||
from .common import Rule, client_reachable, code_files, dedupe_lines, hits
|
||||
|
||||
DOMAIN = "exposure"
|
||||
MARKUP_EXTS = (".html", ".htm", ".astro", ".php", ".ejs", ".hbs", ".twig",
|
||||
".njk", ".liquid")
|
||||
ATTR_EXTS = MARKUP_EXTS + (".jsx", ".tsx", ".vue", ".svelte")
|
||||
DEV_TOKEN = re.compile(
|
||||
r"(?:^|[._-])(?:dev|development|local|test|testing)(?:[._-]|$)", re.I)
|
||||
CONSOLE = re.compile(
|
||||
r"\bconsole\.(?:log|info|debug|dir|table)\s*\(([^\n]{0,300})")
|
||||
DATA_NAMES = re.compile(
|
||||
r"\b(?:users?|profile|session|token|account|customer|order|payment"
|
||||
r"|response|res|data|result|rows|body|headers|props|state|error|err"
|
||||
r"|json|payload|record|items?)\b", re.I)
|
||||
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)")
|
||||
LOADER = re.compile(
|
||||
r"getServerSideProps|getStaticProps"
|
||||
r"|export\s+(?:async\s+)?function\s+(?:loader|load)\b"
|
||||
r"|export\s+const\s+(?:loader|load)\b|window\.__\w+__\s*=")
|
||||
TYPEISH = (r"(?:string|number|boolean|null|undefined|unknown|any|never"
|
||||
r"|[A-Z][\w<>\[\]|]*)")
|
||||
HYDRATED = re.compile(
|
||||
rf"\b{SENSITIVE}\s*:(?!\s*{TYPEISH}\s*(?:[;,}}]|$))", re.M)
|
||||
COMMENT = re.compile(r"<!--([\s\S]{0,400}?)-->")
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
SENDING = (
|
||||
r"(?:\bres\.(?:status|json|send|end|write)\b"
|
||||
r"|\breply\.(?:send|code|status)\b|\bctx\.body\b|\bResponse\("
|
||||
r"|Response\.json\(|\bjsonify\(|\bJSONResponse\(|\bHTTPException\("
|
||||
r"|\bdetail\s*=|\becho\b)")
|
||||
ERR = r"(?:err|error|e|exc|exception)"
|
||||
ERROR_STACK = re.compile(
|
||||
rf"{SENDING}[^\n]{{0,300}}?(?:\b{ERR}\.stack\b|traceback\.format_exc"
|
||||
rf"|getTraceAsString\(\))"
|
||||
rf"|\b(?:json|send)\s*\(\s*\{{[^}}\n]{{0,200}}\berror\s*:\s*{ERR}\s*[,}}]")
|
||||
ERROR_MESSAGE = re.compile(
|
||||
rf"{SENDING}[^\n]{{0,300}}?(?:\b{ERR}\.message\b|\bstr\({ERR}\)"
|
||||
rf"|\brepr\({ERR}\)|->getMessage\(\))")
|
||||
SETTINGS_NAME = re.compile(r"^(?:settings|config)", re.I)
|
||||
DEBUG_SETTINGS = re.compile(r"^DEBUG\s*=\s*True\b", re.M)
|
||||
DEBUG_ENV = re.compile(
|
||||
r"^[ \t]*(?:APP_DEBUG\s*=\s*true|FLASK_DEBUG\s*=\s*1)\b", re.M | re.I)
|
||||
DEBUG_CODE = re.compile(
|
||||
r"app\.debug\s*=\s*True|app\.run\([^)\n]{0,200}debug\s*=\s*True")
|
||||
DEBUG_HANDLER = re.compile(r"app\.use\(\s*errorhandler\(\)")
|
||||
ENV_GUARD = re.compile(r"development|NODE_ENV")
|
||||
DEBUG_RAILS = re.compile(r"consider_all_requests_local\s*=\s*true")
|
||||
NEXT_MAPS = re.compile(r"productionBrowserSourceMaps\s*:\s*true")
|
||||
VITE_MAPS = re.compile(r"\bsourcemap\s*:\s*(?:true|['\"]inline['\"])")
|
||||
WEBPACK_DEVTOOL = re.compile(
|
||||
r"\bdevtool\s*:\s*['\"](?:source-map|eval[\w-]*|inline[\w-]*"
|
||||
r"|cheap[\w-]*)['\"]")
|
||||
ENV_MAPS = re.compile(r"^[ \t]*GENERATE_SOURCEMAP\s*=\s*true\b", re.M | re.I)
|
||||
ANGULAR_MAPS = re.compile(r"\"sourceMap\"\s*:\s*true")
|
||||
PUBLIC_DIRS = {"public", "static", "assets", "www"}
|
||||
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"|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}\}"
|
||||
r"\s*\)", re.I)
|
||||
|
||||
|
||||
def applies(project):
|
||||
return bool(project.with_ext(".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs",
|
||||
".py", ".php", ".rb", ".vue", ".svelte",
|
||||
".astro", *MARKUP_EXTS))
|
||||
|
||||
|
||||
def _named(project, prefix):
|
||||
return [p for p in project.files if p.name.startswith(prefix)]
|
||||
|
||||
|
||||
def _client(project, path):
|
||||
"""client_reachable, plus Next pages and a root App component."""
|
||||
if client_reachable(project, path):
|
||||
return True
|
||||
segments = project.segments(path)
|
||||
return (path.suffix.lower() in (".tsx", ".jsx") and "api" not in segments
|
||||
and ("pages" in segments or path.stem == "App"))
|
||||
|
||||
|
||||
def _console_data(project, files):
|
||||
rule = Rule(DOMAIN, "EXP-CONSOLE-DATA", "WARN")
|
||||
out = []
|
||||
for path in (p for p in files if _client(project, p)):
|
||||
for m in CONSOLE.finditer(project.text(path)):
|
||||
if passwords.LOGGED_NAME.search(m.group(1)):
|
||||
continue
|
||||
if DATA_NAMES.search(passwords.log_args(m.group(1))):
|
||||
out.append(project.found(
|
||||
rule, path, m.start(),
|
||||
"data logged to the browser console"))
|
||||
return out
|
||||
|
||||
|
||||
def _map_config(project):
|
||||
fail = Rule(DOMAIN, "EXP-SOURCEMAP-PUBLIC", "FAIL")
|
||||
warn = Rule(DOMAIN, "EXP-SOURCEMAP-PUBLIC", "WARN")
|
||||
out = hits(project, _named(project, "next.config"), NEXT_MAPS, fail,
|
||||
"production source maps enabled")
|
||||
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]
|
||||
out += hits(project, prod, WEBPACK_DEVTOOL, fail,
|
||||
"devtool emits readable source maps in production")
|
||||
out += hits(project, other, WEBPACK_DEVTOOL, warn,
|
||||
"devtool emits readable source maps: confirm not in prod")
|
||||
return out + hits(project, project.named("angular.json"), ANGULAR_MAPS,
|
||||
warn, "sourceMap true: confirm not the production build")
|
||||
|
||||
|
||||
def _env_files(project):
|
||||
"""Committed env files that are not samples and not dev/local/test."""
|
||||
patterns = ignore_patterns(project)
|
||||
return [p for p in project.files if ENV_NAME.fullmatch(p.name)
|
||||
and not p.name.endswith(ENV_SAMPLE)
|
||||
and not DEV_TOKEN.search(p.name[4:] or "x")
|
||||
and not is_ignored_env(p, patterns)]
|
||||
|
||||
|
||||
def _public_map(project, path):
|
||||
return (set(project.segments(path)) & PUBLIC_DIRS
|
||||
and not VENDORED.search(project.rel(path)))
|
||||
|
||||
|
||||
def _large_map(project, path):
|
||||
"""A large public .map whose first 4 KB already hold a mappings 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)
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def _map_files(project):
|
||||
rule = Rule(DOMAIN, "EXP-SOURCEMAP-PUBLIC", "FAIL")
|
||||
out = hits(project, _env_files(project), ENV_MAPS, rule,
|
||||
"GENERATE_SOURCEMAP=true ships source maps")
|
||||
small = [p for p in project.with_ext(".map")
|
||||
if _public_map(project, p) and '"mappings"' in project.text(p)]
|
||||
large = [p for p in project.large if _large_map(project, p)]
|
||||
return out + [project.found(rule, p, 0, "source map in a public directory")
|
||||
for p in small + large]
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
def _markup_comments(project):
|
||||
rule = Rule(DOMAIN, "EXP-MARKUP-COMMENT", "WARN")
|
||||
return [project.found(rule, path, m.start(),
|
||||
"HTML comment shipped to the browser carries "
|
||||
"internal notes")
|
||||
for path in project.with_ext(*MARKUP_EXTS)
|
||||
for m in COMMENT.finditer(project.text(path))
|
||||
if COMMENT_WORDS.search(m.group(1))]
|
||||
|
||||
|
||||
def _hidden_sensitive(tag):
|
||||
if not re.search(r"type\s*=\s*[\"']?hidden\b", tag, re.I):
|
||||
return False
|
||||
name = re.search(r"name\s*=\s*[\"']([^\"']+)", tag, re.I)
|
||||
return bool(name and SENSITIVE_NAME.search(name.group(1))
|
||||
and not SAFE_NAME.search(name.group(1)))
|
||||
|
||||
|
||||
def _data_attrs(project):
|
||||
rule = Rule(DOMAIN, "EXP-DATA-ATTR-SENSITIVE", "WARN")
|
||||
out = []
|
||||
for path in project.with_ext(*ATTR_EXTS):
|
||||
text = project.text(path)
|
||||
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))]
|
||||
out += [project.found(rule, path, m.start(),
|
||||
"sensitive value in a hidden input")
|
||||
for m in HIDDEN_INPUT.finditer(text)
|
||||
if _hidden_sensitive(m.group(0))]
|
||||
return out
|
||||
|
||||
|
||||
def _errors(project, files):
|
||||
server = [p for p in files if not client_reachable(project, p)]
|
||||
stack = hits(project, server, ERROR_STACK,
|
||||
Rule(DOMAIN, "EXP-ERROR-STACK", "FAIL"),
|
||||
"stack trace or error object sent to the client")
|
||||
message = hits(project, server, ERROR_MESSAGE,
|
||||
Rule(DOMAIN, "EXP-ERROR-MESSAGE", "WARN"),
|
||||
"raw exception message sent to the client")
|
||||
return dedupe_lines(stack + message)
|
||||
|
||||
|
||||
def _settings_modules(project, files):
|
||||
return [p for p in files if p.suffix == ".py"
|
||||
and (SETTINGS_NAME.match(p.name)
|
||||
or "settings" in project.segments(p))
|
||||
and not DEV_TOKEN.search(p.stem)]
|
||||
|
||||
|
||||
def _handler_hits(project, files):
|
||||
"""errorhandler() mounted with no env guard in the 200 chars before."""
|
||||
rule = Rule(DOMAIN, "EXP-DEBUG-ON", "FAIL")
|
||||
return [project.found(rule, path, m.start(),
|
||||
"dev error handler mounted without an "
|
||||
"environment guard")
|
||||
for path in files
|
||||
for m in DEBUG_HANDLER.finditer(project.text(path))
|
||||
if not ENV_GUARD.search(
|
||||
project.text(path)[max(0, m.start() - 200):m.start()])]
|
||||
|
||||
|
||||
def _debug(project, files):
|
||||
rule = Rule(DOMAIN, "EXP-DEBUG-ON", "FAIL")
|
||||
out = hits(project, _settings_modules(project, files), DEBUG_SETTINGS,
|
||||
rule, "DEBUG = True in a settings module")
|
||||
out += hits(project, _env_files(project), DEBUG_ENV, rule,
|
||||
"debug mode on in a committed env file")
|
||||
out += hits(project, files, DEBUG_CODE, rule,
|
||||
"debug mode enabled in code")
|
||||
out += _handler_hits(project, files)
|
||||
return out + hits(project, project.named("production.rb"), DEBUG_RAILS,
|
||||
rule, "full error pages enabled in production")
|
||||
|
||||
|
||||
def _response_wide(project):
|
||||
return hits(project, route_files(project), WIDE,
|
||||
Rule(DOMAIN, "EXP-RESPONSE-WIDE", "WARN"),
|
||||
"whole rows of a user table returned: select the fields")
|
||||
|
||||
|
||||
def check(project):
|
||||
files = code_files(project)
|
||||
console = code_files(project, keep_built=True)
|
||||
found = _console_data(project, console) + _map_config(project)
|
||||
found += _map_files(project) + _hydrated(project, files)
|
||||
found += _markup_comments(project) + _data_attrs(project)
|
||||
found += _errors(project, files) + _debug(project, files)
|
||||
return found + _response_wide(project)
|
||||
@@ -0,0 +1,149 @@
|
||||
"""Injection checks: SQL built from input, raw ORM escapes, dynamic SQL,
|
||||
PostgREST filters, NoSQL operators, a shell into a DB tool."""
|
||||
import re
|
||||
|
||||
from .common import Rule, blank_comments, code_files, dedupe_lines, hits
|
||||
|
||||
DOMAIN = "injection"
|
||||
JS_EXTS = (".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".vue", ".svelte",
|
||||
".astro")
|
||||
SQL_EXTS = (".sql", ".pgsql", ".plpgsql")
|
||||
GAP = r"[^'\"`]{0,200}"
|
||||
STMT = (
|
||||
rf"(?:select\b{GAP}\bfrom\b{GAP}\b(?:where|join|limit|order\s+by"
|
||||
rf"|group\s+by)\b|select\s+\*\s+from\b"
|
||||
rf"|insert\s+into\s+[\w.\"]+{GAP}\b(?:values|select)\b"
|
||||
r"|insert\s+into\s+[\w.\"]+\s*\(|update\s+[\w.\"]+\s+set\b"
|
||||
r"|delete\s+from\s+[\w.\"]+\s+where\b"
|
||||
r"|\bwhere\s+[\w.\"]+\s*(?:=|like\b|in\b|<|>)"
|
||||
r"|create\s+(?:table|index)\s|drop\s+(?:table|index)\s"
|
||||
r"|alter\s+table\s|truncate\s+table\s)")
|
||||
DQ = r"[^\"\n]{0,200}"
|
||||
SQ = r"[^'\n]{0,200}"
|
||||
|
||||
|
||||
def _quoted(tail):
|
||||
"""A double- or single-quoted SQL statement string followed by tail."""
|
||||
return rf"\"{DQ}?{STMT}{DQ}\"{tail}|'{SQ}?{STMT}{SQ}'{tail}"
|
||||
|
||||
|
||||
CONCAT = {
|
||||
JS_EXTS: re.compile(
|
||||
rf"(?<![\w$)\]>])`[^`]{{0,400}}?{STMT}[^`]{{0,400}}?\$\{{|"
|
||||
+ _quoted(r"\s*\+\s*[\w$(]"), re.I),
|
||||
(".py",): re.compile(
|
||||
rf"\bf['\"][^'\"\n]{{0,200}}?{STMT}|"
|
||||
+ _quoted(r"\s*(?:%\s*[\w(]|\.format\(|\+\s*[\w(])"), re.I),
|
||||
(".php",): re.compile(
|
||||
rf"\"{DQ}?{STMT}{DQ}\$[A-Za-z_]\w*|"
|
||||
+ _quoted(r"\s*\.\s*\$[A-Za-z_]"), re.I),
|
||||
(".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),
|
||||
}
|
||||
RAW = {
|
||||
JS_EXTS: re.compile(
|
||||
r"(?:\$queryRawUnsafe|\$executeRawUnsafe|\bknex\.raw"
|
||||
r"|\bsequelize\.query|\b[Ss]equelize\.literal)\s*\(\s*(?![\s'\"`)])"),
|
||||
(".py",): re.compile(
|
||||
r"\.objects\.raw\(\s*(?![\s'\"`)])|\.extra\(\s*(?![\s'\"`)])"),
|
||||
}
|
||||
SQLA_TEXT = re.compile(
|
||||
r"(?:(?<![.\w])|(?<=\bsa\.)|(?<=\bsqlalchemy\.))text\s*\(\s*(?![\s'\"`)])")
|
||||
DYNAMIC_EXEC = re.compile(r"\bexecute\s+(?:'[^']*'|\w+)\s*\|\|", re.I)
|
||||
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"|\.(?:find|findOne|findOneAndUpdate|findOneAndDelete|updateOne"
|
||||
r"|updateMany|deleteOne|deleteMany|countDocuments|replaceOne)\(\s*"
|
||||
r"(?:req\.(?:body|query|params)\b"
|
||||
r"|\{\s*\w+\s*:\s*req\.(?:body|query|params)\.\w+\s*[,}])")
|
||||
SHELL_DB_HEAD = (
|
||||
r"\b(?:exec|execSync|spawn|spawnSync|system|popen|subprocess\.\w+"
|
||||
r"|os\.system|Command::new|shell_exec|passthru|proc_open)\s*\("
|
||||
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|"
|
||||
# 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_])")
|
||||
SHELL_DB_PHP = re.compile(SHELL_DB_HEAD + SHELL_INTERP + r"\$[A-Za-z_])")
|
||||
|
||||
|
||||
def applies(project):
|
||||
return bool(project.with_ext(*JS_EXTS, ".py", ".php", ".rb", ".rs",
|
||||
".go", *SQL_EXTS))
|
||||
|
||||
|
||||
def _by_ext(files, exts):
|
||||
return [p for p in files if p.suffix.lower() in exts]
|
||||
|
||||
|
||||
def _per_language(project, files, table, rule, message):
|
||||
out = []
|
||||
for exts, regex in table.items():
|
||||
out += hits(project, _by_ext(files, exts), regex, rule, message)
|
||||
return out
|
||||
|
||||
|
||||
def _raw_unsafe(project, files):
|
||||
rule = Rule(DOMAIN, "INJ-SQL-RAW-UNSAFE", "WARN")
|
||||
msg = ("raw SQL escape fed a non-literal: show it is a constant "
|
||||
"with bound values, else bind them")
|
||||
sqla = [p for p in _by_ext(files, (".py",))
|
||||
if "sqlalchemy" in project.text(p)]
|
||||
return (_per_language(project, files, RAW, rule, msg)
|
||||
+ hits(project, sqla, SQLA_TEXT, rule, msg))
|
||||
|
||||
|
||||
def _concat(project, files):
|
||||
return _per_language(
|
||||
project, files, CONCAT, Rule(DOMAIN, "INJ-SQL-CONCAT", "FAIL"),
|
||||
"SQL built from an expression: use placeholders")
|
||||
|
||||
|
||||
def _dynamic_exec(project):
|
||||
rule = Rule(DOMAIN, "INJ-SQL-DYNAMIC-EXEC", "WARN")
|
||||
out = []
|
||||
for path in code_files(project, SQL_EXTS):
|
||||
text = blank_comments(project.text(path))
|
||||
for m in DYNAMIC_EXEC.finditer(text):
|
||||
out.append(project.found(
|
||||
rule, path, m.start(),
|
||||
"EXECUTE built with ||: use format() with %I/%L and USING"))
|
||||
return out
|
||||
|
||||
|
||||
def _postgrest(project, files):
|
||||
client = [p for p in _by_ext(files, JS_EXTS)
|
||||
if "supabase" in project.text(p)]
|
||||
return hits(project, client, POSTGREST,
|
||||
Rule(DOMAIN, "INJ-POSTGREST-FILTER", "WARN"),
|
||||
"PostgREST filter string built from a value: use .eq()")
|
||||
|
||||
|
||||
def _nosql(project, files):
|
||||
return hits(project, _by_ext(files, JS_EXTS), NOSQL,
|
||||
Rule(DOMAIN, "INJ-NOSQL-OPERATOR", "WARN"),
|
||||
"filter taken from the request: allowlist fields, cast")
|
||||
|
||||
|
||||
def _shell_db(project, files):
|
||||
rule = Rule(DOMAIN, "INJ-SHELL-DB-TOOL", "FAIL")
|
||||
msg = "DB tool run through a shell with input: pass an argv"
|
||||
php = _by_ext(files, (".php",))
|
||||
other = [p for p in files if p.suffix.lower() != ".php"]
|
||||
return (hits(project, other, SHELL_DB, rule, msg)
|
||||
+ hits(project, php, SHELL_DB_PHP, rule, msg))
|
||||
|
||||
|
||||
def check(project):
|
||||
files = code_files(project)
|
||||
found = _concat(project, files) + _raw_unsafe(project, files)
|
||||
found += _dynamic_exec(project) + _postgrest(project, files)
|
||||
found += _nosql(project, files) + _shell_db(project, files)
|
||||
return dedupe_lines(found)
|
||||
@@ -98,7 +98,7 @@ def _weak_hash(project, files):
|
||||
]
|
||||
|
||||
|
||||
def _log_args(args):
|
||||
def log_args(args):
|
||||
"""Call arguments with string literals reduced to their interpolations."""
|
||||
return STRING.sub(
|
||||
lambda m: " ".join(re.findall(r"\{([^}]*)\}", m.group())), args)
|
||||
@@ -110,7 +110,7 @@ def _logged(project, files):
|
||||
Rule(DOMAIN, "API-PASSWORD-LOGGED", "FAIL"), path, m.start(),
|
||||
"password reaches a log: never log credentials")
|
||||
for path, m in project.matches(LOG_CALL, files)
|
||||
if LOGGED_NAME.search(_log_args(m.group(1)))
|
||||
if LOGGED_NAME.search(log_args(m.group(1)))
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
from .apis import ignore_patterns, is_ignored_env
|
||||
from .common import Rule, SOURCE_EXTS, blank_comments
|
||||
from .common import CLIENT_EXTS, Rule, SOURCE_EXTS, blank_comments
|
||||
from .common import client_reachable
|
||||
|
||||
DOMAIN = "supabase"
|
||||
_NAME = r'(?:"?\w+"?\.)?"?\w+"?'
|
||||
@@ -35,15 +36,6 @@ ANON_ROLES = {"anon", "public"}
|
||||
PRIVILEGED_ROLES = {"service_role", "postgres", "supabase_admin"}
|
||||
|
||||
SERVICE_REF = r"service_role|SERVICE_ROLE|SUPABASE_SECRET_KEY|sb_secret_"
|
||||
SERVER_SEGMENTS = {
|
||||
"functions", "api", "server", "scripts", "tests", "test", "migrations",
|
||||
"seed", ".github", "supabase", "tools",
|
||||
}
|
||||
CLIENT_SEGMENTS = {
|
||||
"components", "public", "static", "client", "browser", "www", "islands",
|
||||
}
|
||||
CLIENT_EXTS = (".vue", ".svelte", ".html", ".htm")
|
||||
SCRIPT_EXTS = (".ts", ".tsx", ".js", ".jsx", ".mjs")
|
||||
JWT = r"eyJ[\w-]{8,}\.(eyJ[\w-]{8,})\.[\w-]{8,}"
|
||||
MANIFESTS = (
|
||||
"package.json", "Cargo.toml", "requirements.txt", "pyproject.toml",
|
||||
@@ -286,18 +278,6 @@ def _config(project):
|
||||
return out
|
||||
|
||||
|
||||
def _client_reachable(project, path):
|
||||
segments = set(project.segments(path))
|
||||
if segments & SERVER_SEGMENTS:
|
||||
return False
|
||||
if path.suffix.lower() in CLIENT_EXTS:
|
||||
return True
|
||||
if path.suffix.lower() not in SCRIPT_EXTS:
|
||||
return False
|
||||
head = project.text(path)[:300]
|
||||
return bool(segments & CLIENT_SEGMENTS) or "use client" in head
|
||||
|
||||
|
||||
def _client_leaks(project):
|
||||
files = project.with_ext(*SOURCE_EXTS, *CLIENT_EXTS)
|
||||
return [
|
||||
@@ -306,7 +286,7 @@ def _client_leaks(project):
|
||||
"service role or secret key referenced in client-reachable "
|
||||
"code: it bypasses RLS for anyone who reads the bundle")
|
||||
for path, m in project.matches(SERVICE_REF, files, 0)
|
||||
if _client_reachable(project, path)
|
||||
if client_reachable(project, path)
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -5,12 +5,15 @@ The static scan shows a protection is absent in the code. This observes what
|
||||
a running target the user owns and names actually returns. It sends GET, HEAD
|
||||
and OPTIONS only; a login burst is opt-in in the plan. It never writes data,
|
||||
never uses a service_role key, never follows a redirect to another host, and
|
||||
stops at a fixed request budget.
|
||||
stops at a fixed request budget. With an exposure block in the plan it
|
||||
also reads what the page's scripts, error bodies and JSON responses give
|
||||
away; a target it could not observe is ERROR or SKIPPED, never CLOSED.
|
||||
|
||||
Input is a plan JSON (built by the skill from the static findings) plus
|
||||
secrets from the environment, never the command line:
|
||||
GUARDRAILS_ANON_KEY Supabase anon/publishable key for the anon-read probe
|
||||
GUARDRAILS_JWT2 a second test user's token for the cross-user probe
|
||||
(also sent as bearer by the fields probe when set)
|
||||
|
||||
A verdict is a factual observation, not a conclusion: the skill reads it
|
||||
against the static findings. OPEN means the request returned data or a 200,
|
||||
@@ -18,25 +21,42 @@ CLOSED means it was refused or empty. Exit codes: 0 no OPEN, 1 at least one
|
||||
OPEN, 2 usage error.
|
||||
"""
|
||||
import argparse
|
||||
import http.client
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from dataclasses import asdict, dataclass
|
||||
from urllib.parse import quote, urlsplit
|
||||
from urllib.parse import quote, urljoin, urlsplit
|
||||
|
||||
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
|
||||
SCRIPT_SRC = re.compile(r"<script[^>]{1,300}src=[\"']?([^\"'\s>]+)", re.I)
|
||||
MAP_COMMENT = re.compile(
|
||||
r"^[ \t]*//[#@][ \t]*sourceMappingURL=(\S+)", re.M)
|
||||
TRACE_MARKERS = re.compile(
|
||||
rb"Traceback \(most recent call last\)"
|
||||
rb"|\bat [\w.$<> ]{1,80} \([^)\n]{0,200}:\d+:\d+\)"
|
||||
rb"|File \"[^\"\n]+\", line \d+|SQLSTATE\[|syntax error at or near"
|
||||
rb"|node_modules/|/var/www/|Stack trace:|#\d+ /[\w/.-]+\.php\(\d+\)")
|
||||
SENSITIVE_KEY = re.compile(
|
||||
r"(?:^|_)(?:password|passwd|pwd|salt|secret|token|hash|api_?key"
|
||||
r"|service_?role"
|
||||
r"|private_?key|(?:access|refresh|id|auth|api|session)_token|jwt|ssn"
|
||||
r"|iban|cvv|card_?number)(?:$|_)")
|
||||
IDENT = re.compile(r"[A-Za-z_][\w-]{0,31}") # used with fullmatch
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Response:
|
||||
status: int # None on a transport error
|
||||
headers: dict
|
||||
headers: object # http.client.HTTPMessage: .get() ignores case
|
||||
body: bytes
|
||||
error: str = ""
|
||||
|
||||
@@ -53,11 +73,22 @@ class Probe:
|
||||
return asdict(self)
|
||||
|
||||
|
||||
def _stays_on_host(old_url, new_url):
|
||||
"""Same host and port; the scheme may stay or upgrade, never downgrade."""
|
||||
try:
|
||||
old, new = urlsplit(old_url), urlsplit(new_url)
|
||||
except ValueError:
|
||||
return False
|
||||
return old.netloc == new.netloc and (
|
||||
old.scheme == new.scheme or (old.scheme, new.scheme)
|
||||
== ("http", "https"))
|
||||
|
||||
|
||||
class _SameHost(urllib.request.HTTPRedirectHandler):
|
||||
"""Follow a same-host redirect, drop one that leaves the host."""
|
||||
|
||||
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
||||
if urlsplit(newurl).netloc != urlsplit(req.full_url).netloc:
|
||||
if not _stays_on_host(req.full_url, newurl):
|
||||
return None
|
||||
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
||||
|
||||
@@ -71,8 +102,15 @@ class Session:
|
||||
self.budget = budget
|
||||
|
||||
|
||||
def _error_body(exc):
|
||||
try:
|
||||
return exc.read(BODY_CAP)
|
||||
except (OSError, ValueError, AttributeError):
|
||||
return b""
|
||||
|
||||
|
||||
def _response_from(resp):
|
||||
return Response(resp.status, dict(resp.headers), resp.read(BODY_CAP))
|
||||
return Response(resp.status, resp.headers, resp.read(BODY_CAP))
|
||||
|
||||
|
||||
def fetch(session, method, url, headers=None, body=None):
|
||||
@@ -85,9 +123,11 @@ def fetch(session, method, url, headers=None, body=None):
|
||||
with session.opener.open(req, timeout=session.timeout) as resp:
|
||||
return _response_from(resp)
|
||||
except urllib.error.HTTPError as exc:
|
||||
return Response(exc.code, dict(exc.headers), b"")
|
||||
except (urllib.error.URLError, OSError, ValueError) as exc:
|
||||
return Response(None, {}, b"", str(exc))
|
||||
return Response(exc.code, exc.headers, _error_body(exc))
|
||||
except (urllib.error.URLError, OSError, ValueError,
|
||||
http.client.HTTPException) as exc:
|
||||
reason = str(exc)
|
||||
return Response(None, {}, b"", reason)
|
||||
|
||||
|
||||
def _verdict(ctx, response, is_open, msgs):
|
||||
@@ -167,7 +207,7 @@ def _route_probe(session, base, route):
|
||||
|
||||
def probe_routes(session, plan):
|
||||
base = plan["base_url"].rstrip("/")
|
||||
routes = [r for r in plan.get("routes", []) if not r.get("public")]
|
||||
routes = [r for r in plan.get("routes") or [] if not r.get("public")]
|
||||
return [_route_probe(session, base, r) for r in routes]
|
||||
|
||||
|
||||
@@ -219,8 +259,180 @@ def probe_rate_limit(session, plan):
|
||||
return [_rate_verdict(target, codes)]
|
||||
|
||||
|
||||
def _same_host(context, url):
|
||||
"""Absolute url when it stays on context's host, else None."""
|
||||
try:
|
||||
full = urljoin(context, url)
|
||||
except ValueError:
|
||||
return None
|
||||
return full if _stays_on_host(context, full) else None
|
||||
|
||||
|
||||
def _page_scripts(session, base):
|
||||
"""(urls, note): same-host scripts of the base page, or why none."""
|
||||
page = fetch(session, "GET", base + "/")
|
||||
if page.error:
|
||||
return [], f"base page unreachable: {page.error}"
|
||||
text = page.body.decode("utf-8", "ignore")
|
||||
urls = [u for u in (_same_host(base + "/", s)
|
||||
for s in SCRIPT_SRC.findall(text)) if u]
|
||||
urls = list(dict.fromkeys(urls))[:SCRIPT_CAP]
|
||||
return urls, "" if urls else "no same-host script on the base page"
|
||||
|
||||
|
||||
def _map_candidates(script_url, resp):
|
||||
bare = urlsplit(script_url)._replace(query="", fragment="").geturl()
|
||||
urls = [bare + ".map"]
|
||||
header = resp.headers.get("sourcemap") or resp.headers.get("x-sourcemap")
|
||||
if header:
|
||||
urls.append(header)
|
||||
comments = MAP_COMMENT.findall(resp.body.decode("utf-8", "ignore"))
|
||||
if comments:
|
||||
urls.append(comments[-1])
|
||||
return list(dict.fromkeys(urls))
|
||||
|
||||
|
||||
def _map_verdict(session, script_url, candidates):
|
||||
"""(verdict, target, note) over the candidate map urls, fail closed."""
|
||||
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"
|
||||
return "CLOSED", script_url, "no source map served for this script"
|
||||
|
||||
|
||||
def _sourcemap_probe(session, script_url):
|
||||
pid = f"sourcemap:{urlsplit(script_url).path}"
|
||||
resp = fetch(session, "GET", script_url)
|
||||
if resp.error:
|
||||
return Probe("exposure", pid, "ERROR", script_url, resp.error)
|
||||
if resp.status != 200:
|
||||
return Probe("exposure", pid, "SKIPPED", script_url,
|
||||
f"HTTP {resp.status}: script not served, map not read")
|
||||
if len(resp.body) >= BODY_CAP:
|
||||
return Probe("exposure", pid, "SKIPPED", script_url,
|
||||
"script body truncated: its map comment was not read")
|
||||
verdict, target, note = _map_verdict(
|
||||
session, script_url, _map_candidates(script_url, resp))
|
||||
return Probe("exposure", pid, verdict, target, note)
|
||||
|
||||
|
||||
def _sourcemaps(session, base, cfg):
|
||||
listed = cfg.get("scripts")
|
||||
if listed is None:
|
||||
urls, note = _page_scripts(session, base)
|
||||
else:
|
||||
urls = [base + s for s in listed][:SCRIPT_CAP]
|
||||
note = "" if urls else "no script listed in exposure.scripts"
|
||||
if note:
|
||||
return [Probe("exposure", "sourcemap", "SKIPPED", base, note)]
|
||||
return [_sourcemap_probe(session, u) for u in urls]
|
||||
|
||||
|
||||
def _error_probe(session, base, path):
|
||||
target = base + path
|
||||
resp = fetch(session, "GET", target)
|
||||
return _verdict(
|
||||
("exposure", f"error-body:{path}", target), resp,
|
||||
bool(TRACE_MARKERS.search(resp.body)),
|
||||
("error body carries a stack trace or an internal path",
|
||||
"error body carries no trace marker"))
|
||||
|
||||
|
||||
def _error_paths(cfg):
|
||||
random_path = "/guardrails-probe-" + os.urandom(6).hex()
|
||||
return [random_path] + list(cfg.get("error_routes") or [])
|
||||
|
||||
|
||||
def _keys(data):
|
||||
"""Every string key of the whole body, walked without recursion."""
|
||||
found, stack = [], [data]
|
||||
while stack:
|
||||
node = stack.pop()
|
||||
if isinstance(node, dict):
|
||||
found += [k for k in node if isinstance(k, str)]
|
||||
stack += node.values()
|
||||
elif isinstance(node, list):
|
||||
stack += node
|
||||
return found
|
||||
|
||||
|
||||
def _snake(key):
|
||||
return re.sub(r"(?<=[a-z0-9])(?=[A-Z])", "_", key).replace("-", "_").lower()
|
||||
|
||||
|
||||
def _sensitive_keys(data):
|
||||
return sorted({k for k in _keys(data) if SENSITIVE_KEY.search(_snake(k))})
|
||||
|
||||
|
||||
def _key_note(keys):
|
||||
"""Identifier-shaped key names only; anything else is counted."""
|
||||
shown = [k for k in keys if IDENT.fullmatch(k)]
|
||||
hidden = len(keys) - len(shown)
|
||||
return ", ".join(shown) + (f" (+{hidden} unprintable)" if hidden else "")
|
||||
|
||||
|
||||
def _json_body(resp):
|
||||
try:
|
||||
return json.loads(resp.body), True
|
||||
except (ValueError, RecursionError):
|
||||
return None, False
|
||||
|
||||
|
||||
def _fields_verdict(resp):
|
||||
if resp.error:
|
||||
return "ERROR", resp.error
|
||||
data, is_json = _json_body(resp)
|
||||
if resp.status != 200 or not is_json:
|
||||
return "SKIPPED", f"HTTP {resp.status}: no JSON body to read"
|
||||
keys = _sensitive_keys(data)
|
||||
if keys:
|
||||
return "OPEN", "response carries sensitive keys: " + _key_note(keys)
|
||||
return "CLOSED", "no sensitive key in the response"
|
||||
|
||||
|
||||
def _bearer():
|
||||
token = os.environ.get("GUARDRAILS_JWT2")
|
||||
return {"Authorization": f"Bearer {token}"} if token else None
|
||||
|
||||
|
||||
def _fields_probe(session, base, route):
|
||||
target = base + route["path"]
|
||||
verdict, note = _fields_verdict(fetch(session, "GET", target, _bearer()))
|
||||
return Probe("exposure", f"fields:{route['path']}", verdict, target, note)
|
||||
|
||||
|
||||
def probe_exposure(session, plan):
|
||||
cfg = plan.get("exposure")
|
||||
if cfg is None:
|
||||
return []
|
||||
base = plan["base_url"].rstrip("/")
|
||||
out = _sourcemaps(session, base, cfg)
|
||||
out += [_error_probe(session, base, p) for p in _error_paths(cfg)]
|
||||
out += [_fields_probe(session, base, r) for r in plan.get("routes") or []]
|
||||
return out
|
||||
|
||||
|
||||
PROBES = (probe_supabase, probe_cross_user, probe_routes,
|
||||
probe_cors, probe_rate_limit)
|
||||
probe_cors, probe_exposure, probe_rate_limit)
|
||||
|
||||
|
||||
def run_probes(session, plan):
|
||||
@@ -235,9 +447,15 @@ 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} {probe.id} "
|
||||
f"{probe.target}\n {probe.message}")
|
||||
return (f" {probe.verdict:<8} {probe.domain:<9} "
|
||||
f"{_printable(probe.id)} {_printable(probe.target)}\n"
|
||||
f" {_printable(probe.message)}")
|
||||
|
||||
|
||||
def _summary(results):
|
||||
@@ -248,7 +466,7 @@ def _summary(results):
|
||||
|
||||
def _render_text(plan, results):
|
||||
body = [_probe_row(p) for p in results]
|
||||
head = [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)])
|
||||
|
||||
@@ -261,21 +479,82 @@ def _render_json(plan, results):
|
||||
}, indent=2)
|
||||
|
||||
|
||||
def _http_url(value):
|
||||
if not isinstance(value, str):
|
||||
return False
|
||||
try:
|
||||
parts = urlsplit(value)
|
||||
except ValueError:
|
||||
return False
|
||||
return parts.scheme in ("http", "https") and bool(parts.netloc)
|
||||
|
||||
|
||||
def _load_plan(path):
|
||||
try:
|
||||
plan = json.loads(open(path, encoding="utf-8").read())
|
||||
except (OSError, ValueError) as exc:
|
||||
return None, f"cannot read plan: {exc}"
|
||||
if not isinstance(plan, dict) or not plan.get("base_url"):
|
||||
return None, "plan needs an object with a base_url"
|
||||
if not isinstance(plan, dict) or not _http_url(plan.get("base_url")):
|
||||
return None, "plan needs an object with an http(s) base_url"
|
||||
return plan, ""
|
||||
|
||||
|
||||
def _obj(plan, key):
|
||||
value = plan.get(key)
|
||||
return value if isinstance(value, dict) else {}
|
||||
|
||||
|
||||
def _plan_paths(plan):
|
||||
"""Every path the probe would append to base_url (None when malformed)."""
|
||||
routes = plan.get("routes") or []
|
||||
cfg, supa, rate = _obj(plan, "exposure"), _obj(plan, "supabase"), \
|
||||
_obj(plan, "rate_limit")
|
||||
return ([r.get("path") if isinstance(r, dict) else None for r in routes]
|
||||
+ list(supa.get("cross_user_paths") or [])
|
||||
+ [plan.get("cors_path", "/"), rate.get("path", "/")]
|
||||
+ list(cfg.get("scripts") or [])
|
||||
+ list(cfg.get("error_routes") or []))
|
||||
|
||||
|
||||
def _exposure_error(cfg):
|
||||
if cfg is None:
|
||||
return ""
|
||||
if not isinstance(cfg, dict):
|
||||
return "exposure must be an object"
|
||||
for key in ("scripts", "error_routes"):
|
||||
if cfg.get(key) is not None and not isinstance(cfg[key], list):
|
||||
return f"exposure.{key} must be a list"
|
||||
return ""
|
||||
|
||||
|
||||
def _shape_error(plan):
|
||||
rate = plan.get("rate_limit", {})
|
||||
if not isinstance(rate, dict):
|
||||
return "rate_limit must be an object"
|
||||
if rate and not isinstance(rate.get("path"), str):
|
||||
return "rate_limit.path must be a string"
|
||||
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 ""
|
||||
|
||||
|
||||
def _plan_error(plan):
|
||||
method = plan.get("rate_limit", {}).get("method", "GET").upper()
|
||||
method = str(_obj(plan, "rate_limit").get("method", "GET")).upper()
|
||||
if method not in READ_METHODS and method != "POST":
|
||||
return f"rate_limit method {method} is not a probe method"
|
||||
return ""
|
||||
error = _exposure_error(plan.get("exposure")) or _shape_error(plan)
|
||||
if error:
|
||||
return error
|
||||
bad = [p for p in _plan_paths(plan)
|
||||
if not isinstance(p, str) or not p.startswith("/")]
|
||||
return f"plan path {bad[0]!r} must start with /" if bad else ""
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
@@ -297,7 +576,8 @@ def main(argv):
|
||||
return 2
|
||||
if not args.authorized:
|
||||
print("refused: pass --authorized to confirm you own "
|
||||
f"{plan['base_url']} and may probe it", file=sys.stderr)
|
||||
f"{_printable(plan['base_url'])} and may probe it",
|
||||
file=sys.stderr)
|
||||
return 2
|
||||
results = run_probes(Session(), plan)
|
||||
render = _render_json if args.json else _render_text
|
||||
|
||||
@@ -1,251 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Static guardrails scan: API, hosting, a11y, Supabase, messaging, functions.
|
||||
"""Static guardrails scan: API, hosting, Supabase, messaging, functions,
|
||||
injection, exposure.
|
||||
|
||||
Reads a project tree as data and never executes it. Exit codes:
|
||||
0 no FAIL, 1 at least one FAIL, 2 usage error.
|
||||
|
||||
Two check modes replace the report and its exit code:
|
||||
--assert-absent RULE:path,... exit 0 and print GUARDRAILS-CLEAR only when
|
||||
none of these FAIL/WARN pairs remain (a fix contract's oracle);
|
||||
--baseline before.json compare with an earlier --json run, exit 0 and
|
||||
print GUARDRAILS-NO-NEW only when no FAIL/WARN hit appeared.
|
||||
See scanner.py for the modes and exit codes.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from collections import Counter
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from checks import a11y, apis, functions, hosting, messaging, supabase
|
||||
from checks.common import Project
|
||||
|
||||
DOMAINS = {
|
||||
"api": apis,
|
||||
"hosting": hosting,
|
||||
"a11y": a11y,
|
||||
"supabase": supabase,
|
||||
"messaging": messaging,
|
||||
"functions": functions,
|
||||
}
|
||||
SEVERITY_RANK = {"FAIL": 0, "WARN": 1, "MANUAL": 2}
|
||||
RULE_DOMAINS = {
|
||||
"API": "api", "HOST": "hosting", "A11Y": "a11y", "SB": "supabase",
|
||||
"MSG": "messaging", "FN": "functions",
|
||||
}
|
||||
MANUAL_RULES = {
|
||||
"HOST-WAF-DDOS", "HOST-SPEND-CAP", "SB-RLS-LIVE", "FN-CAP-UNVERIFIED",
|
||||
"FN-BUDGET-STOP",
|
||||
}
|
||||
GATED = ("FAIL", "WARN")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Result:
|
||||
findings: list
|
||||
applicable: list
|
||||
skipped: list
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("path", help="project root to scan")
|
||||
parser.add_argument(
|
||||
"--domain", default=",".join(DOMAINS),
|
||||
help="comma list among: " + ", ".join(DOMAINS))
|
||||
parser.add_argument(
|
||||
"--exclude", default="",
|
||||
help="comma list of relative paths to skip (copies, vendored code)")
|
||||
parser.add_argument("--json", action="store_true", help="JSON output")
|
||||
parser.add_argument(
|
||||
"--assert-absent", default="", metavar="RULE:path,...",
|
||||
help="contract oracle: pass only when these pairs are gone")
|
||||
parser.add_argument(
|
||||
"--baseline", default="", metavar="JSON",
|
||||
help="earlier --json run: report fixed, remaining and new hits")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def _split(value):
|
||||
return [part.strip() for part in value.split(",") if part.strip()]
|
||||
|
||||
|
||||
def run_checks(project, names):
|
||||
findings, applicable, skipped = [], [], []
|
||||
for name in names:
|
||||
module = DOMAINS[name]
|
||||
if module.applies(project):
|
||||
applicable.append(name)
|
||||
findings += module.check(project)
|
||||
else:
|
||||
skipped.append(name)
|
||||
findings.sort(key=lambda f: (
|
||||
SEVERITY_RANK[f.severity], f.domain, f.path, f.line))
|
||||
return Result(findings, applicable, skipped)
|
||||
|
||||
|
||||
def summarize(findings):
|
||||
return {sev: sum(f.severity == sev for f in findings)
|
||||
for sev in SEVERITY_RANK}
|
||||
|
||||
|
||||
def _domain_lines(domain, findings):
|
||||
rows = [f for f in findings if f.domain == domain]
|
||||
return [f"\n[{domain}]"] + (
|
||||
[f" {f.severity:<6} {f.rule:<24} {f.path}:{f.line} {f.message}"
|
||||
for f in rows] or [" no finding"])
|
||||
|
||||
|
||||
def _summary_line(findings):
|
||||
totals = summarize(findings)
|
||||
return "\nsummary: " + ", ".join(
|
||||
f"{n} {sev}" for sev, n in totals.items())
|
||||
|
||||
|
||||
def render_text(project, result):
|
||||
lines = [
|
||||
f"guardrails scan: {project.root} ({len(project.files)} files)",
|
||||
"scanned: " + (", ".join(result.applicable) or "none"),
|
||||
]
|
||||
if result.skipped:
|
||||
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)])
|
||||
|
||||
|
||||
def render_json(project, result):
|
||||
return json.dumps({
|
||||
"root": str(project.root), "files": len(project.files),
|
||||
"applicable": result.applicable, "not_applicable": result.skipped,
|
||||
"summary": summarize(result.findings),
|
||||
"findings": [f.as_dict() for f in result.findings],
|
||||
}, indent=2)
|
||||
|
||||
|
||||
def _rule_domain(rule):
|
||||
return RULE_DOMAINS.get(rule.split("-", 1)[0])
|
||||
|
||||
|
||||
def _pairs(value):
|
||||
"""'RULE:path,RULE:path' -> [(rule, path)]; a missing path stays ''."""
|
||||
return [tuple(p.strip() for p in item.partition(":")[::2])
|
||||
for item in _split(value)]
|
||||
|
||||
|
||||
def _assert_error(value):
|
||||
for rule, path in _pairs(value):
|
||||
if not path or not _rule_domain(rule):
|
||||
return f"bad --assert-absent item {rule}:{path}, want RULE:path"
|
||||
if rule in MANUAL_RULES:
|
||||
return f"{rule} is MANUAL: no static scan can prove it fixed"
|
||||
return ""
|
||||
|
||||
|
||||
def _hits(findings):
|
||||
return Counter((f.rule, f.path) for f in findings if f.severity in GATED)
|
||||
|
||||
|
||||
def _load_baseline(path):
|
||||
data = json.loads(Path(path).read_text(encoding="utf-8"))
|
||||
return Counter((f["rule"], f["path"]) for f in data["findings"]
|
||||
if f["severity"] in GATED)
|
||||
|
||||
|
||||
def _baseline_error(path):
|
||||
if not path:
|
||||
return ""
|
||||
try:
|
||||
_load_baseline(path)
|
||||
except (OSError, ValueError, KeyError, TypeError) as exc:
|
||||
return f"unreadable baseline {path}: {exc}"
|
||||
return ""
|
||||
|
||||
|
||||
def _usage_error(args):
|
||||
unknown = [n for n in _split(args.domain) if n not in DOMAINS]
|
||||
if unknown:
|
||||
return f"unknown domain {unknown}"
|
||||
if not Path(args.path).is_dir():
|
||||
return f"not a directory: {args.path}"
|
||||
return _assert_error(args.assert_absent) or _baseline_error(args.baseline)
|
||||
|
||||
|
||||
def _pair_status(hits, applicable, pair):
|
||||
rule, path = pair
|
||||
if _rule_domain(rule) not in applicable:
|
||||
return False, f" CONTROL {rule} {path}: domain not scanned, " \
|
||||
"absence proves nothing"
|
||||
if hits[pair]:
|
||||
plural = "s" if hits[pair] > 1 else ""
|
||||
return False, f" PRESENT {rule} {path} ({hits[pair]} hit{plural})"
|
||||
return True, f" CLEAR {rule} {path}"
|
||||
|
||||
|
||||
def assert_absent(project, result, pairs):
|
||||
"""Positive control first: an empty tree or an unscanned domain fails."""
|
||||
rows = [_pair_status(_hits(result.findings), result.applicable, p)
|
||||
for p in pairs]
|
||||
lines = [text for _, text in rows]
|
||||
if not project.files:
|
||||
lines.insert(0, " CONTROL no file scanned, absence proves nothing")
|
||||
ok = bool(project.files) and all(passed for passed, _ in rows)
|
||||
return ok, lines + ([f"GUARDRAILS-CLEAR {len(pairs)}"] if ok else [])
|
||||
|
||||
|
||||
def _moved(more, less):
|
||||
"""Pairs where `more` holds extra hits over `less`, with the surplus."""
|
||||
return [(key, more[key] - less[key]) for key in sorted(more)
|
||||
if more[key] > less[key]]
|
||||
|
||||
|
||||
def _rows(tag, moved, sign):
|
||||
return [f" {tag:<5} {rule} {path} ({sign}{n})"
|
||||
for (rule, path), n in moved]
|
||||
|
||||
|
||||
def baseline_report(before, result):
|
||||
after = _hits(result.findings)
|
||||
fixed, new = _moved(before, after), _moved(after, before)
|
||||
summary = (f"baseline: {sum(n for _, n in fixed)} fixed, "
|
||||
f"{sum((before & after).values())} remaining, "
|
||||
f"{sum(n for _, n in new)} new")
|
||||
lines = _rows("FIXED", fixed, "-") + _rows("NEW", new, "+") + [summary]
|
||||
return not new, lines + ([] if new else ["GUARDRAILS-NO-NEW"])
|
||||
|
||||
|
||||
def _check_modes(project, result, args):
|
||||
checks = []
|
||||
if args.assert_absent:
|
||||
checks.append(
|
||||
assert_absent(project, result, _pairs(args.assert_absent)))
|
||||
if args.baseline:
|
||||
checks.append(
|
||||
baseline_report(_load_baseline(args.baseline), result))
|
||||
return checks
|
||||
|
||||
|
||||
def _scan(args):
|
||||
project = Project(Path(args.path), _split(args.exclude))
|
||||
result = run_checks(project, _split(args.domain))
|
||||
checks = _check_modes(project, result, args)
|
||||
if not checks:
|
||||
render = render_json if args.json else render_text
|
||||
print(render(project, result))
|
||||
return 1 if any(f.severity == "FAIL" for f in result.findings) else 0
|
||||
for _, lines in checks:
|
||||
print("\n".join(lines))
|
||||
return 0 if all(ok for ok, _ in checks) else 1
|
||||
|
||||
|
||||
def main(argv):
|
||||
args = parse_args(argv)
|
||||
error = _usage_error(args)
|
||||
if error:
|
||||
print(f"usage error: {error}", file=sys.stderr)
|
||||
return 2
|
||||
return _scan(args)
|
||||
import scanner
|
||||
from checks import (
|
||||
apis, exposure, functions, hosting, injection, messaging, supabase,
|
||||
)
|
||||
|
||||
CATALOGUE = scanner.Catalogue(
|
||||
name="guardrails",
|
||||
domains={
|
||||
"api": apis,
|
||||
"hosting": hosting,
|
||||
"supabase": supabase,
|
||||
"messaging": messaging,
|
||||
"functions": functions,
|
||||
"injection": injection,
|
||||
"exposure": exposure,
|
||||
},
|
||||
rule_domains={
|
||||
"API": "api", "HOST": "hosting", "SB": "supabase",
|
||||
"MSG": "messaging", "FN": "functions",
|
||||
"INJ": "injection", "EXP": "exposure",
|
||||
},
|
||||
manual_rules=frozenset({
|
||||
"HOST-WAF-DDOS", "HOST-SPEND-CAP", "SB-RLS-LIVE",
|
||||
"FN-CAP-UNVERIFIED", "FN-BUDGET-STOP",
|
||||
}),
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
sys.exit(scanner.main(sys.argv[1:], CATALOGUE))
|
||||
@@ -0,0 +1,249 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Static scan engine shared by the guardrails and a11y scanners.
|
||||
|
||||
A Catalogue names the check modules, the rule prefixes and the MANUAL
|
||||
rules; its name gives the report title and the markers the check modes
|
||||
print. The engine reads a project tree as data and never executes it.
|
||||
Exit codes: 0 no FAIL, 1 at least one FAIL, 2 usage error.
|
||||
|
||||
Two check modes replace the report and its exit code:
|
||||
--assert-absent RULE:path,... exit 0 and print <NAME>-CLEAR only when
|
||||
none of these FAIL/WARN pairs remain (a fix contract's oracle);
|
||||
--baseline before.json compare with an earlier --json run, exit 0 and
|
||||
print <NAME>-NO-NEW only when no FAIL/WARN hit appeared.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from collections import Counter
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from checks.common import Project
|
||||
|
||||
SEVERITY_RANK = {"FAIL": 0, "WARN": 1, "MANUAL": 2}
|
||||
GATED = ("FAIL", "WARN")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Catalogue:
|
||||
"""What one scanner CLI exposes."""
|
||||
name: str # report title and marker prefix (upper-cased)
|
||||
domains: dict # ordered: domain name -> check module
|
||||
rule_domains: dict # rule prefix (before the first '-') -> domain
|
||||
manual_rules: frozenset = frozenset()
|
||||
|
||||
@property
|
||||
def marker(self):
|
||||
return self.name.upper()
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Result:
|
||||
findings: list
|
||||
applicable: list
|
||||
skipped: list
|
||||
|
||||
|
||||
def parse_args(argv, cat):
|
||||
parser = argparse.ArgumentParser(
|
||||
description=f"{cat.name} static scan: reads the tree, runs nothing")
|
||||
parser.add_argument("path", help="project root to scan")
|
||||
parser.add_argument(
|
||||
"--domain", default=",".join(cat.domains),
|
||||
help="comma list among: " + ", ".join(cat.domains))
|
||||
parser.add_argument(
|
||||
"--exclude", default="",
|
||||
help="comma list of relative paths to skip (copies, vendored code)")
|
||||
parser.add_argument("--json", action="store_true", help="JSON output")
|
||||
parser.add_argument(
|
||||
"--assert-absent", default="", metavar="RULE:path,...",
|
||||
help="contract oracle: pass only when these pairs are gone")
|
||||
parser.add_argument(
|
||||
"--baseline", default="", metavar="JSON",
|
||||
help="earlier --json run: report fixed, remaining and new hits")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def _split(value):
|
||||
return [part.strip() for part in value.split(",") if part.strip()]
|
||||
|
||||
|
||||
def run_checks(project, cat, names):
|
||||
findings, applicable, skipped = [], [], []
|
||||
for name in names:
|
||||
module = cat.domains[name]
|
||||
if module.applies(project):
|
||||
applicable.append(name)
|
||||
findings += module.check(project)
|
||||
else:
|
||||
skipped.append(name)
|
||||
findings.sort(key=lambda f: (
|
||||
SEVERITY_RANK[f.severity], f.domain, f.path, f.line))
|
||||
return Result(findings, applicable, skipped)
|
||||
|
||||
|
||||
def summarize(findings):
|
||||
return {sev: sum(f.severity == sev for f in findings)
|
||||
for sev in SEVERITY_RANK}
|
||||
|
||||
|
||||
def _domain_lines(domain, findings):
|
||||
rows = [f for f in findings if f.domain == domain]
|
||||
return [f"\n[{domain}]"] + (
|
||||
[f" {f.severity:<6} {f.rule:<24} {f.path}:{f.line} {f.message}"
|
||||
for f in rows] or [" no finding"])
|
||||
|
||||
|
||||
def _summary_line(findings):
|
||||
totals = summarize(findings)
|
||||
return "\nsummary: " + ", ".join(
|
||||
f"{n} {sev}" for sev, n in totals.items())
|
||||
|
||||
|
||||
def render_text(project, cat, result):
|
||||
lines = [
|
||||
f"{cat.name} scan: {project.root} ({len(project.files)} files)",
|
||||
"scanned: " + (", ".join(result.applicable) or "none"),
|
||||
]
|
||||
if result.skipped:
|
||||
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)])
|
||||
|
||||
|
||||
def render_json(project, result):
|
||||
return json.dumps({
|
||||
"root": str(project.root), "files": len(project.files),
|
||||
"applicable": result.applicable, "not_applicable": result.skipped,
|
||||
"summary": summarize(result.findings),
|
||||
"findings": [f.as_dict() for f in result.findings],
|
||||
}, indent=2)
|
||||
|
||||
|
||||
def _rule_domain(cat, rule):
|
||||
return cat.rule_domains.get(rule.split("-", 1)[0])
|
||||
|
||||
|
||||
def _pairs(value):
|
||||
"""'RULE:path,RULE:path' -> [(rule, path)]; a missing path stays ''."""
|
||||
return [tuple(p.strip() for p in item.partition(":")[::2])
|
||||
for item in _split(value)]
|
||||
|
||||
|
||||
def _assert_error(cat, value):
|
||||
for rule, path in _pairs(value):
|
||||
if not path or not _rule_domain(cat, rule):
|
||||
return f"bad --assert-absent item {rule}:{path}, want RULE:path"
|
||||
if rule in cat.manual_rules:
|
||||
return f"{rule} is MANUAL: no static scan can prove it fixed"
|
||||
return ""
|
||||
|
||||
|
||||
def _hits(findings):
|
||||
return Counter((f.rule, f.path) for f in findings if f.severity in GATED)
|
||||
|
||||
|
||||
def _load_baseline(path):
|
||||
data = json.loads(Path(path).read_text(encoding="utf-8"))
|
||||
return Counter((f["rule"], f["path"]) for f in data["findings"]
|
||||
if f["severity"] in GATED)
|
||||
|
||||
|
||||
def _baseline_error(path):
|
||||
if not path:
|
||||
return ""
|
||||
try:
|
||||
_load_baseline(path)
|
||||
except (OSError, ValueError, KeyError, TypeError) as exc:
|
||||
return f"unreadable baseline {path}: {exc}"
|
||||
return ""
|
||||
|
||||
|
||||
def _usage_error(cat, args):
|
||||
unknown = [n for n in _split(args.domain) if n not in cat.domains]
|
||||
if unknown:
|
||||
return f"unknown domain {unknown}"
|
||||
if not Path(args.path).is_dir():
|
||||
return f"not a directory: {args.path}"
|
||||
return (_assert_error(cat, args.assert_absent)
|
||||
or _baseline_error(args.baseline))
|
||||
|
||||
|
||||
def _pair_status(cat, hits, applicable, pair):
|
||||
rule, path = pair
|
||||
if _rule_domain(cat, rule) not in applicable:
|
||||
return False, f" CONTROL {rule} {path}: domain not scanned, " \
|
||||
"absence proves nothing"
|
||||
if hits[pair]:
|
||||
plural = "s" if hits[pair] > 1 else ""
|
||||
return False, f" PRESENT {rule} {path} ({hits[pair]} hit{plural})"
|
||||
return True, f" CLEAR {rule} {path}"
|
||||
|
||||
|
||||
def assert_absent(project, cat, result, pairs):
|
||||
"""Positive control first: an empty tree or an unscanned domain fails."""
|
||||
hits = _hits(result.findings)
|
||||
rows = [_pair_status(cat, hits, result.applicable, p) for p in pairs]
|
||||
lines = [text for _, text in rows]
|
||||
if not project.files:
|
||||
lines.insert(0, " CONTROL no file scanned, absence proves nothing")
|
||||
ok = bool(project.files) and all(passed for passed, _ in rows)
|
||||
marker = [f"{cat.marker}-CLEAR {len(pairs)}"] if ok else []
|
||||
return ok, lines + marker
|
||||
|
||||
|
||||
def _moved(more, less):
|
||||
"""Pairs where `more` holds extra hits over `less`, with the surplus."""
|
||||
return [(key, more[key] - less[key]) for key in sorted(more)
|
||||
if more[key] > less[key]]
|
||||
|
||||
|
||||
def _rows(tag, moved, sign):
|
||||
return [f" {tag:<5} {rule} {path} ({sign}{n})"
|
||||
for (rule, path), n in moved]
|
||||
|
||||
|
||||
def baseline_report(cat, before, result):
|
||||
after = _hits(result.findings)
|
||||
fixed, new = _moved(before, after), _moved(after, before)
|
||||
summary = (f"baseline: {sum(n for _, n in fixed)} fixed, "
|
||||
f"{sum((before & after).values())} remaining, "
|
||||
f"{sum(n for _, n in new)} new")
|
||||
lines = _rows("FIXED", fixed, "-") + _rows("NEW", new, "+") + [summary]
|
||||
return not new, lines + ([] if new else [f"{cat.marker}-NO-NEW"])
|
||||
|
||||
|
||||
def _check_modes(project, cat, result, args):
|
||||
checks = []
|
||||
if args.assert_absent:
|
||||
checks.append(
|
||||
assert_absent(project, cat, result, _pairs(args.assert_absent)))
|
||||
if args.baseline:
|
||||
checks.append(
|
||||
baseline_report(cat, _load_baseline(args.baseline), result))
|
||||
return checks
|
||||
|
||||
|
||||
def _scan(cat, args):
|
||||
project = Project(Path(args.path), _split(args.exclude))
|
||||
result = run_checks(project, cat, _split(args.domain))
|
||||
checks = _check_modes(project, cat, result, args)
|
||||
if not checks:
|
||||
text = (render_json(project, result) if args.json
|
||||
else render_text(project, cat, result))
|
||||
print(text)
|
||||
return 1 if any(f.severity == "FAIL" for f in result.findings) else 0
|
||||
for _, lines in checks:
|
||||
print("\n".join(lines))
|
||||
return 0 if all(ok for ok, _ in checks) else 1
|
||||
|
||||
|
||||
def main(argv, cat):
|
||||
args = parse_args(argv, cat)
|
||||
error = _usage_error(cat, args)
|
||||
if error:
|
||||
print(f"usage error: {error}", file=sys.stderr)
|
||||
return 2
|
||||
return _scan(cat, args)
|
||||
@@ -4,5 +4,7 @@
|
||||
{"id": 3, "prompt": "Audit my Firebase functions: can any of them loop on itself or run up the bill?", "expected": "Scans functions domain only, reports max instances status and any trigger that writes its own collection, MANUAL item for a budget alert wired to an automatic stop, no live call to the provider"},
|
||||
{"id": 4, "prompt": "est-ce que les mots de passe sont stockés en clair quelque part dans ~/Documents/zenquality ?", "expected": "Runs the scanner's api domain, reads every API-PASSWORD-* hit in context, traces the sign-up and password-change write points to the password_hash column by hand, names the hashing function found, reports with file:line, fixes nothing"},
|
||||
{"id": 5, "prompt": "teste les garde-fous sur ~/Documents/game puis sonde-le en direct, le dev tourne sur http://localhost:5173", "expected": "Runs the static scan first, then builds a probe plan from the findings, exports test keys from the environment, runs probe.py --authorized against the localhost target only, reports OPEN verdicts next to the matching static FAIL, never writes data, never probes a target the user did not name"},
|
||||
{"id": 6, "prompt": "corrige les garde-fous qui échouent sur ~/Documents/faunosteo, je veux valider chaque correction avant", "expected": "Scans and judges, proposes numbered fixes with risks and visible choices, stops for approval, applies only the accepted ones on a bugfix branch through a contract whose oracles are scan.py --assert-absent, runs the verify-secure gates, re-scans against the baseline, reports fixed and still open, waits for a go before committing"}
|
||||
{"id": 6, "prompt": "corrige les garde-fous qui échouent sur ~/Documents/faunosteo, je veux valider chaque correction avant", "expected": "Scans and judges, proposes numbered fixes with risks and visible choices, stops for approval, applies only the accepted ones on a bugfix branch through a contract whose oracles are scan.py --assert-absent, runs the verify-secure gates, re-scans against the baseline, reports fixed and still open, waits for a go before committing"},
|
||||
{"id": 7, "prompt": "cherche les failles d'injection SQL dans ~/Documents/zenquality", "expected": "Runs the scanner's injection domain, traces each INJ hit to the source of the interpolated value, labels constants and cast values FALSE POSITIVE, proposes parameterized rewrites with the binding as a visible choice, applies only after acceptance with --assert-absent oracles"},
|
||||
{"id": 8, "prompt": "est-ce que mon site laisse voir trop de choses dans le navigateur ? console, network, inspecteur", "expected": "Runs the exposure domain, reads each EXP hit in context, offers the live probe with an exposure block against a production build the user names, reports source maps served, error bodies and sensitive keys next to the static findings, never prints a response value, marks dev-server OPENs as dev artefacts"}
|
||||
]
|
||||
@@ -354,7 +354,7 @@ Agent(
|
||||
- Legal pages (mentions légales, CGV, privacy) — unless the issue is
|
||||
a security-header gap on those pages, not their content
|
||||
- Content quality, keyword density, readability
|
||||
- a11y / WCAG (owned by /web-validate — W3C + WCAG audit)
|
||||
- WCAG conformance (owned by /web-validate) and the keyboard, alt and label baseline (owned by /a11y)
|
||||
- W3C HTML / CSS syntactic validity (owned by /web-validate)
|
||||
|
||||
If you detect an out-of-scope issue, DROP IT silently. Do NOT mention
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ description: |
|
||||
geo-analyzer concurrently, merges into .claude/audits/SEO.md.
|
||||
Triggers: "seo", "referencement", "meta tags", "JSON-LD", "sitemap",
|
||||
"robots.txt", "local SEO", "llms.txt", "ChatGPT visibility".
|
||||
GEO only → /geo. W3C/a11y → /web-validate. Bugs → /bugfix.
|
||||
GEO only → /geo. W3C/WCAG → /web-validate; keyboard, alt, labels →
|
||||
/a11y. Bugs → /bugfix.
|
||||
argument-hint: optional keywords/scope, e.g. "local SEO plombier 91 94 77" or "SaaS B2B content strategy"
|
||||
allowed-tools:
|
||||
- Read
|
||||
|
||||
@@ -3,10 +3,11 @@ name: web-validate
|
||||
effort: high
|
||||
description: |
|
||||
Use when a web project needs W3C HTML/CSS validity or WCAG 2.1
|
||||
accessibility audit. Dispatches the validator-analyzer agent, strict
|
||||
conformance audit. Dispatches the validator-analyzer agent, strict
|
||||
scope (no meta/security-header noise).
|
||||
Triggers: "validate", "w3c", "wcag", "a11y", "accessibility", "axe",
|
||||
"pa11y", "accessibilité", "conformité web".
|
||||
Triggers: "validate", "w3c", "wcag", "conformité wcag", "axe",
|
||||
"pa11y", "conformité web", "validité html".
|
||||
Keyboard, alt and label basics and their fixes → /a11y.
|
||||
CSP/HSTS/404 → /harden. Meta/sitemap → /seo. AI engines → /geo.
|
||||
argument-hint: "[URL] [--fix] [--local|--full] [--no-external]"
|
||||
allowed-tools:
|
||||
|
||||
Reference in new issue
Block a user