Closes#256. Stacked on #292 (feat/fail-closed-config) — it needs AppEnv from there, so the base is that branch; review this diff alone, and it retargets to main once #292 merges.
Why
Every target says where the scanner should connect: a git URL, a live URL, a DAST base URL, a pentest app URL, a PLC endpoint. Nothing checked what those resolve to, and the agent sits on the platform network. A tenant could aim a scan at pruefwerk-mongo:27017, at 169.254.169.254, or at file:///data/compliance-scanner/ssh/id_ed25519, and read the result back as findings — server-side request forgery with a UI in front of it, plus a straight local-file read on the blob path.
The guard
compliance_core::net_guard, dependency-free so the agent, the DAST crate and the runner can all use it:
Layer
Use
check_url / check_git_url
scheme + host rules. http(s) for fetches; git also allows ssh but never file://, git:// or a bare path (including scp-style git@host:org/repo)
check_ip
loopback, private, carrier-NAT, link-local (including 169.254.169.254), documentation, benchmarking, reserved — in v4, v6 and v4-mapped-v6 form
check_resolved
resolves a name and requires every answer to pass, so a host returning one public and one private address is refused
Internal names are refused by shape as well: single-label hosts (mongo, compliance-agent), localhost, .internal, .local, .home.arpa.
Where it is enforced
git ingest and live-URL ingest (ingest/mod.rs)
DAST target creation, and again at scan start, re-resolved — a hostname can be repointed after registration, and targets exist that predate this policy
the pentest wizard's app_url
the ICS probe (werkbank-exec/src/ics), which opens raw TCP connections
Blob artifacts (firmware, archives, PLC projects, mobile packages) now require an uploaded stored_path. source_ref was previously read as a filesystem path when no upload existed, so an API caller could name any file the agent can read and ingest it as their own artifact. Uploads already set stored_path, so the wizard, the upload handler and the demo seeder are unaffected; only the JSON "point at a server path" path is gone.
On-premise
A Werkbank runner inside a plant network is aimed at 10.x PLCs on purpose, so PW_ALLOW_PRIVATE_TARGETS=1 relaxes the policy. A hardened deployment ignores it — the cloud agent shares a network with the platform's own services. Documented in docs/guide/scanning.md.
Not covered yet (follow-ups, not regressions)
Redirects and DNS rebinding. A name that passes can resolve elsewhere by the time the connection is made, and a redirect can lead anywhere. Pinning the resolved address into the connection and validating each redirect hop is the next layer; I'd file it under MVP-0 if you want it before go-live.
The ICS probe refuses by logging and returning no findings. Surfacing it as a skipped stage needs the signature change in #284.
New tests: 9 in net_guard (platform hostnames, private/loopback/link-local/metadata/v4-mapped, ordinary public targets, parsing incl. IPv6 and userinfo, non-HTTP schemes and local paths, git scheme rules, the on-premise policy, resolution of literals); 3 in ingest (git remotes that would read our own disk, live URLs at internal hosts, a blob artifact naming a server path); 1 in the ICS probe (internal endpoints are never probed).
Closes #256. **Stacked on #292** (`feat/fail-closed-config`) — it needs `AppEnv` from there, so the base is that branch; review this diff alone, and it retargets to `main` once #292 merges.
## Why
Every target says where the scanner should connect: a git URL, a live URL, a DAST base URL, a pentest app URL, a PLC endpoint. Nothing checked what those resolve to, and the agent sits on the platform network. A tenant could aim a scan at `pruefwerk-mongo:27017`, at `169.254.169.254`, or at `file:///data/compliance-scanner/ssh/id_ed25519`, and read the result back as findings — server-side request forgery with a UI in front of it, plus a straight local-file read on the blob path.
## The guard
`compliance_core::net_guard`, dependency-free so the agent, the DAST crate and the runner can all use it:
| Layer | Use |
|---|---|
| `check_url` / `check_git_url` | scheme + host rules. `http(s)` for fetches; git also allows `ssh` but never `file://`, `git://` or a bare path (including scp-style `git@host:org/repo`) |
| `check_ip` | loopback, private, carrier-NAT, link-local (including `169.254.169.254`), documentation, benchmarking, reserved — in v4, v6 and v4-mapped-v6 form |
| `check_resolved` | resolves a name and requires **every** answer to pass, so a host returning one public and one private address is refused |
Internal names are refused by shape as well: single-label hosts (`mongo`, `compliance-agent`), `localhost`, `.internal`, `.local`, `.home.arpa`.
## Where it is enforced
- git ingest and live-URL ingest (`ingest/mod.rs`)
- DAST target creation, and again at **scan start**, re-resolved — a hostname can be repointed after registration, and targets exist that predate this policy
- the pentest wizard's `app_url`
- the ICS probe (`werkbank-exec/src/ics`), which opens raw TCP connections
Blob artifacts (firmware, archives, PLC projects, mobile packages) now require an uploaded `stored_path`. `source_ref` was previously read as a filesystem path when no upload existed, so an API caller could name any file the agent can read and ingest it as their own artifact. Uploads already set `stored_path`, so the wizard, the upload handler and the demo seeder are unaffected; only the JSON "point at a server path" path is gone.
## On-premise
A Werkbank runner inside a plant network is aimed at `10.x` PLCs on purpose, so `PW_ALLOW_PRIVATE_TARGETS=1` relaxes the policy. A hardened deployment ignores it — the cloud agent shares a network with the platform's own services. Documented in `docs/guide/scanning.md`.
## Not covered yet (follow-ups, not regressions)
- **Redirects and DNS rebinding.** A name that passes can resolve elsewhere by the time the connection is made, and a redirect can lead anywhere. Pinning the resolved address into the connection and validating each redirect hop is the next layer; I'd file it under MVP-0 if you want it before go-live.
- The ICS probe refuses by logging and returning no findings. Surfacing it as a skipped stage needs the signature change in #284.
## Verification
- `cargo fmt --all --check` clean; `cargo clippy -p compliance-core -p compliance-agent -p compliance-mcp -p werkbank-exec -p control-map -- -D warnings` clean.
- `cargo test -p compliance-core -p compliance-agent -p werkbank-exec -p control-map --lib` → **327 + 69 + 28 + 9 pass**.
- New tests: 9 in `net_guard` (platform hostnames, private/loopback/link-local/metadata/v4-mapped, ordinary public targets, parsing incl. IPv6 and userinfo, non-HTTP schemes and local paths, git scheme rules, the on-premise policy, resolution of literals); 3 in ingest (git remotes that would read our own disk, live URLs at internal hosts, a blob artifact naming a server path); 1 in the ICS probe (internal endpoints are never probed).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang
changed target branch from feat/fail-closed-config to main2026-09-20 21:37:26 +00:00
Scans are aimed by the customer — a git URL, a live URL, a DAST base URL, a
pentest app URL, a PLC endpoint — and nothing checked where those resolve to.
A tenant could point a scan at `pruefwerk-mongo:27017`, at
`169.254.169.254`, or at `file:///data/compliance-scanner/ssh/id_ed25519`,
and read the result back as findings. Server-side request forgery with a UI
in front of it, and on the blob path a straight local-file read.
New `compliance_core::net_guard`, dependency-free so every crate can use it:
- `check_url` / `check_git_url` — scheme and host rules. http(s) for fetches;
git additionally allows ssh but never `file://`, `git://` or a bare path
(including scp-style `git@host:org/repo`).
- `check_ip` — refuses loopback, private, carrier-NAT, link-local (with the
cloud-metadata address), documentation, benchmarking and reserved ranges,
in v4, v6 and v4-mapped-v6 form.
- `check_resolved` — resolves a name and requires *every* answer to pass, so
a host that returns one public and one private address is refused.
- Internal names are refused by shape: single-label hosts (`mongo`,
`compliance-agent`), `localhost`, `.internal`, `.local`, `.home.arpa`.
Wired in at each place a tenant decides where we connect: git and live-URL
ingest, DAST target creation, DAST scan start (re-resolved at use, not only at
registration), the pentest wizard's app URL, and the ICS probe, which opens
raw TCP connections.
Blob artifacts (firmware, archives, PLC projects, mobile packages) now require
an uploaded `stored_path`. `source_ref` used to be read as a filesystem path
when no upload existed, so an API caller could name any file the agent can
read and ingest it as their own artifact.
On-premise runners legitimately scan private ranges — a Werkbank runner inside
a plant network is aimed at 10.x PLCs on purpose — so `PW_ALLOW_PRIVATE_TARGETS=1`
relaxes the policy. A hardened deployment ignores it: the cloud agent shares a
network with the platform's own services.
Stacked on #254 (`feat/fail-closed-config`) for `AppEnv`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #256. Stacked on #292 (
feat/fail-closed-config) — it needsAppEnvfrom there, so the base is that branch; review this diff alone, and it retargets tomainonce #292 merges.Why
Every target says where the scanner should connect: a git URL, a live URL, a DAST base URL, a pentest app URL, a PLC endpoint. Nothing checked what those resolve to, and the agent sits on the platform network. A tenant could aim a scan at
pruefwerk-mongo:27017, at169.254.169.254, or atfile:///data/compliance-scanner/ssh/id_ed25519, and read the result back as findings — server-side request forgery with a UI in front of it, plus a straight local-file read on the blob path.The guard
compliance_core::net_guard, dependency-free so the agent, the DAST crate and the runner can all use it:check_url/check_git_urlhttp(s)for fetches; git also allowssshbut neverfile://,git://or a bare path (including scp-stylegit@host:org/repo)check_ip169.254.169.254), documentation, benchmarking, reserved — in v4, v6 and v4-mapped-v6 formcheck_resolvedInternal names are refused by shape as well: single-label hosts (
mongo,compliance-agent),localhost,.internal,.local,.home.arpa.Where it is enforced
ingest/mod.rs)app_urlwerkbank-exec/src/ics), which opens raw TCP connectionsBlob artifacts (firmware, archives, PLC projects, mobile packages) now require an uploaded
stored_path.source_refwas previously read as a filesystem path when no upload existed, so an API caller could name any file the agent can read and ingest it as their own artifact. Uploads already setstored_path, so the wizard, the upload handler and the demo seeder are unaffected; only the JSON "point at a server path" path is gone.On-premise
A Werkbank runner inside a plant network is aimed at
10.xPLCs on purpose, soPW_ALLOW_PRIVATE_TARGETS=1relaxes the policy. A hardened deployment ignores it — the cloud agent shares a network with the platform's own services. Documented indocs/guide/scanning.md.Not covered yet (follow-ups, not regressions)
Verification
cargo fmt --all --checkclean;cargo clippy -p compliance-core -p compliance-agent -p compliance-mcp -p werkbank-exec -p control-map -- -D warningsclean.cargo test -p compliance-core -p compliance-agent -p werkbank-exec -p control-map --lib→ 327 + 69 + 28 + 9 pass.net_guard(platform hostnames, private/loopback/link-local/metadata/v4-mapped, ordinary public targets, parsing incl. IPv6 and userinfo, non-HTTP schemes and local paths, git scheme rules, the on-premise policy, resolution of literals); 3 in ingest (git remotes that would read our own disk, live URLs at internal hosts, a blob artifact naming a server path); 1 in the ICS probe (internal endpoints are never probed).🤖 Generated with Claude Code
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
1920ba9d9atoea70777c89