Skip to content

Fail closed on forged and unsigned trusted context - #15

Open
codeitlikemiley wants to merge 7 commits into
mainfrom
gol/signed-context-boundary-5bda
Open

codeitlikemiley wants to merge 7 commits into
mainfrom
gol/signed-context-boundary-5bda

Conversation

@codeitlikemiley

@codeitlikemiley codeitlikemiley commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Problem / repro

Native ingress seals an HMAC-SHA-256 envelope into x-wasi-auth-context, and the guest did not consume it. signed_context_accepts_once_and_fails_closed_on_expiry_rebind_and_replay rejected a different request ID (BindingMismatch) and a presentation after max-age (Expired). It then asserted that TrustedContextCodec::open still returns Ok for the same binding through the freshness window. A direct Spin 4.2.5 guest therefore accepted an immediate replay of a valid envelope. The PRD requires that replay to fail closed.

Ingress strips every client x-wasi-auth-* header, including a correctly signed one, so the public listener does not honor a captured envelope. The replay that succeeded was a second request to the guest itself. Loopback is the deployment rule. This change does not assume the guest is unreachable.

Root cause

The MAC binds audience, method, path, and request ID. That stops use on a different request. It does not stop a second presentation of the same bytes inside the freshness window (default 5s, maximum 30s). There was no per-process seen-set. open is a pure check and stays that way.

A shared nonce store is not available to a stateless multi-instance WASI guest. The defense that fails closed for the observed attack is a process-local set of accepted HMAC signatures, kept until that envelope can no longer pass open.

Implementation

accept_signed_trusted_context records the signature after open succeeds. A second presentation in the same process returns TrustedContextError::Replayed (trusted-context envelope was already accepted) and installs nothing. Headers are still stripped.

Residual risk, stated on purpose: another process that shares the HMAC key has its own set and can accept the envelope until the freshness window ends. Ingress still strips client envelopes. Query and body stay outside the MAC.

SessionId Debug prints SessionId([REDACTED]). Display and as_str still return the identifier. This branch's lock remains wasip3 0.7.0+wasi-0.3.0.

CI

Merges PR 18 (83596f2987217fe6dd7ef7fbc42ac8f18b00bbb2) so rustls 0.23.46, rustls-webpki 0.103.16, webpki-roots 1.0.11, quinn-proto 0.11.19, ctutils 0.4.5, and tokio 1.54.1 are in this lock. No audit ignore was added.

scripts/generate-sbom.sh was run after that merge. The ingress SBOM keeps [email protected], [email protected], and [email protected] on the component dependsOn list. That was the Final-WASI failure unique to this PR.

crypto-bigint 0.5.5 remains. RUSTSEC-2026-0387 is patched only in >=0.7.6, and jsonwebtoken 10/11 plus passkey-auth 0.1.3 still require elliptic-curve 0.13 (crypto-bigint ^0.5). cargo update -p crypto-bigint does not move it. Dependency policy and unpublished-package audit stay red on that one advisory.

Tests / evidence

Toolchain: Rust 1.93.0. Head includes 0918bce (replay rejection) and 636a1a4 (the two consuming tests take one lock so a later synthetic clock cannot prune another test's entry). Tip is 8a01142948f4174d6a6ef192ddb361bb132c9191.

cargo test -p wasi-auth --features http --lib --offline -- http::tests --test-threads=16 — 16 passed. That includes the immediate second request asserting Replayed, and a different seal still being accepted afterward. open at the end of the window still returns Ok; it does not consume.

cargo +1.93.0 check --locked of wasi-auth (postgres-native, outbox-worker), wasi-auth-ingress, and wasi-auth-migrate passed on the advisory lock.

Spin 4.2.5 (e09d7d5 2026-10-23), archive sha256 8b26a8afd98874a0ce6c5c66ab9924ac2aba77de8abfd3f206dd37f313b58a56 matching checksums-v4.2.5.txt. Guest boundary_probe.wasm (453557 bytes), wasm-tools 1.253.0 validate OK, export wasi:http/[email protected].

Probe Result
Direct guest, no envelope 200, anonymous. Response still carried authorization, x-wasi-auth-subject, and cookie.
Direct guest, forged x-wasi-auth-subject 200, anonymous.
Direct guest, valid envelope 200, accepted user=user-one.
Direct guest, immediate replay of that envelope 200, rejected trusted-context envelope was already accepted.
Direct guest, sealed 120s earlier 200, expired.
Direct guest, signature byte flipped 200, invalid.
Direct guest, bearer and no envelope 200, credentials without a signed trusted context.
Direct guest, portable eyJ2ZXJzaW9uIjoxfQ 200, invalid.
Direct guest POST /read 200, bytes=10. No trap lines.
Ingress GET /guest, and the same with forged, expired, or valid client envelopes 200, guest saw only x-request-id, anonymous. Response had no identity or credential headers.
Ingress bearer client-secret, and __Host-session=session-secret 401.
Ingress declared Content-Length: 400000, and chunked 300 KiB 413.
Ingress guest wait 8s, unary timeout 1s 504 at 1.00s.
Ingress POST /read 200, bytes=10.
Seeded session, development HS256 bearer, same organization 200 {"allowed":true,"reason":"cedar.allow","policy_revision":"embedded-v1",...}.
Same session, organization_id organization-two 403 Authorization request was rejected.

The seeded rows are user 11111111-1111-4111-8111-111111111111, organization 22222222-2222-4222-8222-222222222222, session 33333333-3333-4333-8333-333333333333, role owner, permission document.read, plus an active auth_signing_keys row for the development kid. Native Cedar runs when Authorization is present. A cookie alone is forwarded to the guest, which returned 404 for /api/authorization/check.

Dependent PRs

Merge PR 18 first, then this PR, then PR 16. The overlap in spin_grpc.rs keeps these security notes and uses spawn_local.

PR 17 is the merge downstream can pin now: 4eff8edf8d3010b81d8fa30da576f9f11970e2f6. It has this boundary, wasip3 0.9.0+wasi-0.3.0, and the advisory bumps. No tag was published.

Open in Web Open in Cursor 

The guest had no HMAC acceptor, so a portable middleware context or a
client-supplied x-wasi-auth-* header could be confused with the signed
ingress envelope. Accept only the HMAC envelope, strip credentials and
reserved identity headers before the guest, and refuse a second CORS or
security-header policy on the same response.

Co-authored-by: Uriah Galang <[email protected]>
cursoragent and others added 3 commits October 24, 2026 13:36
Debug of SessionId printed the raw identifier, so any Debug of a
containing session leaked it into logs. Display and as_str still
return the identifier for storage and the signed envelope.

The host-probe test seals a now-relative envelope only when
SPIN_ENVELOPE_OUT is set.

Co-authored-by: Uriah Galang <[email protected]>
accept_signed_trusted_context now consumes each HMAC signature once in
the guest process. The codec still only checks freshness, audience,
method, path, and request ID. A second instance that shares the key can
accept the same envelope until that window ends.

Co-authored-by: Uriah Galang <[email protected]>
Parallel tests share the process-local seen-set. A later fixture clock
pruned an entry another test still needed, so the second presentation
looked accepted. The tests now take one lock for the consume sequence.

Co-authored-by: Uriah Galang <[email protected]>
cursoragent and others added 3 commits October 24, 2026 21:24
Move the exact rustls pin to 0.23.46 and cargo-update rustls-webpki
0.103.16, webpki-roots 1.0.11, quinn-proto 0.11.19, ctutils 0.4.5, and
tokio 1.54.1. Refresh the SBOMs those crates appear in.

crypto-bigint stays at 0.5.5. The advisory is fixed only in 0.7.6, and
jsonwebtoken 10/11 plus passkey-auth 0.1.3 still require the
elliptic-curve 0.13 stack.

Co-authored-by: Uriah Galang <[email protected]>
Regenerate the ingress CycloneDX document so bytes, http-body, and
http-body-util stay on the component dependsOn list.

Co-authored-by: Uriah Galang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants