feat(findings): add pentest and DAST findings by hand or from a report (#337) #349

Merged
sharang merged 1 commits from feat/manual-findings into main 2026-09-23 14:46:35 +00:00
Owner

Closes #337. Pilot P1, item H. Stacked on #348.

Why

A DAST run on the Werkbank or a penetration test is done by hand. Its results had no way into Prüfwerk, so they could not sit next to the scan's findings, carry CRA refs or reach the evidence.

Agent

  • Endpoints:
    • POST /api/v1/targets/{id}/findings adds one finding (201). The same finding (tool + title + location) again gives 409.
    • POST /api/v1/targets/{id}/findings/import?format=sarif|zap&kind=pentest|dast takes the report itself as the body (limit 20 MB) and returns {total, imported, duplicates}. Importing the same report again adds nothing. A document that is not the named format gives 422.
  • Who: both need IT_ADMIN, otherwise 403. The tester is invited into the customer's organisation with that role. The dev tenant's synthetic user now holds it too.
  • import module:
    • ManualFinding becomes an ordinary Finding: scanner is the tool or manual, the location is stored in file_path, and evidence is kept in code_snippet, truncated at 4,000 characters.
    • SARIF 2.1.0: severity from security-severity, else the level; CWE from external/cwe/cwe-N tags; the rule's short description, full description and help. runs is required, so {} is refused rather than imported as empty.
    • ZAP JSON (traditional): one finding per alert, not per URL; the first instance is the location and the description gives the count. Risk codes 0–3, HTML stripped, cweid -1 means none.
  • Model:
    • new ScanType::Pentest;
    • Finding.reported_by and Finding.reproduction (serde default, so old rows still read).
  • CRA refs: ControlMap::controls_for_cwe. A human-verified weakness maps through any tool's binding for its CWE; rule-only bindings are never matched this way.

Dashboard

  • Target details get a "Befunde aus manuellen Tests" panel: test kind, a form (title, severity, location, CWE, CVSS, tool, description, evidence, reproduction, fix), and an import (format + file, streamed through like uploads).
  • It shows "N importiert, M bereits vorhanden", or the agent's refusal (for example, 403 for a non-admin).
  • The finding detail shows the reproduction steps and "Erfasst von".
  • Pentest is in the type filter and labels. German and English.

Docs

docs/guide/manual-findings.md: fields, both formats, curl examples. Added to the sidebar.

Verification

  • Unit tests (agent):
    • SARIF: rule details, security-severity over level, a CWE tag, refusal of non-SARIF;
    • ZAP: one finding per alert, HTML stripped, -1 means no CWE;
    • CWE normalisation and score thresholds; fingerprints; the admin check; form parsing.
    • 392 agent lib tests, control-map tests (controls_for_cwe) and 71 core lib tests pass.
  • Integration (MongoDB): tests/manual_findings.rs walks through add → 409 → import ×2 (2 imported, then 2 duplicates) → 422 for non-SARIF → 404 for an unknown target, then checks the stored rows and CRA refs. The credentials, tenant_isolation, tenant_status_middleware and demo_seed suites still pass with the dev user as admin.
  • clippy with the CI flags (agent, mcp, dashboard server/web); fmt; 40 dashboard lib tests.
  • Not yet seen in a browser.
  • Unrelated and pre-existing: compliance-core/tests/models.rs does not compile on main (TrackedRepository). CI only runs core --lib.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #337. Pilot P1, item H. **Stacked on #348.** ## Why A DAST run on the Werkbank or a penetration test is done by hand. Its results had no way into Prüfwerk, so they could not sit next to the scan's findings, carry CRA refs or reach the evidence. ## Agent - **Endpoints:** - `POST /api/v1/targets/{id}/findings` adds one finding (201). The same finding (tool + title + location) again gives **409**. - `POST /api/v1/targets/{id}/findings/import?format=sarif|zap&kind=pentest|dast` takes the report itself as the body (limit 20 MB) and returns `{total, imported, duplicates}`. Importing the same report again adds nothing. A document that is not the named format gives **422**. - **Who:** both need `IT_ADMIN`, otherwise 403. The tester is invited into the customer's organisation with that role. The dev tenant's synthetic user now holds it too. - **`import` module:** - `ManualFinding` becomes an ordinary `Finding`: `scanner` is the tool or `manual`, the location is stored in `file_path`, and evidence is kept in `code_snippet`, truncated at 4,000 characters. - **SARIF 2.1.0:** severity from `security-severity`, else the level; CWE from `external/cwe/cwe-N` tags; the rule's short description, full description and help. `runs` is required, so `{}` is refused rather than imported as empty. - **ZAP JSON (traditional):** one finding per alert, not per URL; the first instance is the location and the description gives the count. Risk codes 0–3, HTML stripped, `cweid -1` means none. - **Model:** - new `ScanType::Pentest`; - `Finding.reported_by` and `Finding.reproduction` (serde default, so old rows still read). - **CRA refs:** `ControlMap::controls_for_cwe`. A human-verified weakness maps through any tool's binding for its CWE; rule-only bindings are never matched this way. ## Dashboard - Target details get a **"Befunde aus manuellen Tests"** panel: test kind, a form (title, severity, location, CWE, CVSS, tool, description, evidence, reproduction, fix), and an import (format + file, streamed through like uploads). - It shows "N importiert, M bereits vorhanden", or the agent's refusal (for example, 403 for a non-admin). - The finding detail shows the reproduction steps and "Erfasst von". - `Pentest` is in the type filter and labels. German and English. ## Docs `docs/guide/manual-findings.md`: fields, both formats, curl examples. Added to the sidebar. ## Verification - Unit tests (agent): - SARIF: rule details, `security-severity` over level, a CWE tag, refusal of non-SARIF; - ZAP: one finding per alert, HTML stripped, `-1` means no CWE; - CWE normalisation and score thresholds; fingerprints; the admin check; form parsing. - 392 agent lib tests, control-map tests (`controls_for_cwe`) and 71 core lib tests pass. - **Integration (MongoDB):** `tests/manual_findings.rs` walks through add → 409 → import ×2 (2 imported, then 2 duplicates) → 422 for non-SARIF → 404 for an unknown target, then checks the stored rows and CRA refs. The credentials, tenant_isolation, tenant_status_middleware and demo_seed suites still pass with the dev user as admin. - clippy with the CI flags (agent, mcp, dashboard `server`/`web`); fmt; 40 dashboard lib tests. - Not yet seen in a browser. - Unrelated and pre-existing: `compliance-core/tests/models.rs` does not compile on `main` (`TrackedRepository`). CI only runs core `--lib`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang changed target branch from feat/sbom-i18n to main 2026-09-23 14:38:57 +00:00
sharang added 1 commit 2026-09-23 14:38:57 +00:00
feat(findings): add pentest and DAST findings by hand or from a report (#337)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m6s
9e7e1b3ebb
A DAST run or penetration test is done by a person. Its results had no
way into Prüfwerk, so they could not sit next to the scan's findings or
go into the evidence.

- POST /api/v1/targets/{id}/findings adds one finding; the same finding
  (tool, title, location) twice is a 409.
- POST /api/v1/targets/{id}/findings/import?format=sarif|zap&kind=... reads
  a SARIF 2.1.0 or OWASP ZAP JSON report (up to 20 MB); findings already on
  the target are counted, not added again. A document that is not the named
  format is a 422.
- Both need the organisation's IT_ADMIN role (the dev tenant's user now has
  it). The finding records who added it and how to reproduce it.
- New ScanType::Pentest. A finding's CWE maps it to CRA controls through
  the control map (controls_for_cwe: any tool's binding for that CWE).
- Dashboard: a panel on each target's details with the form and the
  import; the finding detail shows the reproduction steps and who reported
  it. German and English.
- Guide: docs/guide/manual-findings.md.

Tests: SARIF and ZAP parsing, CWE and score handling, fingerprints, the
admin check, and an integration test (MongoDB) that adds, re-adds, imports
twice, and refuses a non-SARIF document and an unknown target.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang force-pushed feat/manual-findings from eca794cd61 to 9e7e1b3ebb 2026-09-23 14:38:58 +00:00 Compare
sharang merged commit a5fb0aa947 into main 2026-09-23 14:46:35 +00:00
Sign in to join this conversation.