feat(dast): scans log in with the target's credentials (#1000) #1003

Merged
sharang merged 1 commits from feat/dast-auth-headers into main 2026-11-16 02:31:38 +00:00
Owner

Part 1 of #1000 (header logins). Form and Keycloak login through the browser follow in part 2, so this does not close the issue.

DastTarget.auth_config was stored but nothing in compliance-dast read it. Every DAST request went out unauthenticated, so a scan of anything behind a login tested the login page only.

Login

  • New compliance_dast::auth::login_headers:
    • basic (username + password), bearer (token), cookie (token = name=value), plus extra headers;
    • values marked sensitive, so they never appear in a Debug print;
    • form, an unknown method or a missing secret are refused.
  • DastOrchestrator::run_scan builds one guarded client per scan with those default headers, used by recon, crawler and agents.
  • The auth-bypass agent keeps the anonymous client, since it asks as a stranger.
  • A login that cannot be sent fails the scan with Login: <reason> instead of quietly testing anonymously.

API and storage

  • POST /api/v1/dast/targets takes an auth block and refuses (400) a login the scan could not send.
  • The login is stored sealed and the target is returned with its _id. Before, the response had no id.
  • Header values are sealed too, through the new Credentials::credential_maps_mut (SecretBox::seal_unsealed / open_in_place handle maps value by value; a value that does not open is dropped).
  • trigger_scan and the pipeline's DAST trigger open the secrets in memory only.
  • ensure_dast_target: the wizard's basic login lands in password (it went to token before), and the copy is sealed before it is stored.

Scope fixes that matter once requests carry a login

  • The crawler kept links to the origin but not forms: a form posting to another site became an endpoint the agents attacked. Forms now stay on the target's origin.
  • Same-origin compares scheme, host and port (it ignored the port).
  • The auth-bypass agent sent PUT/PATCH/DELETE to every endpoint regardless of "destructive tests", and reported a finding when its own DELETE succeeded. Write methods are now sent only with destructive tests allowed; a stranger's accepted write is the finding.

CI: compliance-dast was neither linted nor tested. Added Clippy (dast) (library only: its test modules predate items_after_test_module, 8 files, separate cleanup) and Tests (dast).

Tests

  • compliance-dast/tests/login.rs, against a local fake site that serves only a logged-in visitor:
    • the crawl reaches member pages and skips forms to another site or port;
    • a scan sends the login except for the bypass probes, and no write method without destructive tests;
    • a form login fails the scan before any request.
  • auth.rs unit tests: each method, missing secrets, bad headers, sensitivity.
  • secret_box: headers sealed once and opened; an unopenable header dropped.
  • API (e2e, Mongo): the login is stored sealed, never returned, and the id is returned; form, missing-token and unknown logins get 400.

Run locally: cargo test -p compliance-dast, core + agent --lib (1074 passed), core --tests, the DAST e2e tests against MongoDB, clippy (CI flags) for core, agent and the dast library, dashboard and MCP check, fmt.

Docs: features/dast.md now says what actually works.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9

Part 1 of #1000 (header logins). Form and Keycloak login through the browser follow in part 2, so this does not close the issue. `DastTarget.auth_config` was stored but nothing in `compliance-dast` read it. Every DAST request went out unauthenticated, so a scan of anything behind a login tested the login page only. **Login** - New `compliance_dast::auth::login_headers`: - `basic` (username + password), `bearer` (token), `cookie` (token = `name=value`), plus extra `headers`; - values marked sensitive, so they never appear in a `Debug` print; - `form`, an unknown method or a missing secret are refused. - `DastOrchestrator::run_scan` builds one guarded client per scan with those default headers, used by recon, crawler and agents. - The **auth-bypass agent keeps the anonymous client**, since it asks as a stranger. - A login that cannot be sent **fails the scan** with `Login: <reason>` instead of quietly testing anonymously. **API and storage** - `POST /api/v1/dast/targets` takes an `auth` block and refuses (400) a login the scan could not send. - The login is stored sealed and the target is returned with its `_id`. Before, the response had no id. - Header values are sealed too, through the new `Credentials::credential_maps_mut` (`SecretBox::seal_unsealed` / `open_in_place` handle maps value by value; a value that does not open is dropped). - `trigger_scan` and the pipeline's DAST trigger open the secrets in memory only. - `ensure_dast_target`: the wizard's basic login lands in `password` (it went to `token` before), and the copy is sealed before it is stored. **Scope fixes that matter once requests carry a login** - The crawler kept links to the origin but not forms: a form posting to another site became an endpoint the agents attacked. Forms now stay on the target's origin. - Same-origin compares scheme, host **and port** (it ignored the port). - The auth-bypass agent sent `PUT`/`PATCH`/`DELETE` to every endpoint regardless of "destructive tests", and reported a finding when its own `DELETE` succeeded. Write methods are now sent only with destructive tests allowed; a stranger's accepted write is the finding. **CI:** `compliance-dast` was neither linted nor tested. Added `Clippy (dast)` (library only: its test modules predate `items_after_test_module`, 8 files, separate cleanup) and `Tests (dast)`. **Tests** - `compliance-dast/tests/login.rs`, against a local fake site that serves only a logged-in visitor: - the crawl reaches member pages and skips forms to another site or port; - a scan sends the login except for the bypass probes, and no write method without destructive tests; - a form login fails the scan before any request. - `auth.rs` unit tests: each method, missing secrets, bad headers, sensitivity. - `secret_box`: headers sealed once and opened; an unopenable header dropped. - API (`e2e`, Mongo): the login is stored sealed, never returned, and the id is returned; form, missing-token and unknown logins get 400. Run locally: `cargo test -p compliance-dast`, core + agent `--lib` (1074 passed), core `--tests`, the DAST `e2e` tests against MongoDB, clippy (CI flags) for core, agent and the dast library, dashboard and MCP check, fmt. Docs: `features/dast.md` now says what actually works. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang added 1 commit 2026-11-14 11:03:11 +00:00
feat(dast): scans log in with the target's credentials (#1000)
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 / Agent integration (pull_request) Successful in 4m37s
CI / Check (pull_request) Successful in 20m29s
6cc4ab67bb
Part 1 of #1000: the header logins. A target's DastAuthConfig was
stored but never read, so every DAST request went out unauthenticated
and a scan of anything behind a login tested only the login page.

- compliance-dast::auth turns basic, bearer and cookie logins plus extra
  headers into sensitive default headers of a per-scan client; recon,
  crawler and the agents use it, the auth-bypass agent asks as a
  stranger. A login that cannot be sent (form login, a missing secret,
  an unknown method) fails the scan with the reason.
- POST /api/v1/dast/targets takes an `auth` block, refuses a login the
  scan could not send, stores it sealed (header values too, via the new
  Credentials::credential_maps_mut) and returns the target with its id.
  Scans open the stored secrets in memory only.
- The wizard's basic login lands in the password, not the token.
- The crawler keeps forms to the target's origin (scheme, host, port),
  so payloads and the login never go to another site.
- The auth-bypass agent sends PUT/PATCH/DELETE only with destructive
  tests allowed (it sent them always and reported its own success).
- CI lints the compliance-dast library and runs its tests.

Form and Keycloak login follow in part 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
sharang merged commit f5ac5321bd into main 2026-11-16 02:31:38 +00:00
sharang deleted branch feat/dast-auth-headers 2026-11-16 02:31:39 +00:00
Sign in to join this conversation.