Files
Tejas ChopraandClaude Fable 5.1 9d98ea5908 fix(rust-proxy): forward request paths verbatim and pin the rustls provider (#3853)
## Summary

VAPT-readiness findings **03-F2** (Bedrock/Vertex path traversal to a
signed request, previously *unverified* — now **confirmed** by the tests
below), **03-F3** (`join_upstream_path` base-prefix escape), **03-F1**
(rustls provider panic on `wss://`) and part of **03-F9** (lint
posture). Rust `headroom-proxy` only; the Python wheel is untouched.

**Problem.** `url::Url::set_path` resolves `.`/`..` (also `%2e`) and
folds `\\` into `/`. So a client could walk out of a tenant base prefix
on the generic forwarder, move a **SigV4-signed** Bedrock request to
another resource (`/model/../invoke`), or move an **ADC-signed** Vertex
request to another project. Bedrock also re-interpolated the URL-decoded
`model_id`, so an inference-profile ARN (contains `/`) became two
segments and a hostile id gained segments.

**Fix, one generic module rather than per-provider patches.** New
`crates/headroom-proxy/src/upstream_path.rs`, used by every upstream URL
builder (forwarder, Bedrock invoke + streaming, Vertex, WebSocket
upgrade):
- `join_request_path` rejects any raw path the URL parser would rewrite
and asserts the result still sits under the configured base prefix (400
before anything is signed or sent).
- `append_segments` rebuilds provider paths segment by segment from
decoded route parameters, percent-encoding `/` so an ARN stays one `%2F`
segment, and rejecting `.`, `..`, empty and control-character segments.
Side effect: a `bedrock_endpoint` with a path prefix now keeps that
prefix.

Also:
- ring is installed as the **process-wide** rustls `CryptoProvider` in
`AppState::new`. The binary links both ring and aws-lc-rs, and rustls
panics in `ClientConfig::builder()` without a default. Main already
names ring explicitly for the `wss://` relay (#3831), so that path no
longer panics there; this makes every present and future TLS client in
the process safe and adds the first end-to-end `wss://` relay test
(rcgen certificate generated at test time, trusted via
`HEADROOM_CA_BUNDLE`).
- `#![forbid(unsafe_code)]` on the four crates that have no `unsafe`
today; `overflow-checks = true` in the release profile for the proxy
package only.

## Reproduction / regression tests

`tests/integration_path_traversal.rs` (6) and
`tests/integration_ws_tls.rs` (2), mock upstream records the path it
receives.

Against **origin/main** (test files copied over, test-only crates
added):
```
thread 'forwarder_keeps_requests_under_the_base_prefix' (653400) panicked at crates/headroom-proxy/tests/integration_path_traversal.rs:103:9:
assertion `left == right` failed: /../tenant-b/v1/models must be rejected
  left: 200
 right: 400
thread 'websocket_upgrade_with_traversal_path_is_rejected_before_upgrade' (653402) panicked at crates/headroom-proxy/tests/integration_path_traversal.rs:130:5:
assertion `left == right` failed: a traversal path must not be upgraded (101)
  left: 404
 right: 400
thread 'vertex_dot_segment_project_is_rejected_unsigned' (653401) panicked at crates/headroom-proxy/tests/integration_path_traversal.rs:269:5:
assertion `left == right` failed
  left: 200
 right: 400
thread 'bedrock_streaming_dot_segment_model_id_is_rejected_unsigned' (653399) panicked at crates/headroom-proxy/tests/integration_path_traversal.rs:246:9:
assertion `left == right` failed: /model/../invoke-with-response-stream must be rejected
  left: 200
 right: 400
thread 'bedrock_dot_segment_model_id_is_rejected_unsigned' (653397) panicked at crates/headroom-proxy/tests/integration_path_traversal.rs:172:9:
assertion `left == right` failed: /model/../invoke must be rejected
  left: 200
 right: 400
thread 'bedrock_encoded_slashes_in_model_id_stay_one_segment' (653398) panicked at crates/headroom-proxy/tests/integration_path_traversal.rs:203:5:
traversal reached the upstream: ["/guardrail/GID/version/1/apply/invoke"]
test result: FAILED. 0 passed; 6 failed
```
The last line is the important one: on main a crafted `model_id` made
the proxy sign and send a request to
`/guardrail/GID/version/1/apply/invoke`.

`integration_ws_tls.rs` **passes on main as well**: the explicit-ring
fix in #3831 already covers the relay, and test builds unify crypto
features differently from the release binary, so these two tests guard
the behaviour but do not reproduce the original panic. Stated plainly so
nobody counts them as fail-before.

On this branch: `cargo test -p headroom-proxy` **498 passed, 0 failed**;
`cargo clippy -p headroom-proxy --all-targets -- -D warnings` clean;
`cargo fmt --all -- --check` clean.

## Real behavior proof

The integration tests run the real proxy router in-process against a
real local HTTP upstream and a real TLS WebSocket upstream; the
traversal assertions are on the path the upstream actually received.
**Not tested:** a live Bedrock or Vertex endpoint (no credentials used),
the release binary's startup against a live `wss://` provider, and the
`overflow-checks` performance cost (no benchmark run; expected to be
small on the proxy, which is I/O bound). The Rust proxy ships only in
the OSS core image, not in the enterprise wheelhouse.

## Behaviour change / release note

Requests whose path contains dot-segments, encoded dot-segments or
backslashes, or that would leave the configured base prefix, now get
**400** instead of being normalised and forwarded. Bedrock model ids
containing `/` (inference-profile ARNs) are now sent as one encoded
segment, which is what the Bedrock API expects.

## Decision assumed

None. Not done here from the original item: workspace-level clippy
`unwrap_used`/`expect_used` warnings (left for a separate, noisier PR).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-29 14:10:33 -05:00
..

Headroom Simulators

headroom-simulators is a local, deterministic upstream for Headroom proxy tests. It serves provider-shaped responses without contacting real LLM APIs.

cargo run -p headroom-simulators -- --listen 127.0.0.1:8789

Optional JSON config:

{
  "stubs": [
    {
      "name": "exact chat smoke",
      "method": "POST",
      "path": "/v1/chat/completions",
      "body_contains": "ping",
      "response": {
        "status": 200,
        "headers": {"x-simulator": "configured"},
        "json": {"ok": true}
      }
    }
  ]
}

Point the proxy at http://127.0.0.1:8789 to run local or CI validations.