Skip to content

Stabilize middleware contracts on wasip3 0.9 and Spin 4.2.5 - #1

Open
codeitlikemiley wants to merge 4 commits into
mainfrom
gol/stabilize-middleware-contracts-894a
Open

codeitlikemiley wants to merge 4 commits into
mainfrom
gol/stabilize-middleware-contracts-894a

Conversation

@codeitlikemiley

@codeitlikemiley codeitlikemiley commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

CI

GitHub reported no checks on this pull request because workflow CI (id 311190778) is disabled_inactivity (updated 2026-09-10T08:59:42Z). A disabled workflow does not start on pull_request or push. on.pull_request was already present with no branch filter. on.push listed only main, so a push of this branch would not match even after the workflow is enabled. Commit f23c7d6 keeps every existing job and adds gol/stabilize-middleware-contracts-894a to push.

PUT /repos/codeitlikemiley/wasi-http-middleware/actions/workflows/311190778/enable returned 403 (actions=write required). After pushing f23c7d6, the workflow state was still disabled_inactivity, the commit had 0 check runs, and this pull request's statusCheckRollup was empty. That push was not queued. Enabling the workflow in the Actions tab, then pushing another commit or running the workflow on this ref, is what will create the jobs. There are no GitHub job conclusions for f23c7d6.

The last main schedule run, https://github.com/codeitlikemiley/wasi-http-middleware/actions/runs/34458171742 (2026-09-10, head 61b4199), failed only in Semver and package structure: https://github.com/codeitlikemiley/wasi-http-middleware/actions/runs/34458171742/job/102809391692. That job installed Rust 1.93.0 and cargo-semver-checks 0.48.0. The script exited 1 and printed none of the tool log, because a failing grep -Fq under set -e discarded the captured output. Replaying that commit today with Rust 1.93.0 and cargo-semver-checks 0.48.0 exits 0, so that retained log does not identify a still-reproducing tool error.

This branch's semver job uses Rust 1.99.0. cargo-semver-checks 0.48.0 rejects that compiler's rustdoc JSON (unsupported rustdoc format v61). 0.51.0 reads v61, and the existing expected summaries still match. The script now prints the tool log when a summary does not match. scripts/require-rust-1.99.sh fails a 1.99.0 job if Cargo would use current stable (1.99.1) instead. cargo +1.99.0 fmt --all -- --check and cargo +1.99.1 fmt --all -- --check are both clean, so no source was reformatted.

cargo audit --deny warnings exits 0 on Cargo.lock (65 crates) and fuzz/Cargo.lock (29 crates) against 1352 advisories. Neither lockfile contains rustls, rustls-webpki, webpki-roots, quinn-proto, ctutils, tokio, or crypto-bigint. RUSTSEC-2026-0387 did not appear and is not ignored. cargo deny check exits 0; the duplicate syn 2.0.118 / 3.0.9 warning stays a warning (multiple-versions = "warn"). wasip3 stays =0.9.0 and wit-bindgen stays =0.62.0. The root Cargo.lock is unchanged.

f23c7d69e645b3363ba17935c12d179cfb025683 changes CI, the semver-report tool line, the semver script's failure output, and the fuzz lockfile's path-package versions (wasi-http-metadata and wasi-http-policy-core from 0.2.0-alpha.1 to 0.2.0-alpha.3). It does not change middleware Rust, the public API, or behavior. Downstream repos that pin behavior can stay on 3df96c21a7906b885e67229e9a7c8c01b6497109. Repos that track this branch tip should move to f23c7d6.

Problem / repro

Portable and native middleware duplicated request-ID, CORS, Vary, security-header, and broker-decision logic. Cross-origin requests whose method was outside the allowlist still reflected Access-Control-Allow-Origin, including simple browser GETs. accept_trusted_ingress accepted a superset of the configured audiences. The unsigned AuthContextV1 envelope was easy to confuse with wasi-auth's HMAC trusted context.

wasi-auth also vendors this tree at legacy/wasi-http-middleware. Two copies will diverge.

The guest pins were behind the coordinated target: wasip3 0.7.0 and wit-bindgen 0.59.0. wasip3 0.8+ renamed spawn to spawn_local. The July Spin fork does not serve final wasi:http/[email protected] plus native dependencies.middleware.

HTTP/1.1 responses that carry WASI trailers were first treated as a host bug. They are not. Hyper 1.11 (src/proto/h1/conn.rs write_trailers) sends HTTP/1.1 trailers only when the request has TE: trailers (RFC 9110 §6.5.1) and only for names listed in the response Trailer header. The echo fixture declared no Trailer name, and the contract client did not send TE.

apply_security_headers and the portable CORS merge inserted unconditionally. If this middleware runs after wasi-auth on the same response, it replaced Referrer-Policy: same-origin and X-Content-Type-Options while leaving CSP and HSTS. That is an inconsistent policy. wasi-auth codeitlikemiley/wasi-auth#15 stops its own writer from clobbering a foreign policy. This repository still overwrote.

Root cause

Policy decisions lived in both wasi-http-policy-core and the component crates, so the portable path could accept a request the native path would reject. CORS applied the method allowlist only to preflight. Audience checks compared the service id and then treated any overlapping audience as sufficient. HMAC dotted envelopes are not valid base64url AuthContextV1, but that rejection was not tested as a boundary.

The legacy tree was a byte copy of this repo, pinned in wasi-auth metadata at an older SHA (006352a) than the bytes actually checked in.

The trailer fixture omitted Trailer: x-echo-trailer. Without that declaration, and without TE: trailers on the request, Hyper correctly ends the HTTP/1.1 body at the zero chunk.

HeaderMap::insert and portable set_header replace the named field. CORS merge deleted every non-Vary decision name and wrote this middleware's values, including onto an existing Access-Control-* policy.

Upstream status

  • Public WIT stays wasi:[email protected]. wasip3 0.9.0 still embeds that package. The binding crate and wit-bindgen pin are what changed.
  • wasip3 0.9.0 pins wit-bindgen 0.62.0 exactly. Do not move the generator to 0.63.0.
  • Guest SDK pin for consumers that import it: codeitlikemiley/spin-rust-sdk revision 3cf30012b50a1afb750dac3d28aa6da4a32c3468 (Align spin-sdk with wasip3 0.9 and Wasmtime 50 spin-rust-sdk#1, branch gol/wasi-dep-stabilization-1365). This workspace does not depend on the spin-sdk crate.
  • Host: official spinframework/spin v4.2.5 linux-amd64 (e09d7d5, 2026-10-23). The codeitlikemiley/spin fork is not a host.
  • HTTP/1.1 trailers are host-correct on Spin 4.2.5 and Wasmtime 50.0.0 once the client sends TE: trailers and the response declares the name. Spin 4.2.5 also writes x-echo-trailer on HTTP/2 prior knowledge.
  • wasmtime serve 50.0.0 (ebe5e8df1, 2026-10-20) does not accept HTTP/2 prior knowledge. Both -W component-model-async=y -S p3=y -S cli=y -S http=y and -S cli,http,p3 -W component-model-async,component-model-error-context log hyper::Error(Parse(VersionH2)). Curl exits 56. Wasmtime HTTP/2 trailers are unverified because serve rejects the preface. Those flags were not changed for the header guard, and the HTTP/2 probe was not repeated on 3df96c2.

Implementation

  • Workspace pins: wasip3 = "=0.9.0" (http-compat), wit-bindgen = "=0.62.0" (async-spawn). package.rust-version is 1.94. rust-toolchain.toml and CI pin 1.99.0, not stable.
  • wasip3::spawn is wasip3::spawn_local in the echo service and mock broker.
  • wasi-http-policy-core owns request-ID canonicalization, the security-header table, Vary merging, CORS evaluation (including simple cross-origin methods), and accepted_claims. Native wasi-http-authn and the portable components call those functions.
  • Security headers are written only when that name is absent. An existing value is kept, including Referrer-Policy: same-origin and a non-baseline X-Content-Type-Options. CSP and HSTS are still never written.
  • Access-Control-* fields are copied only when the downstream response has none, so a foreign CORS policy is not replaced and sibling fields such as Access-Control-Allow-Credentials are not mixed in. Vary is still merged and * is not narrowed. absent_security_header_fields and cors_field_edits are the shared decision; apply_security_headers / apply_cors_headers and the portable *_to_fields forms both use them. security-headers, cors, and secure-defaults call those functions. Request IDs are still replaced.
  • accept_trusted_ingress requires exact audience-list equality. Dotted HMAC envelopes are rejected and stripped.
  • The echo /trailers response sets Trailer: x-echo-trailer. The shared contract reads the raw HTTP/1.1 message: with TE: trailers it requires x-echo-trailer: preserved; without TE it requires that field to be absent and the body to remain.
  • docs/CANONICAL.md is the ownership decision and the removal plan for Agent 4. Crate version stays 0.2.0-alpha.3. The next operator tag is v0.2.0-alpha.4; this commit is not a release.
  • wasm32-wasip2 links the WASI 0.2.12 reactor adapter. The exact-import gate records that adapter separately from policy imports. Filesystem, sockets, and Spin storage imports stay forbidden.

Tests / evidence

Commands were run on 2026-10-24. Header non-overwrite and the E2E re-run are commit 3df96c2.

Command Result
rustc +1.99.0 --version 1.99.0 (b940084d7 2026-09-28)
cargo +1.99.0 --version 1.99.0 (5f94df478 2026-08-27)
cargo +1.99.0 test --workspace --locked --all-features 65 tests passed, doctests passed
native_and_portable_response_policy_preserves_downstream_headers same native HeaderMap and portable field-list result: keeps same-origin, nosniff, CSP, HSTS, and a foreign Access-Control-Allow-Origin; does not add credentials; merges Vary to Accept-Encoding, Origin; fills absent baseline fields
cargo +1.99.0 clippy --workspace --locked --all-targets --all-features -- -D warnings clean
cargo +1.99.0 fmt --all -- --check clean
cargo +1.94.0 check --workspace --locked --all-targets --all-features compiled (rustc 1.94.0 (4a4ef493e 2026-03-02))
cargo +1.94.0 check --workspace --locked --target wasm32-wasip2 --all-features compiled
Wasmtime 50.0.0 STREAM_FAILURE_REPEATS=50 bash scripts/run-wasmtime-e2e.sh passed, including TE: trailers present and no-TE omitted. Log assertion is 116 + 50 + 25 terminal invocations (IMMEDIATE_FAILURE_REPEATS left at the script default 25)
Wasmtime 50.0.0 STREAM_FAILURE_REPEATS=50 bash scripts/run-wasmtime-secure-defaults-e2e.sh passed, same trailer contract, on port 19290
Spin 4.2.5 SPIN_COMPAT_PROFILE=release-composed and release-native, STREAM_FAILURE_REPEATS=50, SPIN_BIN=/tmp/wasi-tools/spin-v4.2.5/spin both passed the shared contract and HTTP/2 x-echo-trailer: preserved
Wasmtime HTTP/2 prior knowledge not re-run on 3df96c2. On 4cc129f: hyper::Error(Parse(VersionH2)), curl exit 56, on both flag sets

Components were rebuilt for wasm32-wasip2 before the E2E (scripts/build-components.sh), so the composed and native hosts ran this commit's policy.

Resolved lock: one [email protected]+wasi-0.3.0, one [email protected], [email protected]. No wasip3 0.4 or 0.6. No second guest wit-bindgen.

spin --version observed: spin 4.2.5 (e09d7d5 2026-10-23).
wasmtime --version observed: wasmtime 50.0.0 (ebe5e8df1 2026-10-20).

Compatibility and security

  • Fail-closed CORS: a cross-origin method outside the allowlist returns 403 and Vary: Origin and does not reflect Access-Control-Allow-Origin.
  • Credentials still reflect the exact origin and never * when this middleware is the CORS policy. Header * is literal.
  • A downstream Access-Control-* policy is left as written. This middleware does not add Access-Control-Allow-Credentials onto a foreign Access-Control-Allow-Origin.
  • A downstream Referrer-Policy or X-Content-Type-Options is left as written. Absent baseline fields are still filled. CSP and HSTS stay with the application or wasi-auth.
  • Exact audience equality blocks a context minted for a wider audience list.
  • HMAC envelopes are not AuthContextV1. This crate does not verify wasi-auth MACs.
  • Preview 2 adapter imports are the wasm32-wasip2 reactor, not new middleware capabilities.
  • HTTP/1.1 trailers follow RFC 9110. Clients that want them send TE: trailers. Clients that do not must not see the trailer fields. HTTP/2 on Spin 4.2.5 writes the field without TE.
  • No crate publish, tag, or force-push.

Dependent PRs

Intended targets

Item Target
Rust quality gate 1.99.0
package.rust-version 1.94
wasip3 =0.9.0 (0.9.0+wasi-0.3.0)
wit-bindgen =0.62.0
WIT wasi:[email protected]
Wasmtime 50.0.0
Spin host official v4.2.5 linux-amd64
spin-sdk (consumers only) 3cf30012b50a1afb750dac3d28aa6da4a32c3468
Crate version unchanged 0.2.0-alpha.3
Open in Web Open in Cursor 

cursoragent and others added 2 commits October 24, 2026 12:55
Pin wasip3 0.9.0 and wit-bindgen 0.62.0, and spawn guest tasks with
spawn_local. Raise the library MSRV to 1.94 and the quality-gate
compiler to 1.99.0. Share request-ID, CORS, security-header, and
broker-decision behavior between the native and portable paths, and
record this repository as the canonical middleware source.

Wasmtime 50.0.0 and official Spin 4.2.5 pass the HTTP contract for the
composed handler and native middleware. Spin still omits HTTP/1.1
response trailers; HTTP/2 writes them.

Co-authored-by: Uriah Galang <[email protected]>
Hyper 1.11 writes chunked trailers when the request includes
TE: trailers and the response declares those names. The echo service
now sends Trailer: x-echo-trailer. The shared contract expects the
field with that request header and expects it to be omitted without
one. Spin 4.2.5 still writes the same field on HTTP/2. Wasmtime 50
serve rejects the HTTP/2 preface with hyper::Error(Parse(VersionH2)).

Co-authored-by: Uriah Galang <[email protected]>
Baseline nosniff and Referrer-Policy are written only when that field is
absent, and Access-Control-* fields are left untouched when a downstream
policy is already present. Vary is still merged. Native HeaderMap and
portable field lists share that decision.

Co-authored-by: Uriah Galang <[email protected]>
The Actions workflow is disabled for inactivity, and push only matched
main, so pull requests on this branch produced no checks. Keep every
existing job, add this branch to push, and pin cargo-semver-checks
0.51.0 so the semver job can read Rust 1.99 rustdoc format v61.
Require the 1.99.0 compiler explicitly, and stamp the fuzz lockfile
path crates to 0.2.0-alpha.3.

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