Skip to content

Commit 6d1dfbd

Browse files
authored
Merge pull request #22 from decksoftware/feat/precision-monorepo-gate-and-honest-docs
feat: detector precision, monorepo discovery, CI gate + honest docs restructure
2 parents 2d24cce + 577de38 commit 6d1dfbd

29 files changed

Lines changed: 2050 additions & 4864 deletions

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,29 @@ jobs:
5757

5858
- name: Verify package contents
5959
run: npm pack --dry-run
60+
61+
self-scan:
62+
name: Self-scan (dogfood, --fail-on high)
63+
runs-on: ubuntu-latest
64+
timeout-minutes: 15
65+
66+
steps:
67+
- name: Checkout
68+
uses: actions/checkout@v5
69+
70+
- name: Setup Node.js
71+
uses: actions/setup-node@v5
72+
with:
73+
node-version: 24
74+
cache: npm
75+
cache-dependency-path: csreview/package-lock.json
76+
77+
- name: Install dependencies
78+
run: npm ci
79+
working-directory: csreview
80+
81+
- name: Install Semgrep
82+
run: python -m pip install --upgrade semgrep
83+
84+
- name: Run CSReview against its own repository
85+
run: node csreview/src/cli.js . --agent-name ci --no-update-check --fail-on high

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ security-findings.md
2121
*_security-findings.md
2222
**/*_security-report.html
2323
**/*_security-findings.md
24+
*_security.sarif
25+
**/*_security.sarif
26+
*_local-dast-report*.html
27+
*_local-dast-findings*.md
28+
**/*_local-dast-report*.html
29+
**/*_local-dast-findings*.md
30+
*_db-dump-guide.html
31+
**/*_db-dump-guide.html
2432

2533
CSREVIEW-ANALISES.md
2634
CSREVIEW-ANALISES*.md

README.md

Lines changed: 235 additions & 2447 deletions
Large diffs are not rendered by default.

csreview/SKILL.md

Lines changed: 159 additions & 1860 deletions
Large diffs are not rendered by default.

csreview/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

csreview/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "csreview",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Development-time local workspace security alignment for AI coding agents",
55
"main": "src/index.js",
66
"bin": {
@@ -29,6 +29,7 @@
2929
"license": "MIT",
3030
"files": [
3131
"src/",
32+
"reference/",
3233
"SKILL.md",
3334
"README.md",
3435
"LICENSE"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# CSReview Reference - Compliance & Framework Correlation
2+
3+
**Honesty contract**: the engine maps findings to the frameworks below by CWE
4+
correlation only (see `COMPLIANCE_MAP` in `src/detector.js`). It does NOT
5+
compute per-article PASS/FAIL verdicts, ASVS coverage percentages, or SLSA
6+
levels, and the agent MUST NOT fabricate such numbers in summaries. Per-article
7+
or per-requirement assessments may appear in a report only when a human or the
8+
agent explicitly evaluated that requirement against the workspace and says so.
9+
Compliance output is **indicative correlation, not an audited compliance
10+
verification**.
11+
12+
## SLSA Supply Chain Review (SLSA Build L3, v1.2)
13+
14+
Checklist for the agent's supply-chain review. Reference requirements with
15+
track + level + version (e.g. "SLSA Build L3 (v1.2)").
16+
17+
**Source integrity**: signed commits, branch protection, required reviews,
18+
CODEOWNERS, repository permission audit, 2FA enforcement.
19+
20+
**Build integrity**: automated CI/CD, reproducible/hermetic builds, hosted build
21+
service, signed build attestations/provenance, artifact signing
22+
(Sigstore/cosign/GPG), base image verification.
23+
24+
**Dependency security**: lock files present and committed, exact version
25+
pinning, integrity hashes, SBOM generation and maintenance, automated
26+
vulnerability scanning, typosquatting review, license audit.
27+
28+
**Deployment security**: dev/staging/production separation, secrets in a
29+
vault/manager (not code or committed env files), restricted and audited
30+
deployment access, rollback capability, audited IaC templates.
31+
32+
## OWASP ASVS 5.0.0 Review Areas
33+
34+
Systematic verification areas from the OWASP Application Security Verification
35+
Standard 5.0.0 (stable since 2025-05-30). Reference requirements with the
36+
version, e.g. `v5.0.0-1.2.5`. The engine's `COMPLIANCE_MAP` correlates CWEs to
37+
ASVS chapters; chapter-by-chapter verification is agent/human work.
38+
39+
- **V1 Architecture**: threat model, security architecture, trust boundaries
40+
- **V2 Authentication**: password policy, MFA, credential storage
41+
(bcrypt/scrypt/Argon2 — never MD5/SHA1), lockout, recovery
42+
- **V3 Session Management**: random session IDs, lifecycle/timeout, cookie
43+
flags (HttpOnly/Secure/SameSite), session binding
44+
- **V4 Access Control**: default deny, function-level and data-level checks,
45+
JWT verification, OAuth scopes
46+
- **V5 Validation & Encoding**: input validation at every entry point,
47+
context-aware output encoding, deserialization safety, mass assignment
48+
- **V6 Stored Cryptography**: key management, modern algorithms (AES-256,
49+
RSA-2048+; never DES/RC4), CSPRNG, key rotation
50+
- **V7 Errors & Logging**: no sensitive info in errors, security event logging,
51+
log integrity, PII redaction, log injection prevention
52+
- **V8 Data Protection**: classification, encryption at rest and in transit
53+
(TLS 1.2+), PII minimization, retention/deletion
54+
- **V9 Communication**: TLS configuration, certificate validation/pinning, HSTS
55+
- **V10 Malicious Code**: no backdoors/time bombs, anti-tampering
56+
- **V11 Business Logic**: flow validation, abuse prevention, rate limiting
57+
- **V12 Files & Resources**: upload restrictions, execution prevention, path
58+
traversal protection
59+
- **V13 API & Web Services**: API authn/authz, rate limiting, GraphQL
60+
introspection off in production, WebSocket security
61+
- **V14 Configuration**: secure build/deploy, security headers, debug off in
62+
production
63+
64+
## Regulatory Correlation Checklists
65+
66+
These lists support the agent when the user asks for a privacy/compliance
67+
review. Many items are process/documentation controls that cannot be verified
68+
from source code alone — say so explicitly instead of guessing.
69+
70+
### LGPD (Brazil)
71+
72+
Data inventory and classification; documented legal basis; granular consent and
73+
withdrawal; data subject rights endpoints (access, correction, deletion,
74+
portability); DPO contact; cross-border transfer safeguards; 72h ANPD breach
75+
notification plan; privacy by design/default; processor agreements.
76+
77+
### GDPR (EU)
78+
79+
LGPD items plus: DPIA for high-risk processing; records of processing (ROPA);
80+
right to be forgotten (automated deletion); machine-readable data portability;
81+
timestamped, versioned consent records; EU representative for non-EU companies;
82+
SCCs for international transfers.
83+
84+
### SOC 2 Type II
85+
86+
Security (access controls), availability (SLA monitoring, DR), processing
87+
integrity (validation, error handling), confidentiality (classification,
88+
encryption), privacy (collection/use/retention/disposal), continuous monitoring
89+
and audit logging, change management.
90+
91+
### HIPAA (US)
92+
93+
PHI mapping in the codebase; role-based access with minimum-necessary; audit
94+
logging of PHI access; AES-256 at rest and TLS 1.2+ in transit; BAAs with third
95+
parties handling PHI; HIPAA-specific breach procedures; de-identification
96+
methods; integrity controls. (BAA and similar contractual controls are process
97+
items — not verifiable from code.)
98+
99+
### CCPA/CPRA (California)
100+
101+
Right to know/delete/opt-out/correct/limit; "Do Not Sell" mechanism when
102+
applicable; opt-in for sensitive personal information; service provider
103+
agreements; data minimization; documented retention schedules.

csreview/reference/local-dast.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# CSReview Reference - Phase 9 Optional Local DAST
2+
3+
Full protocol for the optional, post-remediation, local-only dynamic
4+
complement. The core rules and the required user-facing confirmation prompt
5+
live in SKILL.md; this file holds the operational detail.
6+
7+
## What the built-in probe actually does
8+
9+
`csreview <dir> --local-dast-url <url> --confirm-local-dast` performs a
10+
conservative, non-mutating HTTP check against the confirmed loopback target:
11+
reachability, browser security headers (Content-Security-Policy,
12+
X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy),
13+
and CORS behavior against a hostile origin. It is **not** a penetration test,
14+
it never follows redirects, and it aborts immediately if a response points to
15+
an external host.
16+
17+
## Engine guards (enforced in code, not just documented)
18+
19+
- Target hostname must be `localhost`, `127.0.0.1`, or `[::1]`; anything else
20+
is rejected before any request.
21+
- `--confirm-local-dast` is required; without it the run stops with the
22+
confirmation instructions.
23+
- Redirects are not followed (`redirect: manual`); an external `Location`
24+
aborts the phase.
25+
- Reports are written only inside `csreview-reports/`.
26+
- An advisory pre-flight scans `.env`, `.env.local`, and `.env.development` for
27+
external hosts and surfaces them as `DAST-SUSPECTED` so you can verify the
28+
local app does not proxy probe traffic outward. It is advisory because real
29+
development env files almost always reference external services.
30+
31+
## Status labels (honest semantics)
32+
33+
- `DAST-SUSPECTED` — anomalous local response that requires human review.
34+
- `DAST-CLEAN` — the checked condition passed for the local target.
35+
- `DAST-CONFIRMED`**reserved label, never produced by the built-in probe.**
36+
It may only appear when a dedicated local DAST tool (run separately by the
37+
agent, e.g. OWASP ZAP or Nikto against the same confirmed loopback target,
38+
after the same pre-flight and confirmation) dynamically reproduced an issue
39+
with clear evidence. If no such tool ran, no finding may carry this label.
40+
41+
## Outputs
42+
43+
- `csreview-reports/<agent>_local-dast-report.html`
44+
- `csreview-reports/<agent>_local-dast-findings.md`
45+
- With a run ID: timestamped history copies
46+
(`<agent>_local-dast-report-<runId>.html` / `...-findings-<runId>.md`) so
47+
re-running after remediation never overwrites prior evidence.
48+
- `<agent>_db-dump-guide.html` — a read-only, per-backend guide for preparing
49+
an isolated local database copy BEFORE any database-level testing (schema-only
50+
dumps, synthetic users, zero real PII; never dump production).
51+
52+
## Hard limits
53+
54+
Never probe external IPs, domains, staging, or production. Never use
55+
destructive payloads or DELETE. Do not send mutating POST/PUT/PATCH unless the
56+
user provided an explicit local test endpoint allowlist and confirmed the data
57+
mutation risk. If the test uses a database copy, it must be deliberately
58+
created, stored securely, and sanitized or minimized where needed.

csreview/reference/reports.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# CSReview Reference - What the Engine Reports Actually Contain
2+
3+
The engine writes every report deterministically. The agent never handcrafts
4+
report files and never invents metrics that the engine does not compute. In
5+
particular there is **no** "ASVS coverage %", "SLSA level", or per-article
6+
compliance PASS/FAIL anywhere in the generated reports — see
7+
`reference/compliance-frameworks.md` for what compliance correlation means.
8+
9+
## HTML report (`<agent>_security-report.html`)
10+
11+
For human review, generated in a self-contained file: executive summary with
12+
the 0-100 score (severity-capped: any CRITICAL caps it at 49, any HIGH at 74),
13+
severity and category charts, findings-by-origin breakdown (which tool reported
14+
what, corroborated findings first), tool execution status (which engine tools
15+
ran, versions, raw counts), filterable finding cards (severity, category, file
16+
search), per-finding metadata (CWE link, OWASP category, confidence, compliance
17+
correlation, vibe-risk flag, redacted evidence snippet, theoretical
18+
exploitation hypothesis, remediation guidance, references), and an "Export as
19+
JSON" button. Secrets are redacted before rendering; all dynamic content is
20+
HTML-escaped.
21+
22+
## Markdown report (`<agent>_security-findings.md`)
23+
24+
For coding agents (always English). Actual sections emitted by the engine:
25+
26+
1. **Executive Summary** — score, totals by severity, mode, tool status
27+
2. **Findings Index** — table of every finding with file:line
28+
3. **Detailed Findings** — full canonical finding objects
29+
4. **Category Analysis** — counts and highlights per category
30+
5. **Compliance Impact** — CWE-correlated framework references (indicative)
31+
6. **Fix Priority Order** — Immediate (CRITICAL) → Short-term (HIGH) →
32+
Medium-term (MEDIUM) → Low Priority (LOW/INFO)
33+
7. **Remediation Guidance** — per-finding guidance, never an exact patch to
34+
apply blindly
35+
8. **Scan Metadata** — timestamps, file counts, tool versions, suppression and
36+
baseline counts
37+
38+
## SARIF report (`<agent>_security.sarif`)
39+
40+
SARIF 2.1.0 for CI and GitHub code scanning. It never embeds raw vulnerable
41+
code, so secrets are not leaked into uploaded artifacts. Pair it with
42+
`--fail-on <severity>` to gate merges.
43+
44+
## Canonical finding schema
45+
46+
Exchanged by the detector, tool normalizers, subagent partials, and all report
47+
generators:
48+
49+
```json
50+
{
51+
"id": "SQL_INJECTION_src-auth-ts_45",
52+
"severity": "CRITICAL|HIGH|MEDIUM|LOW|INFO",
53+
"category": "Injection",
54+
"name": "...",
55+
"description": "...",
56+
"file": "src/auth.ts",
57+
"line": 45,
58+
"vulnerableCode": "redacted/snippet",
59+
"cwe": "CWE-89",
60+
"owasp": "A03:2021-Injection",
61+
"fix": "...",
62+
"confidence": "CONFIRMED|TOOL-ONLY|HIGH|MEDIUM|LOW",
63+
"exploitation": "theoretical hypothesis, never a validated exploit",
64+
"references": ["https://..."],
65+
"source": "csreview-detector|semgrep|npm-audit|pnpm-audit|bun-audit|osv-scanner|gitleaks|trivy|gosec|bandit|subagent:<domain>",
66+
"vibeRisk": false,
67+
"compliance": "OWASP ASVS V5.3, GDPR Art.32 (CWE correlation)"
68+
}
69+
```
70+
71+
Confidence semantics: `CONFIRMED` = corroborated by more than one independent
72+
source (e.g. detector + Semgrep at the same file:line:CWE); `TOOL-ONLY` = one
73+
external tool; `HIGH|MEDIUM|LOW` = heuristic detector confidence. Findings in
74+
test/fixture/example paths are downgraded to LOW instead of hidden.

csreview/reference/review-modes.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# CSReview Reference - Code Review Modes
2+
3+
Detail for the five review modes summarized in SKILL.md. These are agent
4+
methodologies layered on top of the engine run; they do not change what the
5+
engine writes.
6+
7+
## Mode 1 - Standard Code Review (`@csreview review [files]`)
8+
9+
Quality: readability, naming, complexity, dead code, duplication, SOLID/DRY,
10+
separation of concerns. Architecture: pattern fit, coupling, dependency
11+
direction. Performance: algorithmic complexity, leaks, N+1 queries, caching,
12+
bundle impact. Testing: coverage gaps, missing edge cases, isolation, mock
13+
overuse. Documentation: missing docstrings on public APIs, stale comments,
14+
undocumented breaking changes.
15+
16+
## Mode 2 - Adversarial Review (`@csreview adversarial [files]`)
17+
18+
Red-team mindset: actively try to break the change. Boundary exploitation,
19+
race conditions, resource exhaustion, error-handling bypass, state corruption,
20+
validation gaps at every layer. Failure modes: external service down, malformed
21+
input, extreme load, concurrent modification, full disk/memory. Edge cases:
22+
empty/null, maximum sizes, Unicode, timezones, float precision, integer
23+
overflow. Ask: "How can I make this fail?", "What is the worst input?", "What
24+
assumption can be wrong?", "Can I bypass this check?"
25+
26+
## Mode 3 - Security-Focused Review (`@csreview security-review [files]`)
27+
28+
Apply the security and database checklists (see
29+
`reference/security-checklists.md`) to the specific changed files, assess the
30+
security impact of each change, and flag architectural changes that require
31+
threat-model updates. Vibe-risk heuristics from the engine apply here.
32+
33+
## Mode 4 - Requesting a Review (`@csreview request-review [scope]`)
34+
35+
Protocol: identify scope (files/functions/modules) → choose depth → select
36+
modes (quality/adversarial/security) → build a checklist for the change type →
37+
execute → prioritize by severity and actionability. Change types: new feature
38+
(full + adversarial), bug fix (correctness + regression), refactor (behavior
39+
preservation), configuration (security impact), dependency update
40+
(vulnerability + license), migration (integrity + rollback).
41+
42+
## Mode 5 - Receiving Review Findings
43+
44+
(`@csreview review csreview-reports/codex_security-findings.md`)
45+
46+
Parse the Markdown report → categorize by severity → for each finding:
47+
acknowledge, research the fix (official docs first), propose, apply (coding
48+
agent's responsibility, never CSReview's), verify nothing new broke. Fix
49+
verification checklist: addresses the specific vulnerability; preserves
50+
behavior; follows framework practice; introduces no new issues; tested;
51+
documented when behavior changes. After all fixes, re-run the engine —
52+
optionally with `--baseline` so only NEW findings fail CI.

0 commit comments

Comments
 (0)