Add configurable trusted client-IP header support for Fastly - #1048
Add configurable trusted client-IP header support for Fastly#1048prk-Jr wants to merge 23 commits into
Conversation
Reject secrets shorter than the 32-character minimum already applied to ec.passphrase, and route the secret through reject_placeholder_secrets so the placeholder published in the example config and guides fails startup. The secret is the only gate on forging the client address that geolocation, EC identity derivation, and bot protection consume.
The shared proxy code forwards an inbound X-Forwarded-For to publisher origins, and no adapter has a trustworthy upstream forwarded-for chain, so a client could choose the address the origin attributes the request to. The Spin adapter already stripped it; moving the rule into the shared spoofable-header list closes the same gap on Fastly without changing Spin behavior. Integrations that need the address keep injecting their own value from the resolved client IP.
Fold resolution and forwarded-header sanitization into resolve_and_sanitize_client_ip so resolution cannot be reordered after the sanitization that removes the headers it reads. Log every fallback taken while a configuration is present at debug level, without the secret or the address, so a rotated secret or renamed header stops failing silently. Document the front door requirement to leave exactly one value per trust header, since duplicates select the peer address.
ChristianPavilonis
left a comment
There was a problem hiding this comment.
Summary
Requesting changes for one high-severity config rollout and rollback compatibility issue. The trusted client-IP runtime behavior and validation otherwise looked sound at the reviewed revision.
| #[serde(default)] | ||
| pub tester_cookie: TesterCookieConfig, | ||
| /// Optional authenticated trusted client IP forwarding configuration. | ||
| #[serde(default)] |
There was a problem hiding this comment.
🔧 P1: Disabled configuration breaks older binaries during rollout or rollback
When [trusted_client_ip] is absent, this field is None, but #[serde(default)] only affects deserialization. Derived serialization still writes "trusted_client_ip": null into every blob produced by ts config push. TrustedServerAppConfig::serialize delegates directly to Settings::serialize, while the base revision's Settings uses deny_unknown_fields and does not know this key.
Pushing an otherwise unchanged config before upgrading all instances, or rolling back after that push, makes old instances reject the blob and return startup-error HTTP 500 responses even though the feature was never enabled. The existing AuctionConfig compatibility logic explicitly omits default new fields for this reason.
Please omit None during serialization and add a regression test proving a default payload lacks this key and remains accepted by a schema matching the base revision. If the field is configured, document that operators must restore a compatible blob before rolling back.
| #[serde(default)] | |
| #[serde(default, skip_serializing_if = "Option::is_none")] |
Summary
Changes
.gitignorecrates/trusted-server-core/src/settings.rsreject_placeholder_secrets.crates/trusted-server-core/src/http_util.rsFastly-Client-IPas spoofable after authenticated consumption and provide a shared sanitizer for configured trust headers.crates/trusted-server-adapter-fastly/src/platform.rscrates/trusted-server-adapter-fastly/src/compat.rsresolve_and_sanitize_client_ipso their ordering cannot be reversed.crates/trusted-server-adapter-fastly/src/main.rsClientInfo.crates/trusted-server-adapter-fastly/src/middleware.rsClientInfofor response geolocation, including authoritative absence.crates/trusted-server-adapter-fastly/src/app.rsClientInfoaddress reaches request-scoped services and the EC finalization context.crates/trusted-server-adapter-axum/src/middleware.rscrates/trusted-server-adapter-cloudflare/src/middleware.rscrates/trusted-server-adapter-spin/src/middleware.rstrusted-server.example.tomldocs/guide/configuration.mddocs/guide/fastly.mdunsetrequirement and keeping the front-door copy of the secret out of inline VCL.docs/superpowers/specs/2026-08-19-trusted-client-ip-header-design.mddocs/superpowers/plans/2026-08-19-trusted-client-ip-header.mdSecret storage
Redacted<String>prevents the shared secret from appearing in debug output and validation errors, but it does not move the value into a platform secret store. With the current configuration architecture,ts config pushserializesshared_secretinto the Trusted Server application-config blob.Fastly recommends Secret Store, rather than Config Store, for sensitive values. Migrating this field requires changing the shared configuration schema to hold a secret-store reference and resolving that reference in the Fastly request path. The broader migration of existing Trusted Server passphrases and secrets is tracked by #846 and remains outside this PR.
The fronting copy is a separate concern: a Fastly VCL/CDN service cannot read a Compute Secret Store. That service must obtain the identical value through a VCL-accessible mechanism such as a tightly restricted private/write-only edge dictionary, and must overwrite both incoming trust headers before forwarding.
Fronting VCL deployment requirement
Code configuration alone does not enable trusted client-IP forwarding. The public/fronting VCL service—not the Trusted Server Compute service—must discard client-supplied trust headers and recreate them on the first visit:
This pasteable example is for a dedicated VCL service whose requests all go to Trusted Server. A shared service must apply the setup only on its Trusted Server route, strip client-supplied authentication on other routes, and never send the dictionary value to unrelated backends. If another CDN precedes Fastly, restrict direct access and use that CDN's protected reader-IP value instead of
client.ip. The dictionary value must exactly matchtrusted_client_ip.shared_secret.Scope note:
X-Forwarded-ForThis PR does not change cross-adapter handling of client-supplied
X-Forwarded-For. An earlier partial hardening change was removed after review because it covered Fastly and Spin but not Cloudflare and Axum. Consistent reconstruction ofX-Forwarded-Forfrom authoritativeClientInfoshould be handled separately.Closes
Closes #1041
Fixes #1040
Test plan
cargo test-fastlycargo test-axumcargo test-cloudflarecargo test-spincargo clippy-fastlycargo clippy-axumcargo clippy-cloudflarecargo clippy-cloudflare-wasmcargo clippy-spin-nativecargo clippy-spin-wasmcargo fmt --all -- --checkcd crates/trusted-server-js/lib && npx vitest runusing repository-pinned Node 24.12.0cd crates/trusted-server-js/lib && npm run formatcd docs && npm run formatcargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1Checklist
unwrap()in production codelogmacros, notprintln!