@ericrisco/rsc 4.0.5 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/manifest.json +78 -84
- package/package.json +1 -1
- package/scripts/lib/default-skill-floor.js +5 -1
- package/scripts/lib/domains.js +1 -1
- package/scripts/lib/recommend.js +1 -1
- package/scripts/lib/retired-skills.js +4 -0
- package/scripts/skill-migration-brief.md +1 -1
- package/scripts/verify.sh +20 -0
- package/skills/accessibility/evals/README.md +1 -1
- package/skills/accessibility/evals/cases.yaml +1 -1
- package/skills/agent-safety/SKILL.md +2 -2
- package/skills/agent-safety/evals/README.md +1 -1
- package/skills/agent-safety/evals/cases.yaml +1 -1
- package/skills/analyze/evals/README.md +1 -1
- package/skills/analyze/evals/cases.yaml +2 -2
- package/skills/angular/SKILL.md +1 -1
- package/skills/api-connector-builder/SKILL.md +1 -1
- package/skills/api-design/SKILL.md +3 -3
- package/skills/api-design/evals/cases.yaml +1 -1
- package/skills/automation-strategy/SKILL.md +1 -1
- package/skills/automation-strategy/evals/README.md +1 -1
- package/skills/automation-strategy/evals/cases.yaml +2 -2
- package/skills/automation-strategy/references/orchestration-and-antipatterns.md +1 -1
- package/skills/aws-essentials/SKILL.md +3 -3
- package/skills/aws-essentials/evals/cases.yaml +2 -2
- package/skills/backups/SKILL.md +2 -2
- package/skills/backups/evals/cases.yaml +2 -2
- package/skills/bash-scripting/SKILL.md +1 -1
- package/skills/building-agents/SKILL.md +2 -2
- package/skills/building-agents/evals/cases.yaml +2 -2
- package/skills/chrome-extension/SKILL.md +1 -1
- package/skills/cloudflare/SKILL.md +1 -1
- package/skills/code-review/SKILL.md +2 -2
- package/skills/code-review/evals/cases.yaml +2 -2
- package/skills/compliance/SKILL.md +3 -3
- package/skills/compliance/evals/cases.yaml +1 -1
- package/skills/constitution/SKILL.md +2 -2
- package/skills/constitution/evals/README.md +2 -2
- package/skills/constitution/evals/cases.yaml +2 -2
- package/skills/constitution/references/constitution-template.md +1 -1
- package/skills/cpp/SKILL.md +2 -2
- package/skills/cpp/evals/README.md +1 -1
- package/skills/cpp/evals/cases.yaml +2 -2
- package/skills/csharp-dotnet/SKILL.md +3 -3
- package/skills/csharp-dotnet/evals/cases.yaml +1 -1
- package/skills/csharp-dotnet/references/aspnetcore.md +1 -1
- package/skills/data-policy/SKILL.md +2 -2
- package/skills/data-policy/evals/README.md +1 -1
- package/skills/data-policy/evals/cases.yaml +1 -1
- package/skills/debug/SKILL.md +1 -1
- package/skills/debug/evals/README.md +1 -1
- package/skills/decision-challenge/SKILL.md +2 -2
- package/skills/decision-challenge/evals/cases.yaml +1 -1
- package/skills/deployment/SKILL.md +2 -2
- package/skills/deployment/evals/README.md +1 -1
- package/skills/deployment/evals/cases.yaml +2 -2
- package/skills/django/SKILL.md +2 -2
- package/skills/django/evals/README.md +1 -1
- package/skills/django/evals/cases.yaml +1 -1
- package/skills/django/references/security.md +1 -1
- package/skills/docker/SKILL.md +3 -3
- package/skills/docker/evals/cases.yaml +1 -1
- package/skills/dynamodb/SKILL.md +2 -2
- package/skills/electron/SKILL.md +1 -1
- package/skills/electron/references/packaging-and-updates.md +1 -1
- package/skills/email-connector/SKILL.md +2 -2
- package/skills/email-deliverability/SKILL.md +1 -1
- package/skills/error-handling/SKILL.md +1 -1
- package/skills/expo/SKILL.md +2 -2
- package/skills/fastapi/SKILL.md +4 -4
- package/skills/fastapi/evals/README.md +2 -2
- package/skills/fastapi/evals/cases.yaml +2 -2
- package/skills/fastapi/references/security.md +2 -2
- package/skills/firebase/SKILL.md +1 -1
- package/skills/flutter/SKILL.md +1 -1
- package/skills/flutter/evals/cases.yaml +2 -2
- package/skills/fly-io/SKILL.md +1 -1
- package/skills/gamedev-multiplayer/SKILL.md +1 -1
- package/skills/gamedev-multiplayer/evals/README.md +1 -1
- package/skills/gamedev-multiplayer/evals/cases.yaml +2 -2
- package/skills/gamedev-shipping/SKILL.md +1 -1
- package/skills/gcp-essentials/SKILL.md +2 -2
- package/skills/gcp-essentials/evals/README.md +1 -1
- package/skills/gcp-essentials/evals/cases.yaml +2 -2
- package/skills/gdpr-privacy/SKILL.md +2 -2
- package/skills/gdpr-privacy/evals/cases.yaml +1 -1
- package/skills/github-actions/SKILL.md +2 -2
- package/skills/go/SKILL.md +4 -4
- package/skills/go/evals/README.md +1 -1
- package/skills/go/evals/cases.yaml +2 -2
- package/skills/google-workspace/SKILL.md +2 -2
- package/skills/hetzner/SKILL.md +1 -1
- package/skills/htmx/SKILL.md +4 -4
- package/skills/htmx/evals/cases.yaml +2 -2
- package/skills/implement/SKILL.md +1 -1
- package/skills/init/SKILL.md +2 -2
- package/skills/init/evals/cases.yaml +2 -2
- package/skills/init/references/discovery.md +1 -1
- package/skills/init/references/recommend-skills.md +5 -5
- package/skills/java/SKILL.md +3 -3
- package/skills/java/evals/README.md +1 -1
- package/skills/java/evals/cases.yaml +2 -2
- package/skills/laravel/SKILL.md +3 -3
- package/skills/laravel/evals/README.md +1 -1
- package/skills/laravel/evals/cases.yaml +1 -1
- package/skills/marketing/evals/README.md +1 -1
- package/skills/marketing/evals/cases.yaml +1 -1
- package/skills/mongodb/SKILL.md +2 -2
- package/skills/mongodb/evals/README.md +1 -1
- package/skills/mongodb/evals/cases.yaml +2 -2
- package/skills/nextjs/SKILL.md +3 -3
- package/skills/nextjs/evals/cases.yaml +2 -2
- package/skills/nextjs/references/security.md +2 -2
- package/skills/notion-connector/SKILL.md +3 -3
- package/skills/notion-connector/evals/README.md +1 -1
- package/skills/notion-connector/evals/cases.yaml +2 -2
- package/skills/php/SKILL.md +4 -4
- package/skills/php/evals/README.md +1 -1
- package/skills/php/evals/cases.yaml +1 -1
- package/skills/plan/evals/README.md +1 -1
- package/skills/postgresdb/SKILL.md +1 -1
- package/skills/postgresdb/evals/README.md +1 -1
- package/skills/postgresdb/evals/cases.yaml +2 -2
- package/skills/presentations/evals/README.md +1 -1
- package/skills/python/SKILL.md +3 -3
- package/skills/python/evals/README.md +1 -1
- package/skills/python/evals/cases.yaml +2 -2
- package/skills/rag/scripts/verify.sh +1 -1
- package/skills/review/SKILL.md +2 -2
- package/skills/review/evals/cases.yaml +3 -3
- package/skills/ruby/SKILL.md +1 -1
- package/skills/rust/SKILL.md +2 -2
- package/skills/rust/evals/README.md +1 -1
- package/skills/rust/evals/cases.yaml +2 -2
- package/skills/security-audit/SKILL.md +186 -0
- package/skills/security-audit/evals/cases.yaml +95 -0
- package/skills/security-audit/references/auditor-safety.md +69 -0
- package/skills/security-audit/references/classes/README.md +225 -0
- package/skills/security-audit/references/classes/ai-and-llm.md +247 -0
- package/skills/security-audit/references/classes/client-side.md +181 -0
- package/skills/security-audit/references/classes/cloud-and-deployment.md +167 -0
- package/skills/security-audit/references/classes/data-isolation.md +161 -0
- package/skills/security-audit/references/classes/desktop-mobile-ipc.md +167 -0
- package/skills/security-audit/references/classes/memory-and-binary.md +230 -0
- package/skills/security-audit/references/classes/protocols-and-messaging.md +151 -0
- package/skills/security-audit/references/classes/resource-exhaustion.md +141 -0
- package/skills/security-audit/references/classes/supply-chain.md +147 -0
- package/skills/security-audit/references/classes/web-and-auth.md +238 -0
- package/skills/security-audit/references/coverage-ledger.md +172 -0
- package/skills/security-audit/references/fixes-by-stack.md +972 -0
- package/skills/security-audit/references/fixing.md +200 -0
- package/skills/security-audit/references/hunting.md +146 -0
- package/skills/security-audit/references/isolated-execution.md +85 -0
- package/skills/security-audit/references/platforms.md +650 -0
- package/skills/security-audit/references/reconnaissance.md +73 -0
- package/skills/security-audit/references/resuming.md +55 -0
- package/skills/security-audit/references/scanners.md +347 -0
- package/skills/{secure-coding → security-audit}/references/secrets-and-supply-chain.md +78 -34
- package/skills/security-audit/references/secrets-discipline.md +173 -0
- package/skills/{secure-coding → security-audit}/references/threat-modeling.md +80 -32
- package/skills/security-audit/references/verification.md +118 -0
- package/skills/security-audit/schema/findings.schema.json +178 -0
- package/skills/security-audit/scripts/render-report.mjs +311 -0
- package/skills/security-audit/scripts/validate-findings.mjs +508 -0
- package/skills/skill-scout/scripts/verify.sh +1 -1
- package/skills/source-grounded-development/evals/cases.yaml +1 -1
- package/skills/specify/evals/README.md +1 -1
- package/skills/spring-boot/SKILL.md +3 -3
- package/skills/spring-boot/evals/README.md +1 -1
- package/skills/spring-boot/evals/cases.yaml +1 -1
- package/skills/spring-boot/references/security.md +1 -1
- package/skills/stripe/SKILL.md +2 -2
- package/skills/suggest/evals/cases.yaml +2 -2
- package/skills/supabase/SKILL.md +1 -1
- package/skills/tauri/SKILL.md +2 -2
- package/skills/testing-go/SKILL.md +1 -1
- package/skills/typescript/SKILL.md +2 -2
- package/skills/verify/SKILL.md +3 -3
- package/skills/verify/evals/README.md +2 -2
- package/skills/verify/evals/cases.yaml +2 -2
- package/skills/vue-nuxt/SKILL.md +2 -2
- package/skills/webhooks/SKILL.md +2 -2
- package/skills/wordpress/SKILL.md +2 -2
- package/skills/wordpress/evals/README.md +1 -1
- package/skills/wordpress/evals/cases.yaml +1 -1
- package/skills/worktrees/evals/README.md +1 -1
- package/targets/clone-bootstrap.mjs +1 -1
- package/targets/commands.js +1 -1
- package/skills/secure-coding/SKILL.md +0 -336
- package/skills/secure-coding/evals/README.md +0 -68
- package/skills/secure-coding/evals/cases.yaml +0 -55
- package/skills/secure-coding/references/authn-authz.md +0 -249
- package/skills/secure-coding/references/owasp-by-stack.md +0 -574
- package/skills/secure-coding/scripts/verify.sh +0 -208
- package/skills/security-scan/SKILL.md +0 -219
- package/skills/security-scan/evals/README.md +0 -14
- package/skills/security-scan/evals/cases.yaml +0 -50
- package/skills/security-scan/references/tools.md +0 -97
- package/skills/security-scan/references/triage.md +0 -92
- package/skills/security-scan/scripts/verify.sh +0 -108
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Verification
|
|
2
|
+
|
|
3
|
+
How a candidate becomes a finding: a fresh agent tries to refute it, the survivor gets a verdict and (if confirmed) a severity no higher than what was shown, and a second fresh agent checks the final record before anything is reported. Applies to every profile.
|
|
4
|
+
|
|
5
|
+
## Who verifies
|
|
6
|
+
|
|
7
|
+
- **A fresh agent per candidate.** It did not hunt this candidate and has seen no other verifier's conclusion. Its job is to prove the candidate wrong.
|
|
8
|
+
- **A different model when possible.** If the harness lets you choose the model per agent, give the verifier a different model from the hunter's. Shared blind spots are the main way false findings survive. If the choice is not available, note it in the run summary; do not skip verification.
|
|
9
|
+
- **What it receives**, and nothing more: the candidate; the checks and evidence paths of its linked units; the parts of `architecture.md` needed to read the path; the verification rules of the relevant [class](classes/README.md) sections, verbatim; the [isolated execution](isolated-execution.md) rules; the [auditor safety](auditor-safety.md) rule; any prior record with the same id; and the record shapes for the three verdicts.
|
|
10
|
+
- **Its own space**: a new agent id and `<audit-dir>/scratch/<agent-id>/`. It writes nowhere else. It may read the hunter's promoted evidence, but must re-read every cited source location itself and re-run any decisive check it can run safely.
|
|
11
|
+
|
|
12
|
+
Carried prior findings (same source) go through exactly this path, even though hunters were told to skip them.
|
|
13
|
+
|
|
14
|
+
## The verifier's task
|
|
15
|
+
|
|
16
|
+
1. Check every location: the file exists, the lines are positive and real, and they say what the candidate claims. The first location must be a real entry reachable by the stated lower-trust principal; the last must be the claimed sink or effect.
|
|
17
|
+
2. Rebuild the strongest controls on the path that source shows: validation, identity, authorization, normalization, lifecycle, framework defaults, containment. A control the candidate missed refutes it.
|
|
18
|
+
3. If the architecture note names a comparable product, say whether it shares the pattern. That is calibration; it is never a reason to reject.
|
|
19
|
+
4. For a proposed `confirmed`: independently reproduce the minimum observed result under isolation when possible. Check input, interface shape, conditions, and the dummy principal and resource affected. Do not infer a bigger result and do not go past it.
|
|
20
|
+
5. Check that likelihood, impact, severity and the proposed fix match exactly what the evidence shows.
|
|
21
|
+
6. For a proposed `needs_validation`: is the missing fact truly outside what source and an isolated check can show? If source refutes the trace, reject. If the fact is still decisive, keep the verdict and make the validation steps exact and harmless.
|
|
22
|
+
7. Keep the id unless this is genuinely a different root cause.
|
|
23
|
+
|
|
24
|
+
Return one JSON object only: `{"decision": "confirmed|needs_validation|rejected", "record": {…}}`, where `record` matches that verdict's shape in `findings.json`. The verifier's corrected wording replaces the hunter's.
|
|
25
|
+
|
|
26
|
+
Malformed or prose-wrapped output is discarded, never repaired. Re-run with another fresh verifier if the budget allows; otherwise the candidate stays `awaiting_verification` and the run is `partial`.
|
|
27
|
+
|
|
28
|
+
## The three verdicts
|
|
29
|
+
|
|
30
|
+
| Verdict | Means | Must have | Must not have |
|
|
31
|
+
|---|---|---|---|
|
|
32
|
+
| `confirmed` | The boundary failure was shown: source trace plus an observed result from an isolated check (or, for platform surface, from read-only configuration) | `principal`, `boundary`, `impact` stating the observed result, `locations[]`, `evidence[]` including the observed output, `severity`, `fix.proposal` | `missing_evidence`, `rejection_reason` |
|
|
33
|
+
| `needs_validation` | The code points to a precise boundary break, but one fact that neither the source nor an isolated run can show is still missing | `principal`, `boundary`, the concrete result that would follow, `locations[]`, `evidence[]`, `missing_evidence` naming **the exact fact** and a harmless way to get it (an isolated test to write, or what the owner should look at in a console or config) | `severity`, a fix presented as required |
|
|
34
|
+
| `rejected` | Source, isolated behaviour, a visible control, no meaningful impact, or an impossible precondition refutes it | `locations[]`, `evidence[]`, `rejection_reason` | `severity`, `missing_evidence` |
|
|
35
|
+
|
|
36
|
+
Rules that hold across verdicts:
|
|
37
|
+
|
|
38
|
+
- `needs_validation` is not a low-confidence `confirmed` and not a parking place for ideas. "Might be exploitable depending on configuration" fails; "exploitable if the `uploads` bucket is public; check Storage → Policies for `uploads` in the project console" passes.
|
|
39
|
+
- A verifier may promote `needs_validation` to `confirmed` only after establishing the whole path and an observed result itself. It demotes `confirmed` to `needs_validation` when one deployment or runtime fact stays unknown.
|
|
40
|
+
- `rejected` records stay in `findings.json` so the next run does not re-raise the same unsupported claim without new evidence.
|
|
41
|
+
|
|
42
|
+
### Principal, boundary, observed result
|
|
43
|
+
|
|
44
|
+
No candidate is confirmed without all three:
|
|
45
|
+
|
|
46
|
+
- **Principal**: who, with what starting capability (anonymous visitor; authenticated user of tenant A; CI job from a fork).
|
|
47
|
+
- **Boundary**: which control, at which location, should have stopped it.
|
|
48
|
+
- **Concrete observed result**: what actually happened in the isolated check or what the read-only configuration shows (tenant B's dummy invoice returned; the parser wrote outside its directory; the bucket policy grants `public read`). Not "could lead to".
|
|
49
|
+
|
|
50
|
+
Self-impact, intended same-principal authority, and a generic crash with no boundary crossed are not findings.
|
|
51
|
+
|
|
52
|
+
### Defense-in-depth gaps are notes
|
|
53
|
+
|
|
54
|
+
A missing header, an unpinned dependency with no reachable path, an absent rate limit where nothing shows harm, a second check that would be nice behind a first one that holds: these go to the report's hardening notes with `path:line`. They do not become findings, get no severity, and are not verified as findings.
|
|
55
|
+
|
|
56
|
+
## Severity
|
|
57
|
+
|
|
58
|
+
Only `confirmed` gets severity. It is set from the **demonstrated** result and conditions, and the overall level never exceeds demonstrated impact. When the concrete damage can't be named, the real level sits below your instinct.
|
|
59
|
+
|
|
60
|
+
| Level | Anchor |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `critical` | Anonymous actor gets code execution, the whole data store, or takeover of any account |
|
|
63
|
+
| `high` | An explicit security control is fully defeated with real consequences: authentication bypass, read or write across tenants, stored script that runs for other users, code execution needing an account, a shared service that anyone can take down remotely without an account |
|
|
64
|
+
| `medium` | A real boundary violation, but limited blast radius, unusual preconditions, or effects confined to a narrow set of resources |
|
|
65
|
+
| `low` | Non-secret internals disclosed, an effect needing sustained effort for little gain, or a confirmed weakness that matters only as one link in a bigger chain |
|
|
66
|
+
|
|
67
|
+
**High or medium?** Was an explicit control beaten *completely*, on an action that matters (high), or merely *weakened* (medium)?
|
|
68
|
+
|
|
69
|
+
## Writing `findings.json`
|
|
70
|
+
|
|
71
|
+
After all candidates are decided (or the run stops), the coordinator writes every record to `findings.json`, sorted by id, using the contract in SKILL.md. Each linked unit in `coverage.units[]` lists the ids it produced. Then run `node scripts/validate-findings.mjs <audit-dir>` and fix every error. Passing proves structure, file and line existence, evidence placement and absence of visible secrets; it does not prove truth.
|
|
72
|
+
|
|
73
|
+
## Second verification of final records
|
|
74
|
+
|
|
75
|
+
A second fresh agent (not the hunter, not the first verifier) checks each final `confirmed` and `needs_validation` record, in parallel. It works from the record, not the hunter's prose. In `quick` the first verifier does this job too, so each candidate gets one independent reviewer; every other profile keeps two. A `confirmed` record is never reported without at least one independent check.
|
|
76
|
+
|
|
77
|
+
For `confirmed`, it checks:
|
|
78
|
+
|
|
79
|
+
1. every location: path, lines, what the code does there;
|
|
80
|
+
2. the real entry interface and the exact input shape;
|
|
81
|
+
3. every condition, parser or policy step, visible preventing layer, and the observed result;
|
|
82
|
+
4. the affected principal or resource and the demonstrated impact;
|
|
83
|
+
5. likelihood, impact and severity, with severity not above impact;
|
|
84
|
+
6. the fix: does it enforce the invariant, or only move the trust somewhere else?
|
|
85
|
+
|
|
86
|
+
For `needs_validation`, it checks:
|
|
87
|
+
|
|
88
|
+
1. the trace is real and supports only the claim made;
|
|
89
|
+
2. the missing fact is decisive and cannot already be answered by source or an isolated check;
|
|
90
|
+
3. a boundary and a concrete possible result are named, not a generic worry;
|
|
91
|
+
4. the validation step is exact and harmless (an isolated test, or something the owner looks at); never audit traffic to a live system;
|
|
92
|
+
5. the id matches prior and current records for the same root cause.
|
|
93
|
+
|
|
94
|
+
It returns `{"decision": "verified", "id": "…"}` or `{"decision": "replace", "reason": "…", "record": {…}}`.
|
|
95
|
+
|
|
96
|
+
**Material replacements need a third agent.** If the replacement raises the verdict (anything to `confirmed`), or changes root cause, trace, input, observed result, impact or severity, a new agent that took no part so far re-checks the source, reproduces any decisive result under isolation, and returns `verified` or another replacement. Repeat until stable. If budget or independence runs out, remove the disputed record from `findings.json`, leave its candidate `awaiting_verification`, and mark the run `partial` with that reason. Wording fixes and line corrections that change neither meaning nor evidence are applied directly.
|
|
97
|
+
|
|
98
|
+
If a final verifier spots a separate root cause, it gets a new id and goes through candidate verification first.
|
|
99
|
+
|
|
100
|
+
After every applied replacement, re-run the validator. The run may be `complete` only when every candidate has an independent final decision and every retained record passed this second check. Do not skip `needs_validation` records here: a wrong one sends the owner chasing a false premise.
|
|
101
|
+
|
|
102
|
+
## Fix evidence: fail, then pass
|
|
103
|
+
|
|
104
|
+
The audit proposes fixes; it changes target code only when the owner approves a specific fix ([auditor safety](auditor-safety.md#who-approves-what)), on a branch, never on the default branch.
|
|
105
|
+
|
|
106
|
+
- `fix.proposal`: the invariant, the narrowest change at the last trusted decision point, and the regression test that proves it. Prefer concrete repository-relative changes over generic hardening advice.
|
|
107
|
+
- `fix.status`: `proposed` until the owner answers; then `approved`, `declined` or `manual` (only the user can do it); `applied` once changed and re-checked; `rolled_back` if the change broke something and was undone. The loop is in [fixing](fixing.md).
|
|
108
|
+
- `fix.rollback`: how to undo it (revert the commit, the flag to flip back, the migration down step).
|
|
109
|
+
- `fix.recheck`: **required when a fix is applied.** A regression test that **fails on the unfixed code and passes on the fixed code**, both runs under isolation:
|
|
110
|
+
- `command`: the exact test command;
|
|
111
|
+
- `result`: both outcomes and the two commits, e.g. `fails at <base-sha> (expected 403, got 200); passes at <fix-sha>`;
|
|
112
|
+
- `artifact`: the promoted output of both runs in `evidence/`.
|
|
113
|
+
|
|
114
|
+
A test that only passes after the fix, with no recorded failure before it, proves nothing; the finding's fix stays `proposed`. A recheck also re-runs the finding's original isolated check and records that the observed result no longer occurs.
|
|
115
|
+
|
|
116
|
+
## After verification
|
|
117
|
+
|
|
118
|
+
Only records that passed the second check feed the report. `scripts/render-report.mjs <audit-dir> [--lang es|en]` builds `report.html` from `findings.json`; prose never changes a verdict, a severity, a missing fact or an impact. A clean run may have zero confirmed findings. Say so, state the remaining coverage and validation limits, and do not invent low-severity findings to fill the page.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/ericrisco/rsc/skills/security-audit/schema/findings.schema.json",
|
|
4
|
+
"title": "security-audit findings.json",
|
|
5
|
+
"description": "Contract of <project>/02-DOCS/security/audit-<YYYY-MM-DD>/findings.json. Documentation only: scripts/validate-findings.mjs enforces these rules by hand (no ajv) and adds the disk checks a schema cannot express — cited files and lines exist under project_root, evidence files exist non-empty under evidence/ or fixes/ of the audit dir, no '..'/absolute/symlink escapes, coverage cross-references resolve, 'complete' runs reviewed something and left nothing unreviewed, tool_path is a real 01-TOOLS/security/<platform>/ dir with a README.md and a check, no likely live secret in any key or string of findings.json nor in any file of the audit dir (report.html and scratch/ excepted; symlinks refused; files over 2 MB refused), findings.json <= 5 MB, cited project files <= 5 MB, nesting <= 32.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["run", "findings", "coverage", "platforms"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"run": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"description": "One audit run.",
|
|
12
|
+
"required": ["id", "started_at", "project_root", "scope", "profile", "status"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"id": { "type": "string", "minLength": 1, "description": "Run id, e.g. audit-2026-11-09." },
|
|
15
|
+
"started_at": { "type": "string", "format": "date-time", "description": "ISO 8601 start time." },
|
|
16
|
+
"project_root": { "type": "string", "description": "Absolute path of the audited project; must be an existing directory. Every locations[].path is relative to it." },
|
|
17
|
+
"scope": { "type": "object", "description": "Free-form description of what was in scope (paths, platforms, exclusions)." },
|
|
18
|
+
"profile": { "enum": ["quick", "standard", "deep"], "description": "Depth of the run." },
|
|
19
|
+
"status": { "enum": ["complete", "partial"], "description": "'complete' is refused while any coverage unit is not done or any platform is not reviewed, and when there are no units and no platforms at all." },
|
|
20
|
+
"partial_reason": { "type": "string", "minLength": 1, "description": "Why the run is partial. Required when status is partial." }
|
|
21
|
+
},
|
|
22
|
+
"if": { "properties": { "status": { "const": "partial" } } },
|
|
23
|
+
"then": { "required": ["partial_reason"] }
|
|
24
|
+
},
|
|
25
|
+
"findings": {
|
|
26
|
+
"type": "array",
|
|
27
|
+
"description": "Every candidate examined, including rejected ones.",
|
|
28
|
+
"items": { "$ref": "#/$defs/finding" }
|
|
29
|
+
},
|
|
30
|
+
"coverage": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"required": ["units"],
|
|
33
|
+
"properties": {
|
|
34
|
+
"units": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"description": "What was (and was not) reviewed. Every confirmed or needs_validation finding must be referenced by at least one unit; every referenced id must exist.",
|
|
37
|
+
"items": { "$ref": "#/$defs/unit" }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"platforms": {
|
|
42
|
+
"type": "array",
|
|
43
|
+
"description": "Platforms the project uses (GitHub, Vercel, Postgres, Hetzner...).",
|
|
44
|
+
"items": { "$ref": "#/$defs/platform" }
|
|
45
|
+
},
|
|
46
|
+
"user_actions": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"description": "Things only the user can do (rotate a key, click a setting).",
|
|
49
|
+
"items": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"required": ["title", "steps"],
|
|
52
|
+
"properties": {
|
|
53
|
+
"title": { "type": "string", "minLength": 1 },
|
|
54
|
+
"steps": { "type": "array", "items": { "type": "string", "minLength": 1 } }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"$defs": {
|
|
60
|
+
"relPath": {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"minLength": 1,
|
|
63
|
+
"description": "Relative path: no leading '/', no drive letter, no '..' segment, no symlink on the way, must resolve to a regular file inside its base.",
|
|
64
|
+
"not": { "pattern": "(^[/\\\\])|(^[A-Za-z]:)|(^|[/\\\\])\\.\\.([/\\\\]|$)" }
|
|
65
|
+
},
|
|
66
|
+
"finding": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"required": ["id", "title", "verdict", "surface", "class"],
|
|
69
|
+
"properties": {
|
|
70
|
+
"id": { "type": "string", "pattern": "^F-\\d{3,}$", "description": "Unique id, F-001 style." },
|
|
71
|
+
"title": { "type": "string", "minLength": 1 },
|
|
72
|
+
"verdict": { "enum": ["confirmed", "needs_validation", "rejected"], "description": "confirmed = proven by an artifact or command output on disk; needs_validation = plausible, one named fact missing; rejected = ruled out." },
|
|
73
|
+
"severity": { "enum": ["critical", "high", "medium", "low"], "description": "Required for confirmed, forbidden otherwise." },
|
|
74
|
+
"surface": { "enum": ["code", "platform"] },
|
|
75
|
+
"platform": { "type": "string", "minLength": 1, "description": "Platform name. Required when surface is platform." },
|
|
76
|
+
"class": { "type": "string", "minLength": 1, "description": "Attack class id (e.g. idor, sqli, ssrf)." },
|
|
77
|
+
"principal": { "type": "string", "minLength": 1, "description": "Who can trigger it. Required unless rejected." },
|
|
78
|
+
"boundary": { "type": "string", "minLength": 1, "description": "Trust boundary crossed. Required unless rejected." },
|
|
79
|
+
"impact": { "type": "string", "minLength": 1, "description": "Concrete result. Required unless rejected." },
|
|
80
|
+
"locations": {
|
|
81
|
+
"type": "array",
|
|
82
|
+
"description": "Where the finding lives. Code: a file and line range, and a confirmed or needs_validation code finding needs at least one (line_start <= line_end <= the file's line count). Platform: the resource the setting was read from, e.g. hetzner:server/app-01/firewall.",
|
|
83
|
+
"items": {
|
|
84
|
+
"type": "object",
|
|
85
|
+
"oneOf": [
|
|
86
|
+
{ "required": ["path", "line_start", "line_end"] },
|
|
87
|
+
{ "required": ["resource"] }
|
|
88
|
+
],
|
|
89
|
+
"properties": {
|
|
90
|
+
"path": { "$ref": "#/$defs/relPath", "description": "Relative to run.project_root (code findings)." },
|
|
91
|
+
"line_start": { "type": "integer", "minimum": 1 },
|
|
92
|
+
"line_end": { "type": "integer", "minimum": 1 },
|
|
93
|
+
"resource": { "type": "string", "minLength": 1, "description": "Platform findings: <platform>:<resource path>." }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"evidence": {
|
|
98
|
+
"type": "array",
|
|
99
|
+
"description": "Evidence files inside the audit dir. A confirmed finding needs at least one of kind artifact or command_output; files must exist and be non-empty, and must contain no live secret.",
|
|
100
|
+
"items": {
|
|
101
|
+
"type": "object",
|
|
102
|
+
"required": ["kind", "path", "summary"],
|
|
103
|
+
"properties": {
|
|
104
|
+
"kind": { "enum": ["artifact", "command_output", "source"] },
|
|
105
|
+
"path": { "$ref": "#/$defs/relPath", "description": "Relative to the audit dir, under evidence/ or fixes/ (never findings.json, ledger.json or report.html)." },
|
|
106
|
+
"summary": { "type": "string", "minLength": 1 }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"missing_evidence": { "type": "string", "minLength": 1, "description": "The exact fact still missing. Required for needs_validation." },
|
|
111
|
+
"rejection_reason": { "type": "string", "minLength": 1, "description": "Why it was ruled out. Required for rejected." },
|
|
112
|
+
"fix": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"required": ["proposal", "status"],
|
|
115
|
+
"properties": {
|
|
116
|
+
"proposal": { "type": "string", "minLength": 1 },
|
|
117
|
+
"status": { "enum": ["proposed", "approved", "applied", "declined", "rolled_back", "manual"] },
|
|
118
|
+
"rollback": { "type": "string", "minLength": 1, "description": "How to undo the fix. Required when status is applied or rolled_back." },
|
|
119
|
+
"recheck": {
|
|
120
|
+
"type": "object",
|
|
121
|
+
"required": ["command", "result"],
|
|
122
|
+
"properties": {
|
|
123
|
+
"command": { "type": "string", "minLength": 1 },
|
|
124
|
+
"result": { "enum": ["pass", "fail", "not_run"] },
|
|
125
|
+
"artifact": { "$ref": "#/$defs/relPath", "description": "Recheck output, relative to the audit dir, under evidence/ or fixes/. Required when result is pass or fail; checked whenever present." }
|
|
126
|
+
},
|
|
127
|
+
"if": { "properties": { "result": { "enum": ["pass", "fail"] } } },
|
|
128
|
+
"then": { "required": ["artifact"] }
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"if": { "properties": { "status": { "enum": ["applied", "rolled_back"] } } },
|
|
132
|
+
"then": { "required": ["rollback"] }
|
|
133
|
+
},
|
|
134
|
+
"manual_steps": { "type": "array", "items": { "type": "string", "minLength": 1 }, "description": "Steps the user must do by hand; shown in 'Your steps' while the finding is open." }
|
|
135
|
+
},
|
|
136
|
+
"allOf": [
|
|
137
|
+
{ "if": { "properties": { "verdict": { "const": "confirmed" } } }, "then": { "required": ["severity", "evidence", "principal", "boundary", "impact"] }, "else": { "not": { "required": ["severity"] } } },
|
|
138
|
+
{ "if": { "properties": { "verdict": { "const": "needs_validation" } } }, "then": { "required": ["missing_evidence", "principal", "boundary", "impact"] } },
|
|
139
|
+
{ "if": { "properties": { "verdict": { "const": "rejected" } } }, "then": { "required": ["rejection_reason"] } },
|
|
140
|
+
{ "if": { "properties": { "surface": { "const": "platform" } } }, "then": { "required": ["platform"] } },
|
|
141
|
+
{ "if": { "properties": { "surface": { "const": "code" }, "verdict": { "enum": ["confirmed", "needs_validation"] } } }, "then": { "required": ["locations"], "properties": { "locations": { "minItems": 1 } } } },
|
|
142
|
+
{ "if": { "properties": { "verdict": { "const": "confirmed" } } }, "then": { "properties": { "evidence": { "contains": { "properties": { "kind": { "enum": ["artifact", "command_output"] } } } } } } }
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
"unit": {
|
|
146
|
+
"type": "object",
|
|
147
|
+
"required": ["id", "surface", "area", "boundary", "class", "status", "findings"],
|
|
148
|
+
"properties": {
|
|
149
|
+
"id": { "type": "string", "minLength": 1, "description": "Unique unit id." },
|
|
150
|
+
"surface": { "enum": ["code", "platform"] },
|
|
151
|
+
"area": { "type": "string", "minLength": 1 },
|
|
152
|
+
"boundary": { "type": "string", "minLength": 1 },
|
|
153
|
+
"class": { "type": "string", "minLength": 1 },
|
|
154
|
+
"status": { "enum": ["done", "blocked", "not_reviewed"] },
|
|
155
|
+
"reason": { "type": "string", "minLength": 1, "description": "Required unless status is done." },
|
|
156
|
+
"findings": { "type": "array", "items": { "type": "string" }, "description": "Ids of findings this unit produced; each must exist." }
|
|
157
|
+
},
|
|
158
|
+
"if": { "not": { "properties": { "status": { "const": "done" } } } },
|
|
159
|
+
"then": { "required": ["reason"] }
|
|
160
|
+
},
|
|
161
|
+
"platform": {
|
|
162
|
+
"type": "object",
|
|
163
|
+
"required": ["name", "detected_by", "access", "status"],
|
|
164
|
+
"properties": {
|
|
165
|
+
"name": { "type": "string", "minLength": 1 },
|
|
166
|
+
"detected_by": { "type": "string", "minLength": 1, "description": "What revealed it (a config file, a dependency)." },
|
|
167
|
+
"access": { "enum": ["read_only", "write_for_fix", "none"] },
|
|
168
|
+
"status": { "enum": ["reviewed", "not_reviewed"] },
|
|
169
|
+
"reason": { "type": "string", "minLength": 1, "description": "Required when not_reviewed." },
|
|
170
|
+
"tool_path": { "type": "string", "pattern": "^01-TOOLS/security/[a-z0-9][a-z0-9._-]{0,63}/?$", "description": "Tool used to review it: 01-TOOLS/security/<platform>/, relative to project_root. Must be a real directory (no symlink anywhere on the way) holding a README.md and at least one other regular file. Required when reviewed." }
|
|
171
|
+
},
|
|
172
|
+
"allOf": [
|
|
173
|
+
{ "if": { "properties": { "status": { "const": "not_reviewed" } } }, "then": { "required": ["reason"] } },
|
|
174
|
+
{ "if": { "properties": { "status": { "const": "reviewed" } } }, "then": { "required": ["tool_path"] } }
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Renders an audit directory written by the `security-audit` skill into one self-contained page:
|
|
3
|
+
//
|
|
4
|
+
// node render-report.mjs <audit-dir> [--lang en|es]
|
|
5
|
+
//
|
|
6
|
+
// It validates first (validate-findings.mjs) and refuses to render anything the validator rejects, so
|
|
7
|
+
// the report can never show a claim the disk does not back. Output: `<audit-dir>/report.html`, mode
|
|
8
|
+
// 0600 — the page lists unfixed vulnerabilities, so it is readable by its owner only. The page makes no
|
|
9
|
+
// external request: inline CSS, no scripts, light/dark from the reader's system, phone-width safe.
|
|
10
|
+
//
|
|
11
|
+
// The fixed text (headings, explanations, enum labels) is translated; what the auditor wrote
|
|
12
|
+
// (titles, impacts, steps) is shown exactly as written, HTML-escaped.
|
|
13
|
+
import { closeSync, constants, fchmodSync, lstatSync, openSync, writeSync } from 'node:fs';
|
|
14
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
16
|
+
import { realpathSync } from 'node:fs';
|
|
17
|
+
import { validate } from './validate-findings.mjs';
|
|
18
|
+
|
|
19
|
+
const T = {
|
|
20
|
+
en: {
|
|
21
|
+
title: 'Security audit report',
|
|
22
|
+
howTitle: 'How to read this report',
|
|
23
|
+
how: [
|
|
24
|
+
'<strong>Confirmed</strong> means the problem was proven: the evidence files listed with it show it happening. Only confirmed findings carry a severity.',
|
|
25
|
+
'<strong>Needs validation</strong> means the problem is plausible but one specific fact is still missing; that fact is written next to it. Treat it as open until someone checks it.',
|
|
26
|
+
'<strong>Rejected</strong> means it was investigated and ruled out; the reason is recorded so nobody re-checks it for nothing.',
|
|
27
|
+
'Severity: <strong>critical</strong> — fix now, an attacker can do serious damage with little effort; <strong>high</strong> — fix this week; <strong>medium</strong> — plan the fix; <strong>low</strong> — fix when convenient.',
|
|
28
|
+
'<strong>Not reviewed</strong> or <strong>blocked</strong> means nobody looked there. Having no findings in that area tells you nothing about it being safe.',
|
|
29
|
+
],
|
|
30
|
+
warning: 'This file contains unfixed vulnerabilities. It must not be shared or committed: keep it on this machine, and delete it once the fixes are in.',
|
|
31
|
+
summary: 'Summary', findings: 'Findings', platforms: 'Platforms', coverage: 'Coverage', steps: 'Your steps',
|
|
32
|
+
runStatus: 'Run status', profile: 'Profile', started: 'Started', projectRoot: 'Project', scope: 'Scope',
|
|
33
|
+
partialReason: 'Why it is partial', bySeverity: 'Confirmed by severity', byVerdict: 'Findings by verdict',
|
|
34
|
+
confirmedH: 'Confirmed', nvH: 'Needs validation', rejectedH: 'Rejected', rejectedSummary: (n) => `${n} rejected finding(s) — click to expand`,
|
|
35
|
+
none: 'None.', who: 'Who can trigger it', boundary: 'Boundary crossed', impact: 'Impact', class: 'Attack class',
|
|
36
|
+
surface: 'Surface', platform: 'Platform', locations: 'Where', evidence: 'Evidence', missing: 'Still missing',
|
|
37
|
+
rejection: 'Why it was rejected', fix: 'Proposed fix', fixStatus: 'Fix status', rollback: 'How to undo the fix',
|
|
38
|
+
recheck: 'Recheck', recheckArtifact: 'recheck output', manualSteps: 'Manual steps',
|
|
39
|
+
platformCols: ['Platform', 'Detected by', 'Access', 'Status', 'Tool or reason'],
|
|
40
|
+
unitCols: ['Unit', 'Surface', 'Area', 'Boundary', 'Class', 'Status', 'Reason', 'Findings'],
|
|
41
|
+
unitsDone: (d, n) => `${d} of ${n} units reviewed.`,
|
|
42
|
+
nothingToDo: 'Nothing for you to do.', fromFinding: 'From finding',
|
|
43
|
+
labels: {
|
|
44
|
+
confirmed: 'Confirmed', needs_validation: 'Needs validation', rejected: 'Rejected',
|
|
45
|
+
critical: 'Critical', high: 'High', medium: 'Medium', low: 'Low',
|
|
46
|
+
complete: 'Complete', partial: 'Partial', quick: 'Quick', standard: 'Standard', deep: 'Deep',
|
|
47
|
+
code: 'Code', platform: 'Platform', artifact: 'artifact', command_output: 'command output', source: 'source',
|
|
48
|
+
proposed: 'Proposed', approved: 'Approved', applied: 'Applied', declined: 'Declined', rolled_back: 'Rolled back', manual: 'Manual (you do it)',
|
|
49
|
+
pass: 'pass', fail: 'fail', not_run: 'not run',
|
|
50
|
+
done: 'Done', blocked: 'Blocked', not_reviewed: 'Not reviewed', reviewed: 'Reviewed',
|
|
51
|
+
read_only: 'Read only', write_for_fix: 'Write (for fixes)', none: 'None',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
es: {
|
|
55
|
+
title: 'Informe de auditoría de seguridad',
|
|
56
|
+
howTitle: 'Cómo leer este informe',
|
|
57
|
+
how: [
|
|
58
|
+
'<strong>Confirmado</strong> significa que el problema está probado: los ficheros de evidencia que lo acompañan lo muestran ocurriendo. Solo los confirmados llevan gravedad.',
|
|
59
|
+
'<strong>Por validar</strong> significa que el problema es verosímil pero falta un dato concreto; ese dato está escrito al lado. Trátalo como abierto hasta que alguien lo compruebe.',
|
|
60
|
+
'<strong>Descartado</strong> significa que se investigó y se descartó; el motivo queda escrito para que nadie lo vuelva a revisar en balde.',
|
|
61
|
+
'Gravedad: <strong>crítica</strong> — arréglalo ya, un atacante puede hacer mucho daño con poco esfuerzo; <strong>alta</strong> — esta semana; <strong>media</strong> — planifica el arreglo; <strong>baja</strong> — cuando te venga bien.',
|
|
62
|
+
'<strong>No revisado</strong> o <strong>bloqueado</strong> significa que nadie miró ahí. Que no haya hallazgos en esa zona no dice nada de que sea segura.',
|
|
63
|
+
],
|
|
64
|
+
warning: 'Este fichero contiene vulnerabilidades sin arreglar. No debe compartirse ni subirse al repositorio: guárdalo en este equipo y bórralo cuando estén los arreglos.',
|
|
65
|
+
summary: 'Resumen', findings: 'Hallazgos', platforms: 'Plataformas', coverage: 'Cobertura', steps: 'Tus pasos',
|
|
66
|
+
runStatus: 'Estado de la auditoría', profile: 'Perfil', started: 'Inicio', projectRoot: 'Proyecto', scope: 'Alcance',
|
|
67
|
+
partialReason: 'Por qué es parcial', bySeverity: 'Confirmados por gravedad', byVerdict: 'Hallazgos por veredicto',
|
|
68
|
+
confirmedH: 'Confirmados', nvH: 'Por validar', rejectedH: 'Descartados', rejectedSummary: (n) => `${n} hallazgo(s) descartado(s) — pulsa para ver`,
|
|
69
|
+
none: 'Ninguno.', who: 'Quién puede provocarlo', boundary: 'Frontera que cruza', impact: 'Impacto', class: 'Tipo de ataque',
|
|
70
|
+
surface: 'Superficie', platform: 'Plataforma', locations: 'Dónde', evidence: 'Evidencia', missing: 'Falta comprobar',
|
|
71
|
+
rejection: 'Por qué se descartó', fix: 'Arreglo propuesto', fixStatus: 'Estado del arreglo', rollback: 'Cómo deshacer el arreglo',
|
|
72
|
+
recheck: 'Recomprobación', recheckArtifact: 'salida de la recomprobación', manualSteps: 'Pasos manuales',
|
|
73
|
+
platformCols: ['Plataforma', 'Detectada por', 'Acceso', 'Estado', 'Herramienta o motivo'],
|
|
74
|
+
unitCols: ['Unidad', 'Superficie', 'Zona', 'Frontera', 'Tipo', 'Estado', 'Motivo', 'Hallazgos'],
|
|
75
|
+
unitsDone: (d, n) => `${d} de ${n} unidades revisadas.`,
|
|
76
|
+
nothingToDo: 'No tienes nada que hacer.', fromFinding: 'Del hallazgo',
|
|
77
|
+
labels: {
|
|
78
|
+
confirmed: 'Confirmado', needs_validation: 'Por validar', rejected: 'Descartado',
|
|
79
|
+
critical: 'Crítica', high: 'Alta', medium: 'Media', low: 'Baja',
|
|
80
|
+
complete: 'Completa', partial: 'Parcial', quick: 'Rápido', standard: 'Estándar', deep: 'Profundo',
|
|
81
|
+
code: 'Código', platform: 'Plataforma', artifact: 'artefacto', command_output: 'salida de comando', source: 'código fuente',
|
|
82
|
+
proposed: 'Propuesto', approved: 'Aprobado', applied: 'Aplicado', declined: 'Rechazado', rolled_back: 'Revertido', manual: 'Manual (lo haces tú)',
|
|
83
|
+
pass: 'pasa', fail: 'falla', not_run: 'sin ejecutar',
|
|
84
|
+
done: 'Hecha', blocked: 'Bloqueada', not_reviewed: 'No revisada', reviewed: 'Revisada',
|
|
85
|
+
read_only: 'Solo lectura', write_for_fix: 'Escritura (para arreglos)', none: 'Ninguno',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const SEVERITY_RANK = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
91
|
+
|
|
92
|
+
/** Escapes text for HTML element content and quoted attributes. */
|
|
93
|
+
export function esc(v) {
|
|
94
|
+
return String(v ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// A relative href: each path segment percent-encoded, then the whole thing attribute-escaped.
|
|
98
|
+
const href = (rel) => esc(rel.split('/').map(encodeURIComponent).join('/'));
|
|
99
|
+
|
|
100
|
+
// A finding is closed only when its fix is applied AND a recheck proved it; anything else is open.
|
|
101
|
+
const isOpen = (f) => f.verdict !== 'rejected' && !(f.fix?.status === 'applied' && f.fix?.recheck?.result === 'pass');
|
|
102
|
+
|
|
103
|
+
const CSS = `
|
|
104
|
+
:root{--bg:#fbfaf7;--fg:#1c1b19;--muted:#5f5b53;--line:#dedad1;--card:#fff;--warn-bg:#fff4e0;--warn-fg:#6b3d00;
|
|
105
|
+
--critical:#b3141b;--high:#c2410c;--medium:#a16207;--low:#3f6212;--nv:#4338ca;--rej:#6b7280;--ok:#15803d}
|
|
106
|
+
@media (prefers-color-scheme:dark){:root{--bg:#141412;--fg:#ecebe6;--muted:#a8a49a;--line:#34322d;--card:#1d1c1a;--warn-bg:#3a2a10;--warn-fg:#ffd9a0;
|
|
107
|
+
--critical:#ff6b6b;--high:#fb923c;--medium:#facc15;--low:#a3e635;--nv:#a5b4fc;--rej:#9ca3af;--ok:#4ade80}}
|
|
108
|
+
*{box-sizing:border-box}
|
|
109
|
+
body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
110
|
+
main{max-width:920px;margin:0 auto;padding:24px 16px 64px}
|
|
111
|
+
h1{font-size:1.6rem;margin:0 0 4px}h2{font-size:1.25rem;margin:40px 0 12px;padding-top:8px;border-top:1px solid var(--line)}
|
|
112
|
+
h3{font-size:1.05rem;margin:0 0 8px}h4{font-size:.95rem;margin:16px 0 6px}
|
|
113
|
+
.muted{color:var(--muted)}code,pre{font:13px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
114
|
+
pre{white-space:pre-wrap;word-break:break-word;background:var(--card);border:1px solid var(--line);border-radius:6px;padding:8px 10px;margin:0}
|
|
115
|
+
.warn{background:var(--warn-bg);color:var(--warn-fg);border-radius:8px;padding:12px 14px;font-weight:600}
|
|
116
|
+
.card{background:var(--card);border:1px solid var(--line);border-left:5px solid var(--rej);border-radius:8px;padding:14px 16px;margin:12px 0;overflow-wrap:anywhere}
|
|
117
|
+
.sev-critical{border-left-color:var(--critical)}.sev-high{border-left-color:var(--high)}.sev-medium{border-left-color:var(--medium)}.sev-low{border-left-color:var(--low)}.nv{border-left-color:var(--nv)}
|
|
118
|
+
.badge{display:inline-block;font-size:.75rem;font-weight:700;padding:1px 8px;border-radius:99px;border:1px solid currentColor;margin-right:6px;vertical-align:middle}
|
|
119
|
+
.b-critical{color:var(--critical)}.b-high{color:var(--high)}.b-medium{color:var(--medium)}.b-low{color:var(--low)}.b-nv{color:var(--nv)}.b-rej{color:var(--rej)}
|
|
120
|
+
.b-pass{color:var(--ok)}.b-fail{color:var(--critical)}
|
|
121
|
+
dl{display:grid;grid-template-columns:minmax(120px,max-content) 1fr;gap:4px 14px;margin:0}dt{color:var(--muted)}dd{margin:0}
|
|
122
|
+
@media (max-width:560px){dl{grid-template-columns:1fr}dd{margin-bottom:6px}}
|
|
123
|
+
ul,ol{margin:4px 0;padding-left:22px}
|
|
124
|
+
.tbl{overflow-x:auto}table{border-collapse:collapse;width:100%;font-size:.9rem}th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line);vertical-align:top}
|
|
125
|
+
tr.open td{background:var(--warn-bg);color:var(--warn-fg)}
|
|
126
|
+
.counts{display:flex;flex-wrap:wrap;gap:8px;margin:8px 0}.count{background:var(--card);border:1px solid var(--line);border-radius:8px;padding:8px 12px;min-width:110px}
|
|
127
|
+
.count b{display:block;font-size:1.4rem}
|
|
128
|
+
details>summary{cursor:pointer;font-weight:600;padding:6px 0}
|
|
129
|
+
a{color:inherit}
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Validates `auditDir` and returns the report HTML. Throws (with every validation error in the
|
|
134
|
+
* message) when the audit dir does not validate.
|
|
135
|
+
*/
|
|
136
|
+
export function render(auditDir, { lang = 'en' } = {}) {
|
|
137
|
+
const t = T[lang];
|
|
138
|
+
if (!t) throw new Error(`unknown --lang ${lang}; use en or es`);
|
|
139
|
+
const r = validate(auditDir);
|
|
140
|
+
if (!r.ok) throw new Error(`refusing to render: findings.json does not validate\n${r.errors.map((e) => ` ${e}`).join('\n')}`);
|
|
141
|
+
const doc = r.data;
|
|
142
|
+
const L = (v) => esc(t.labels[v] ?? v);
|
|
143
|
+
const auditReal = realpathSync(auditDir);
|
|
144
|
+
// Code locations link to the source file relative to the report, so they open next to it.
|
|
145
|
+
const toProject = relative(auditReal, realpathSync(doc.run.project_root)).split(sep).join('/');
|
|
146
|
+
|
|
147
|
+
const findings = doc.findings;
|
|
148
|
+
const confirmed = findings.filter((f) => f.verdict === 'confirmed')
|
|
149
|
+
.sort((a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] || a.id.localeCompare(b.id));
|
|
150
|
+
const nv = findings.filter((f) => f.verdict === 'needs_validation').sort((a, b) => a.id.localeCompare(b.id));
|
|
151
|
+
const rejected = findings.filter((f) => f.verdict === 'rejected').sort((a, b) => a.id.localeCompare(b.id));
|
|
152
|
+
|
|
153
|
+
const row = (k, v) => (v === undefined || v === null || v === '' ? '' : `<dt>${esc(k)}</dt><dd>${v}</dd>`);
|
|
154
|
+
|
|
155
|
+
const card = (f) => {
|
|
156
|
+
const cls = f.verdict === 'confirmed' ? `sev-${f.severity}` : f.verdict === 'needs_validation' ? 'nv' : '';
|
|
157
|
+
const badge = f.verdict === 'confirmed'
|
|
158
|
+
? `<span class="badge b-${esc(f.severity)}">${L(f.severity)}</span>`
|
|
159
|
+
: `<span class="badge ${f.verdict === 'rejected' ? 'b-rej' : 'b-nv'}">${L(f.verdict)}</span>`;
|
|
160
|
+
const locs = (f.locations ?? []).map((l) => {
|
|
161
|
+
if (l.resource) return `<li><code>${esc(l.resource)}</code></li>`;
|
|
162
|
+
const span = l.line_start === l.line_end ? `${l.line_start}` : `${l.line_start}-${l.line_end}`;
|
|
163
|
+
const link = toProject ? `${toProject}/${l.path}` : l.path;
|
|
164
|
+
return `<li><a href="${href(link)}"><code>${esc(l.path)}:${esc(span)}</code></a></li>`;
|
|
165
|
+
});
|
|
166
|
+
const ev = (f.evidence ?? []).map((e) =>
|
|
167
|
+
`<li><a href="${href(e.path)}"><code>${esc(e.path)}</code></a> <span class="muted">(${L(e.kind)})</span> — ${esc(e.summary)}</li>`);
|
|
168
|
+
let fix = '';
|
|
169
|
+
if (f.fix) {
|
|
170
|
+
const rc = f.fix.recheck;
|
|
171
|
+
const rcHtml = rc
|
|
172
|
+
? `<code>${esc(rc.command)}</code> → <span class="badge b-${esc(rc.result)}">${L(rc.result)}</span>${rc.artifact ? ` <a href="${href(rc.artifact)}">${esc(t.recheckArtifact)}</a>` : ''}`
|
|
173
|
+
: '';
|
|
174
|
+
fix = row(t.fix, esc(f.fix.proposal)) + row(t.fixStatus, L(f.fix.status))
|
|
175
|
+
+ (f.fix.rollback ? row(t.rollback, esc(f.fix.rollback)) : '') + row(t.recheck, rcHtml);
|
|
176
|
+
}
|
|
177
|
+
const steps = (f.manual_steps ?? []).length ? row(t.manualSteps, `<ol>${f.manual_steps.map((s) => `<li>${esc(s)}</li>`).join('')}</ol>`) : '';
|
|
178
|
+
return `<article class="card ${cls}" id="${esc(f.id)}">
|
|
179
|
+
<h3>${badge}<code>${esc(f.id)}</code> ${esc(f.title)}</h3>
|
|
180
|
+
<dl>${row(t.who, esc(f.principal))}${row(t.boundary, esc(f.boundary))}${row(t.impact, esc(f.impact))}${row(t.class, esc(f.class))}${row(t.surface, L(f.surface) + (f.platform ? ` · ${esc(f.platform)}` : ''))}${locs.length ? row(t.locations, `<ul>${locs.join('')}</ul>`) : ''}${ev.length ? row(t.evidence, `<ul>${ev.join('')}</ul>`) : ''}${row(t.missing, f.missing_evidence ? esc(f.missing_evidence) : '')}${row(t.rejection, f.rejection_reason ? esc(f.rejection_reason) : '')}${fix}${steps}</dl>
|
|
181
|
+
</article>`;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const list = (arr) => (arr.length ? arr.map(card).join('\n') : `<p class="muted">${esc(t.none)}</p>`);
|
|
185
|
+
const count = (label, n, cls = '') => `<div class="count ${cls}"><b>${n}</b>${label}</div>`;
|
|
186
|
+
const table = (cols, rows) => `<div class="tbl"><table><thead><tr>${cols.map((c) => `<th>${esc(c)}</th>`).join('')}</tr></thead><tbody>${rows.join('')}</tbody></table></div>`;
|
|
187
|
+
|
|
188
|
+
// ---- sections, in the fixed order the contract names ----
|
|
189
|
+
const how = `<section id="how-to-read"><h2>${esc(t.howTitle)}</h2>
|
|
190
|
+
<p class="warn">${esc(t.warning)}</p>
|
|
191
|
+
${t.how.map((p) => `<p>${p}</p>`).join('\n')}
|
|
192
|
+
</section>`;
|
|
193
|
+
|
|
194
|
+
const run = doc.run;
|
|
195
|
+
const summary = `<section id="summary"><h2>${esc(t.summary)}</h2>
|
|
196
|
+
<dl>${row(t.runStatus, `<strong>${L(run.status)}</strong>`)}${row(t.partialReason, run.partial_reason ? esc(run.partial_reason) : '')}${row(t.profile, L(run.profile))}${row(t.started, esc(run.started_at))}${row(t.projectRoot, `<code>${esc(run.project_root)}</code>`)}</dl>
|
|
197
|
+
<h4>${esc(t.byVerdict)}</h4>
|
|
198
|
+
<div class="counts">${count(L('confirmed'), confirmed.length)}${count(L('needs_validation'), nv.length)}${count(L('rejected'), rejected.length)}</div>
|
|
199
|
+
<h4>${esc(t.bySeverity)}</h4>
|
|
200
|
+
<div class="counts">${['critical', 'high', 'medium', 'low'].map((s) => count(`<span class="b-${s}">${L(s)}</span>`, confirmed.filter((f) => f.severity === s).length)).join('')}</div>
|
|
201
|
+
<h4>${esc(t.scope)}</h4>
|
|
202
|
+
<pre>${esc(JSON.stringify(run.scope, null, 2))}</pre>
|
|
203
|
+
</section>`;
|
|
204
|
+
|
|
205
|
+
const findingsHtml = `<section id="findings"><h2>${esc(t.findings)}</h2>
|
|
206
|
+
<h3>${esc(t.confirmedH)}</h3>
|
|
207
|
+
${list(confirmed)}
|
|
208
|
+
<h3>${esc(t.nvH)}</h3>
|
|
209
|
+
${list(nv)}
|
|
210
|
+
<h3>${esc(t.rejectedH)}</h3>
|
|
211
|
+
${rejected.length ? `<details><summary>${esc(t.rejectedSummary(rejected.length))}</summary>\n${list(rejected)}\n</details>` : `<p class="muted">${esc(t.none)}</p>`}
|
|
212
|
+
</section>`;
|
|
213
|
+
|
|
214
|
+
const platforms = `<section id="platforms"><h2>${esc(t.platforms)}</h2>
|
|
215
|
+
${doc.platforms.length ? table(t.platformCols, doc.platforms.map((p) =>
|
|
216
|
+
`<tr class="${p.status === 'reviewed' ? '' : 'open'}"><td>${esc(p.name)}</td><td>${esc(p.detected_by)}</td><td>${L(p.access)}</td><td>${L(p.status)}</td><td>${p.status === 'reviewed' ? `<code>${esc(p.tool_path)}</code>` : esc(p.reason)}</td></tr>`)) : `<p class="muted">${esc(t.none)}</p>`}
|
|
217
|
+
</section>`;
|
|
218
|
+
|
|
219
|
+
const units = doc.coverage.units;
|
|
220
|
+
const coverage = `<section id="coverage"><h2>${esc(t.coverage)}</h2>
|
|
221
|
+
<p>${esc(t.unitsDone(units.filter((u) => u.status === 'done').length, units.length))}</p>
|
|
222
|
+
${units.length ? table(t.unitCols, units.map((u) =>
|
|
223
|
+
`<tr class="${u.status === 'done' ? '' : 'open'}"><td><code>${esc(u.id)}</code></td><td>${L(u.surface)}</td><td>${esc(u.area)}</td><td>${esc(u.boundary)}</td><td>${esc(u.class)}</td><td>${L(u.status)}</td><td>${esc(u.reason ?? '')}</td><td>${u.findings.map((id) => `<a href="#${esc(id)}">${esc(id)}</a>`).join(' ')}</td></tr>`)) : `<p class="muted">${esc(t.none)}</p>`}
|
|
224
|
+
</section>`;
|
|
225
|
+
|
|
226
|
+
const actions = (doc.user_actions ?? []).map((a) => `<h4>${esc(a.title)}</h4><ol>${a.steps.map((s) => `<li>${esc(s)}</li>`).join('')}</ol>`);
|
|
227
|
+
const manual = findings.filter((f) => isOpen(f) && (f.manual_steps ?? []).length)
|
|
228
|
+
.map((f) => `<h4>${esc(t.fromFinding)} <a href="#${esc(f.id)}"><code>${esc(f.id)}</code></a> — ${esc(f.title)}</h4><ol>${f.manual_steps.map((s) => `<li>${esc(s)}</li>`).join('')}</ol>`);
|
|
229
|
+
const steps = `<section id="your-steps"><h2>${esc(t.steps)}</h2>
|
|
230
|
+
${actions.length + manual.length ? [...actions, ...manual].join('\n') : `<p class="muted">${esc(t.nothingToDo)}</p>`}
|
|
231
|
+
</section>`;
|
|
232
|
+
|
|
233
|
+
return `<!doctype html>
|
|
234
|
+
<html lang="${lang}">
|
|
235
|
+
<head>
|
|
236
|
+
<meta charset="utf-8">
|
|
237
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
238
|
+
<meta name="color-scheme" content="light dark">
|
|
239
|
+
<meta name="robots" content="noindex">
|
|
240
|
+
<title>${esc(t.title)} — ${esc(run.id)}</title>
|
|
241
|
+
<style>${CSS}</style>
|
|
242
|
+
</head>
|
|
243
|
+
<body>
|
|
244
|
+
<main>
|
|
245
|
+
<h1>${esc(t.title)}</h1>
|
|
246
|
+
<p class="muted"><code>${esc(run.id)}</code> · ${esc(run.started_at)} · ${L(run.status)}</p>
|
|
247
|
+
${how}
|
|
248
|
+
${summary}
|
|
249
|
+
${findingsHtml}
|
|
250
|
+
${platforms}
|
|
251
|
+
${coverage}
|
|
252
|
+
${steps}
|
|
253
|
+
</main>
|
|
254
|
+
</body>
|
|
255
|
+
</html>
|
|
256
|
+
`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Renders and writes `<auditDir>/report.html` (mode 0600). Returns its absolute path. */
|
|
260
|
+
export function writeReport(auditDir, opts) {
|
|
261
|
+
const html = render(auditDir, opts);
|
|
262
|
+
const out = join(realpathSync(auditDir), 'report.html');
|
|
263
|
+
// Never follow a planted symlink or overwrite something that is not a plain file.
|
|
264
|
+
let st = null;
|
|
265
|
+
try { st = lstatSync(out); } catch { /* not there yet */ }
|
|
266
|
+
if (st && !st.isFile()) throw new Error(`refusing to write ${out}: it exists and is not a regular file`);
|
|
267
|
+
// A hard link would make the write land in another file too (anywhere on the same volume).
|
|
268
|
+
if (st && st.nlink > 1) throw new Error(`refusing to write ${out}: it has another hard link; delete it and render again`);
|
|
269
|
+
// O_NOFOLLOW closes the gap between the check above and the open: a symlink planted in between
|
|
270
|
+
// makes the open fail instead of writing through it.
|
|
271
|
+
const { O_WRONLY, O_CREAT, O_TRUNC, O_NOFOLLOW } = constants;
|
|
272
|
+
const fd = openSync(out, O_WRONLY | O_CREAT | O_TRUNC | (O_NOFOLLOW ?? 0), 0o600);
|
|
273
|
+
try {
|
|
274
|
+
fchmodSync(fd, 0o600); // the mode argument only applies on creation; an older report keeps its old mode otherwise
|
|
275
|
+
const buf = Buffer.from(html, 'utf8');
|
|
276
|
+
for (let off = 0; off < buf.length;) off += writeSync(fd, buf, off, buf.length - off);
|
|
277
|
+
} finally {
|
|
278
|
+
closeSync(fd);
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// ---- CLI ----
|
|
284
|
+
function main(argv) {
|
|
285
|
+
let dir = null;
|
|
286
|
+
let lang = 'en';
|
|
287
|
+
for (let i = 0; i < argv.length; i++) {
|
|
288
|
+
if (argv[i] === '--lang') lang = argv[++i];
|
|
289
|
+
else if (argv[i].startsWith('--lang=')) lang = argv[i].slice(7);
|
|
290
|
+
else if (argv[i] === '-h' || argv[i] === '--help') dir = null;
|
|
291
|
+
else dir = argv[i];
|
|
292
|
+
}
|
|
293
|
+
if (!dir || !T[lang]) {
|
|
294
|
+
console.error('usage: render-report.mjs <audit-dir> [--lang en|es]');
|
|
295
|
+
return 2;
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const out = writeReport(resolve(dir), { lang });
|
|
299
|
+
console.log(out);
|
|
300
|
+
console.log(pathToFileURL(out).href);
|
|
301
|
+
return 0;
|
|
302
|
+
} catch (e) {
|
|
303
|
+
console.error(e.message);
|
|
304
|
+
return 1;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const self = realpathSync(fileURLToPath(import.meta.url));
|
|
309
|
+
let invoked = '';
|
|
310
|
+
try { invoked = realpathSync(process.argv[1] || ''); } catch { /* imported, not run */ }
|
|
311
|
+
if (invoked === self) process.exitCode = main(process.argv.slice(2));
|