Skip to content

Send the resolved client IP to the publisher origin - #1607

Open
jevansnyc wants to merge 13 commits into
feat/1598-ec-route-fastlyfrom
feat/publisher-origin-client-ip
Open

jevansnyc wants to merge 13 commits into
feat/1598-ec-route-fastlyfrom
feat/publisher-origin-client-ip

Conversation

@jevansnyc

Copy link
Copy Markdown
Collaborator

Summary

  • Add an opt-in publisher.origin_client_ip_header setting. When set, every publisher-origin request carries the client IP Trusted Server resolved in that header (for example fastly-client-ip), replacing any client-supplied copy.
  • Add configurable trusted client-IP header support for Fastly #1048 added fastly-client-ip to SPOOFABLE_FORWARDED_HEADERS, so Trusted Server strips it at request entry and the origin request no longer carries it. Origins whose WAF rules, logging, rate limits, or geolocation read that header have received no client address on Trusted Server traffic since. Add configurable trusted client-IP header support for Fastly #1048 called this out and left reconstruction for later; this is that follow-up.
  • With [trusted_client_ip] configured and authenticated, the forwarded value is the reader. Without it, it is the immediate peer, so behind a front door it is the fronting POP. The docs say to enable the setting only after the [trusted_client_ip] handoff is verified, because one POP address standing in for every reader can trip origin rate limits.

Behavior

origin_client_ip_header Resolved client IP Header on the origin request
unset (default) any unchanged from today (inbound copy stripped)
set present exactly one value, the resolved IP
set absent header removed, so no client-chosen value leaks

Validation accepts fastly-client-ip, true-client-ip, x-forwarded-for, or another x- header. It rejects x-ts-*, Trusted Server internal headers such as x-geo-country, and anything else (host, cookie, forwarded). The field is skipped from serialization while unset, following the existing allow_async_html_finish pattern, so a default config blob stays readable by an older binary.

The header goes only on the publisher-origin request built in handle_publisher_request. Bidder, integration, and first-party proxy requests are unchanged. It is not part of the template cache key, the same as the connection address today.

Changes

File Change
crates/trusted-server-core/src/settings.rs New Publisher::origin_client_ip_header field, validate_origin_client_ip_header, field added to existing struct literals, tests for default, serialization, and validation
crates/trusted-server-core/src/publisher.rs set_origin_client_ip_header, called right after rewrite_origin_request; unit tests plus one test through handle_publisher_request that inspects the recorded origin request
crates/trusted-server-core/src/proxy.rs Test that asset proxy requests do not carry the configured header
docs/guide/configuration.md Field table row, origin_client_ip_header reference section, and the [trusted_client_ip] origin note now points to the setting
docs/guide/fastly.md "Effect on origin requests" now explains how to restore the header, plus the VCL-overwrite caveat when origin_url passes back through a VCL service
trusted-server.example.toml Commented example
CHANGELOG.md Unreleased entry

Closes

Follow-up to #1048 (related: #1040). No dedicated issue.

Spec

Not a feature: restores origin client-IP forwarding that #1048 removed, as an opt-in setting with no default behavior change.

Test plan

  • cargo test-fastly && cargo test-fastly-reuse && cargo test-axum && cargo test-cloudflare && cargo test-spin
  • cargo clippy-fastly && cargo clippy-axum && cargo clippy-cloudflare && cargo clippy-cloudflare-wasm && cargo clippy-spin-native && cargo clippy-spin-wasm && cargo clippy-cli && cargo clippy-codegen
  • cargo fmt --all -- --check
  • Parity: cargo test --manifest-path crates/trusted-server-integration-tests/Cargo.toml --test parity
  • CLI: cargo test --package trusted-server-cli --target <host-triple>
  • Docs format: cd docs && npm run format, plus root Markdown prettier check
  • Domain lint: ts dev lint domains --changed-vs origin/main
  • Removing the set_origin_client_ip_header call makes the handle_publisher_request test fail
  • Staging: with origin_client_ip_header = "fastly-client-ip", confirm the origin logs one Fastly-Client-IP holding the reader address, with and without [trusted_client_ip]

Checklist

  • Changes follow AGENTS.md conventions
  • No unwrap() in production code; uses expect("should ...")
  • Uses log macros (not println!)
  • New code has tests
  • No secrets or credentials committed

Trusted Server strips inbound Fastly-Client-IP as spoofable since #1048,
so origins whose WAF rules, logging, or geolocation read that header
receive no client address on Trusted Server traffic.

Add an opt-in publisher.origin_client_ip_header setting. When set, the
publisher-origin request carries the client IP Trusted Server resolved in
that header, replacing any client-supplied copy, and omits it when no IP
was resolved. Integration and proxy requests are unchanged.
@jevansnyc jevansnyc linked an issue Nov 14, 2026 that may be closed by this pull request
6 tasks
@jevansnyc
jevansnyc marked this pull request as ready for review November 14, 2026 15:16
@jevansnyc
jevansnyc requested review from aram356 and prk-Jr November 14, 2026 15:16

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The client-IP forwarding path works in the native tests, but setting the header after template-cache key capture introduces a cross-reader cache isolation bug. Please address the inline finding before merging.

Blocking

  • 🔧 [P1] Capture the resolved origin client-IP header before the template-cache Vary values — see inline at crates/trusted-server-core/src/publisher.rs:5316–5320.
  • 🔧 Changed-lines domain lint fails. The new helper at crates/trusted-server-core/src/settings.rs:6640 and :6642 repeats a non-allowlisted fixture host. The ts dev lint domains (changed lines) job reports both violations and exits 1 on the reviewed head/base merge result. Use a fictional example-domain origin consistently in the shared fixture and this replacement helper, then rerun domain lint and the configuration tests. This is an AGENTS.md CI gate even though branch protection does not enforce it. Failed job.
  • 🔧 The required feature spec is missing. CONTRIBUTING.md explicitly includes new configuration keys and request-handling behavior in its feature definition. The opt-in publisher.origin_client_ip_header adds both, despite the description classifying it as restoration. Please link the required spec with its two review rounds, or obtain an explicit maintainer exception. The implementation review here does not waive that merge requirement.

Verification

Reviewed head b72119a727f73a2a422d2c0d1b09ea0cd80021b0 against base 1810c763add220dd34fd5faaffe2c69aab1d556f.

  • Native core library suite: 3,396 passed, 2 ignored, using Rust 1.98.1 and Node 24.20.0.
  • The existing forwarding integration test passes; removing the new forwarding call makes it fail on the expected resolved-IP assertion.
  • A separate two-reader probe through the actual publisher handler and streaming finalizer, using an in-memory template cache, fails on this head by serving reader A's HTML to reader B. Moving header replacement before cache-key extraction makes the same probe pass.
  • The current check set reports the domain-lint failure above. Live Fastly/staging behavior was not exercised locally.

No fixes were applied to the PR branch.

Comment on lines +5316 to +5320
set_origin_client_ip_header(
&mut req,
settings.publisher.origin_client_ip_header.as_deref(),
services.client_info().client_ip,
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 [P1] Set the origin client-IP header before capturing template-cache Vary values

With origin_client_ip_header = "fastly-client-ip", assembly_mode = "esi", and template_cache_vary = ["fastly-client-ip"], the key has already read req.headers() at line 5308 before this replacement occurs. Fastly strips the inbound header, so two readers with different resolved IPs both contribute an absent value to the key, even though the origin receives different addresses.

If the origin returns IP-dependent HTML with Cache-Control: public, max-age=300 and Vary: Fastly-Client-IP, the Vary coverage check accepts it because the name is configured. Reader B can then receive reader A's cached HTML. I reproduced that result through the actual publisher handler and streaming finalizer with an in-memory template cache; the second reader received the first reader's document.

Please move this replacement before the template-cache Vary values are captured, while keeping it after the auction request snapshot, and add a two-reader regression test. Moving the call to that point in a scratch copy makes the same reproduction pass. This preserves caching within configured IP variants without adding IPs to every cache key. The correction is prose-only because it moves code outside this diff hunk and needs an additional regression test.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: Confirmed at b72119a72, including a case where the key is client-chosen. The fix location below is verified, and the regression test fails at this head and passes after the move.

Probe (throwaway tests named probe1607_*, not in this PR): two readers through handle_publisher_request and the streaming finalizer, using the in-memory template cache from template_cache_end_to_end_tests. Settings: assembly_mode = "esi" and template_cache_vary = [<name>]. Origin response: Vary: <name> and Cache-Control: public, max-age=300. Readers resolve to 192.0.2.7 and 198.51.100.9. Output of cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- probe1607 --nocapture --test-threads=1 at this head:

test publisher::tests::template_cache_end_to_end_tests::probe1607_fastly_client_ip_absent ... PROBE1607 fastly-client-ip: cold=miss-stored warm=hit origin_fetches=1 sent=["192.0.2.7"] reader_b_got_a=true
test publisher::tests::template_cache_end_to_end_tests::probe1607_x_real_ip_absent ... PROBE1607 x-real-ip: cold=miss-stored warm=hit origin_fetches=1 sent=["192.0.2.7"] reader_b_got_a=true
test publisher::tests::template_cache_end_to_end_tests::probe1607_x_real_ip_client_supplied ... PROBE1607 x-real-ip: cold=miss-stored warm=hit origin_fetches=1 sent=["192.0.2.7"] reader_b_got_a=true
test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 3398 filtered out; finished in 0.02s

The third case has both readers send X-Real-IP: 203.0.113.50; it hits like the others. A fourth probe gives one resolved IP (192.0.2.7) and two different client values, and at this head it misses twice, so for a name the adapter does not strip at entry the key follows the client value rather than the resolved IP. Same command filtered to probe1607_x_real_ip_different_client_values:

PROBE1607_SPLIT same resolved ip 192.0.2.7, client values 203.0.113.50 then 203.0.113.51: states=["miss-stored", "miss-stored"] origin_fetches=2

That matches the code: values_from(req.headers()) (lines 5303-5308) runs before the call at line 5316.

Moving the set_origin_client_ip_header(...) call to directly after req.headers_mut().remove("fastly-ssl"); (line 5259) fixes all three cases. That point is still after request_head_snapshot (line 5114), so the auction snapshot is unchanged. Same command, call moved:

test publisher::tests::template_cache_end_to_end_tests::probe1607_fastly_client_ip_absent ... PROBE1607 fastly-client-ip: cold=miss-stored warm=miss-stored origin_fetches=2 sent=["192.0.2.7", "198.51.100.9"] reader_b_got_a=false
test publisher::tests::template_cache_end_to_end_tests::probe1607_x_real_ip_absent ... PROBE1607 x-real-ip: cold=miss-stored warm=miss-stored origin_fetches=2 sent=["192.0.2.7", "198.51.100.9"] reader_b_got_a=false
test publisher::tests::template_cache_end_to_end_tests::probe1607_x_real_ip_client_supplied ... PROBE1607 x-real-ip: cold=miss-stored warm=miss-stored origin_fetches=2 sent=["192.0.2.7", "198.51.100.9"] reader_b_got_a=false
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 3398 filtered out; finished in 0.02s

Regression test for template_cache_end_to_end_tests. At this head, cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- origin_client_ip_header_keys_shared_templates_by_resolved_ip fails with should serve page-for-reader-b when fastly-client-ip carries the resolved IP. After the move, -- origin_client_ip publisher_origin_request_carries gives test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 3389 filtered out.

        fn services_for_client_ip(
            http_client: Arc<StubHttpClient>,
            cache: Arc<MemoryTemplateCache>,
            client_ip: IpAddr,
        ) -> RuntimeServices {
            RuntimeServices::builder()
                .config_store(Arc::new(NoopConfigStore))
                .secret_store(Arc::new(NoopSecretStore))
                .kv_store(Arc::new(edgezero_core::key_value_store::NoopKvStore))
                .backend(Arc::new(StubBackend))
                .http_client(http_client)
                .geo(Arc::new(NoopGeo))
                .client_info(ClientInfo {
                    client_ip: Some(client_ip),
                    ..ClientInfo::default()
                })
                .template_cache(cache)
                .build()
        }

        #[tokio::test]
        async fn origin_client_ip_header_keys_shared_templates_by_resolved_ip() {
            for name in ["fastly-client-ip", "x-real-ip"] {
                let stub = Arc::new(StubHttpClient::new());
                let cache = Arc::new(MemoryTemplateCache::default());
                let mut settings = settings_with_mode("esi");
                settings.publisher.origin_client_ip_header = Some(name.to_owned());
                settings
                    .creative_opportunities
                    .as_mut()
                    .expect("should configure creative opportunities")
                    .template_cache_vary = Some(vec![name.to_owned()]);
                let settings = Arc::new(settings);
                for marker in ["page-for-reader-a", "page-for-reader-b"] {
                    stub.push_response_with_headers(
                        200,
                        format!("<html><head></head><body>{marker}</body></html>").into_bytes(),
                        vec![
                            ("content-type", "text/html; charset=utf-8"),
                            ("cache-control", "public, max-age=300"),
                            ("vary", name),
                        ],
                    );
                }

                // Both readers send the same client-supplied copy, so a key read
                // before replacement would match and serve reader A's page to B.
                for (client_ip, marker) in [
                    (IpAddr::V4(Ipv4Addr::new(192, 0, 2, 7)), "page-for-reader-a"),
                    (
                        IpAddr::V4(Ipv4Addr::new(198, 51, 100, 9)),
                        "page-for-reader-b",
                    ),
                ] {
                    let services =
                        services_for_client_ip(Arc::clone(&stub), Arc::clone(&cache), client_ip);
                    let mut request = navigation_request();
                    request.headers_mut().insert(
                        header::HeaderName::from_static(name),
                        HeaderValue::from_static("203.0.113.50"),
                    );

                    let body = body_of(run(&settings, &services, request).await).await;

                    assert!(
                        String::from_utf8_lossy(&body).contains(marker),
                        "should serve {marker} when {name} carries the resolved IP"
                    );
                }
                assert_eq!(
                    stub.recorded_request_uris().len(),
                    2,
                    "should fetch the origin once per resolved IP for {name}"
                );
            }
        }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: fixed in 02e73fa. set_origin_client_ip_header now runs right after the fastly-ssl strip (crates/trusted-server-core/src/publisher.rs:4842 at 26a6ff423), before the template cache key reads req.headers(). It still runs after request_head_snapshot (line 4699), so the auction request never carries the header.

Regression test: origin_client_ip_header_keys_shared_templates_by_resolved_ip (line 12632) runs for fastly-client-ip and x-real-ip, with template_cache_vary naming the header. Two readers resolved to 192.0.2.7 and 198.51.100.9 both send the same client copy, 203.0.113.50. Each must get its own page, and the origin must see two fetches.

Evidence at dd8d80a58 (26a6ff423 adds only a docs paragraph):

  • cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- origin_client_ip publisher_origin_request_carries settings:: exits 0: test result: ok. 242 passed; 0 failed; 0 ignored; 0 measured; 3723 filtered out
  • Mutation: with the call moved back below the cache key, cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- origin_client_ip_header_keys_shared_templates_by_resolved_ip exits 101: should serve page-for-reader-b when fastly-client-ip carries the resolved IP. Restoring the file left the worktree clean.

@aram356 aram356 self-assigned this Nov 16, 2026
ChristianPavilonis added a commit that referenced this pull request Nov 25, 2026
…isher origin

Source: feat/publisher-origin-client-ip at b72119a.

Conflict resolution against the native stack, same as the first build:
- publisher.rs: the stack builds the origin request with publisher_origin_request
  instead of rewrite_origin_request. set_origin_client_ip_header runs on the
  request just before it, after template-cache key capture, as in the PR.
- proxy.rs, settings.rs: keep the stack's scripted-client tests. The asset proxy
  omission test and the publisher origin header test are ported to the scripted
  client and PublisherUpstream helpers.
- configuration.md: keep the stack's Spin note and add the new setting's section.

Open review items on #1607 (template-cache ordering P1, domain lint, missing
spec) are not addressed here.

@aram356 aram356 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: REQUEST_CHANGES

Phase: implementation. The PR body has no PRfection phase: line and links no spec or plan. Reviewed head b72119a727f73a2a422d2c0d1b09ea0cd80021b0 against base 1810c763add220dd34fd5faaffe2c69aab1d556f. Acting login aram356; PR author jevansnyc.

Summary

The local checks show the request Trusted Server builds for the publisher origin carries the configured header with the resolved IP, and the full local suite below passes apart from the URL-host lint. Changes are needed before approval:

  • The earlier template-cache thread on publisher.rs:5320 is confirmed and stays open. My reply there adds a case where the cache key is client-chosen, a verified fix location and a regression test.
  • Three blocking findings: the failing URL-host lint (one-click fix included), the missing spec and plan, and the unverified Fastly staging check.
  • Three should-fix findings: the validator accepts x-forwarded-host and x-forwarded-proto, and two docs statements are wrong on Axum, Cloudflare and Spin.
  • Two nits in the docs.

Each finding is an inline thread and needs a disposition before approval.

Findings

Severity Finding Thread
blocking Template-cache key reads the header before it is replaced (existing thread) crates/trusted-server-core/src/publisher.rs:5320
blocking Changed-line URL-host lint fails crates/trusted-server-core/src/settings.rs:6644
blocking No reviewed spec or plan for the new key and request change crates/trusted-server-core/src/settings.rs:81
blocking Fastly staging check for the headline example is unchecked docs/guide/fastly.md:267
should-fix Validator accepts x-forwarded-host / x-forwarded-proto crates/trusted-server-core/src/settings.rs:4063
should-fix [trusted_client_ip] changes the forwarded address only on Fastly docs/guide/configuration.md:548
should-fix Default does not keep client copies away from the origin docs/guide/configuration.md:557
nit Template cache hits never reach the origin docs/guide/configuration.md:546
nit Rewrap line 275 docs/guide/fastly.md:278

Executed checks

All checks ran at b72119a72 in a detached REVIEWER worktree (.worktrees/review-1607-b72119a) on macOS aarch64: Rust 1.98.1, Node 24.20.0, Viceroy 0.21.0 (the head's .tool-versions pins), Spin 4.1.0, wrangler 4.83.0, wasm-bindgen 0.2.126. Every Rust build compiled trusted-server-core from that worktree. Exit codes are those of the listed command; result lines are copied from its output.

Command Exit Result
cargo fmt --all -- --check 0 no diff
cargo clippy-fastly, clippy-axum, clippy-cloudflare, clippy-cloudflare-wasm, clippy-spin-native, clippy-spin-wasm, clippy-cli, clippy-codegen 0 each Finished, no lint output
cargo clippy -p trusted-server-core --target aarch64-apple-darwin --test template_build_digest -- -D warnings 0 Finished
scripts/lint-wasm-clock.sh 0 no violation output
cargo test-fastly 0 7 test result: ok lines, 3,708 passed, 0 failed, 31 ignored
cargo test-fastly-reuse 0 test result: ok. 243 passed; 0 failed; 5 ignored
node crates/trusted-server-adapter-fastly/tests/deadline-origin.mjs "$(command -v viceroy)" 0 test result: ok. 5 passed; 0 failed
cargo test -p trusted-server-core --target aarch64-apple-darwin --lib trace_document_skipped_emitted_script_leaves_ad_state_untouched -- --ignored 0 test result: ok. 1 passed; 0 failed
cargo test -p trusted-server-core --target aarch64-apple-darwin --lib trace_document_emitted_script_deep_freezes_owned_context_in_node -- --ignored 0 test result: ok. 1 passed; 0 failed
BID_DELAY=3 ./scripts/template-cache-local-test.sh esi / inline / purge 0 each 22 passed, 0 failed / 9 passed, 0 failed / 34 passed, 0 failed
./scripts/async-html-finalization-local-test.sh fastly --release --auction 0 test result: ok. 1 passed; 0 failed
./scripts/async-html-finalization-local-test.sh axum --auction 0 test result: ok. 1 passed; 0 failed
cargo build -p trusted-server-adapter-axum; cargo test-axum 0; 0 4 result lines, 60 passed, 0 failed, 1 ignored
cargo test-cloudflare 0 4 result lines, 57 passed, 0 failed, 1 ignored
cargo test-spin 0 3 result lines, 96 passed, 0 failed, 1 ignored
Cloudflare and Spin check, check-*, test-utils clippy and release builds from test.yml 0 each Finished
cargo test --manifest-path crates/trusted-server-integration-tests/Cargo.toml --test parity 0 test result: ok. 29 passed; 0 failed
integration-tests fmt --check and clippy --all-targets -- -D warnings 0; 0 no diff; Finished
html_eof_runtime test and clippy (integration-tests, --features html-eof-runtime) 0; 0 test result: ok. 15 passed; 0 failed; 3 ignored; Finished
cargo test -p trusted-server-core --test template_build_digest 0 test result: ok. 10 passed; 0 failed
cargo bench -p trusted-server-core --bench html_processor_bench -- --test 0 Success
cargo test --package trusted-server-openrtb-codegen --target aarch64-apple-darwin 0 test result: ok. 7 passed; 0 failed
cargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1 0 Finished
CLI clippy --all-targets, test, --test release_build_facts, ./scripts/test-cli.sh 0 each 953 passed, 0 failed, 19 ignored; 3 passed; 0 failed; 965 passed, 0 failed
Worker deadline fixtures: build, clippy, node scripts/test-worker-auction-deadlines.mjs cloudflare / spin 0 each 4 PASS, 0 FAIL / 5 PASS, 0 FAIL
npm run lint, npm run format, npx vitest run, node build-all.mjs (crates/trusted-server-js/lib) 0 each Tests 3298 passed | 1 skipped (3299)
npm run lint, npm run format, npm run build (docs); root Markdown Prettier check 0 each build complete
shellcheck scripts/docs-proposal/*.sh; node --test scripts/docs-proposal/hunks.test.mjs; scripts/docs-proposal/test.sh 0 each ℹ pass 20 ℹ fail 0; All documentation proposal script tests passed.
shellcheck scripts/release/phase1-build.sh; node --test scripts/release/phase1.test.mjs 0; 0 ℹ pass 27 ℹ fail 0
node --test scripts/check-ci-node-pin.test.mjs; node scripts/check-ci-node-pin.mjs 0; 0 ℹ pass 30 ℹ fail 0; ok: 34 jobs in 10 workflows pin Node before compiling Rust
test -L CLAUDE.md and its target 0 AGENTS.md
cargo run --manifest-path crates/trusted-server-cli/Cargo.toml --target aarch64-apple-darwin --bin ts -- dev lint domains --changed-vs origin/main 1 2 disallowed host(s) found in 1 file(s). (see the settings.rs:6644 thread)
Per-step commands and exit codes, in run order
head=b72119a727f73a2a422d2c0d1b09ea0cd80021b0 start=2026-12-02T00:43:10Z
setup-target-symlink               rc=0      0s  ln -s <cargo-target> target
setup-js-npm-ci                    rc=0      9s  npm ci --prefix crates/trusted-server-js/lib
setup-docs-npm-ci                  rc=0     25s  bash -c cd docs && npm ci
claude-md-symlink                  rc=0     26s  bash -c test -L CLAUDE.md && test "$(readlink CLAUDE.md)" = AGENTS.md
node-pin-guard-test                rc=0     30s  node --test scripts/check-ci-node-pin.test.mjs
node-pin-guard                     rc=0     18s  node scripts/check-ci-node-pin.mjs
cargo-fmt                          rc=0     13s  cargo fmt --all -- --check
clippy-fastly                      rc=0     37s  cargo clippy-fastly
clippy-axum                        rc=0     38s  cargo clippy-axum
clippy-cloudflare                  rc=0     41s  cargo clippy-cloudflare
clippy-cloudflare-wasm             rc=0     41s  cargo clippy-cloudflare-wasm
lint-wasm-clock                    rc=0     37s  scripts/lint-wasm-clock.sh
clippy-spin-native                 rc=0     31s  cargo clippy-spin-native
clippy-spin-wasm                   rc=0     32s  cargo clippy-spin-wasm
clippy-cli                         rc=0     51s  cargo clippy-cli
clippy-codegen                     rc=0     26s  cargo clippy-codegen
clippy-build-digest                rc=0     28s  cargo clippy -p trusted-server-core --target aarch64-apple-darwin --test template_build_digest -- -D warnings
js-lint                            rc=0     15s  bash -c cd crates/trusted-server-js/lib && npm run lint
js-format                          rc=0     13s  bash -c cd crates/trusted-server-js/lib && npm run format
js-vitest                          rc=0     41s  bash -c cd crates/trusted-server-js/lib && npx vitest run
js-build                           rc=0     11s  bash -c cd crates/trusted-server-js/lib && node build-all.mjs
docs-lint                          rc=0     12s  bash -c cd docs && npm run lint
docs-format                        rc=0     18s  bash -c cd docs && npm run format
md-format-outside-docs             rc=0     10s  docs/node_modules/.bin/prettier --config docs/.prettierrc --check *.md .claude/**/*.md .github/**/*.md crates/**/*.md scripts/**/*.md tinybird/**/*.md
docs-build                         rc=0     18s  bash -c cd docs && npm run build
docs-proposal-shellcheck           rc=0     11s  bash -c shellcheck scripts/docs-proposal/*.sh
docs-proposal-hunks                rc=0     10s  node --test scripts/docs-proposal/hunks.test.mjs
docs-proposal-test                 rc=0     20s  scripts/docs-proposal/test.sh
release-shellcheck                 rc=0     13s  shellcheck scripts/release/phase1-build.sh
release-phase1-test                rc=0     18s  node --test scripts/release/phase1.test.mjs
test-fastly                        rc=0   3824s  cargo test-fastly
fastly-deadline-origin             rc=0     49s  bash -c node crates/trusted-server-adapter-fastly/tests/deadline-origin.mjs "$(command -v viceroy)"
trace-ignored-skipped              rc=0     43s  cargo test -p trusted-server-core --target aarch64-apple-darwin --lib trace_document_skipped_emitted_script_leaves_ad_state_untouched -- --ignored
trace-ignored-freeze               rc=0     11s  cargo test -p trusted-server-core --target aarch64-apple-darwin --lib trace_document_emitted_script_deep_freezes_owned_context_in_node -- --ignored
test-fastly-reuse                  rc=0     23s  cargo test-fastly-reuse
template-cache-esi                 rc=0    127s  env BID_DELAY=3 ./scripts/template-cache-local-test.sh esi
template-cache-inline              rc=0     85s  env BID_DELAY=3 ./scripts/template-cache-local-test.sh inline
template-cache-purge               rc=0    114s  env BID_DELAY=3 ./scripts/template-cache-local-test.sh purge
async-html-fastly                  rc=0    126s  ./scripts/async-html-finalization-local-test.sh fastly --release --auction
build-axum                         rc=0     30s  cargo build -p trusted-server-adapter-axum
test-axum                          rc=0     32s  cargo test-axum
html-eof-test                      rc=0     21s  cargo test --manifest-path crates/trusted-server-integration-tests/Cargo.toml --target aarch64-apple-darwin --features html-eof-runtime --test html_eof_runtime
html-eof-clippy                    rc=0     23s  cargo clippy --manifest-path crates/trusted-server-integration-tests/Cargo.toml --target aarch64-apple-darwin --features html-eof-runtime --test html_eof_runtime -- -D warnings
async-html-axum                    rc=0     16s  ./scripts/async-html-finalization-local-test.sh axum --auction
core-build-digest-test             rc=0     34s  cargo test -p trusted-server-core --test template_build_digest
core-bench-smoke                   rc=0     49s  cargo bench -p trusted-server-core --bench html_processor_bench -- --test
codegen-test                       rc=0     13s  cargo test --package trusted-server-openrtb-codegen --target aarch64-apple-darwin
fastly-release-build               rc=0     37s  cargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1
cli-clippy                         rc=0     45s  cargo clippy --manifest-path crates/trusted-server-cli/Cargo.toml --target aarch64-apple-darwin --all-targets -- -D warnings
cli-test                           rc=0     62s  cargo test --manifest-path crates/trusted-server-cli/Cargo.toml --target aarch64-apple-darwin
cli-release-build-facts            rc=0     33s  cargo test --manifest-path crates/trusted-server-cli/Cargo.toml --target aarch64-apple-darwin --test release_build_facts
test-cli-sh                        rc=0     90s  ./scripts/test-cli.sh
cloudflare-check-native            rc=0     45s  cargo check -p trusted-server-adapter-cloudflare
cloudflare-check-wasm              rc=0     31s  cargo check -p trusted-server-adapter-cloudflare --target wasm32-unknown-unknown --features cloudflare
cloudflare-clippy-test-utils       rc=0     38s  cargo clippy -p trusted-server-adapter-cloudflare --target wasm32-unknown-unknown --features cloudflare,test-utils --lib -- -D warnings
test-cloudflare                    rc=0     39s  cargo test-cloudflare
spin-check-native                  rc=0     34s  cargo check -p trusted-server-adapter-spin
spin-check-wasm                    rc=0     42s  cargo check-spin
spin-clippy-test-utils             rc=0     36s  cargo clippy -p trusted-server-adapter-spin --target wasm32-wasip1 --features spin,test-utils --lib -- -D warnings
spin-release-build                 rc=0     82s  cargo build --package trusted-server-adapter-spin --target wasm32-wasip1 --features spin --release
test-spin                          rc=0     54s  cargo test-spin
integration-fmt                    rc=0     42s  cargo fmt --manifest-path crates/trusted-server-integration-tests/Cargo.toml -- --check
parity                             rc=0     66s  cargo test --manifest-path crates/trusted-server-integration-tests/Cargo.toml --test parity
integration-clippy                 rc=0     57s  cargo clippy --manifest-path crates/trusted-server-integration-tests/Cargo.toml --all-targets -- -D warnings
cf-deadline-build                  rc=0     60s  cargo build --locked -p trusted-server-adapter-cloudflare --example deadline-runtime --target wasm32-unknown-unknown --features cloudflare
cf-deadline-clippy                 rc=0     35s  cargo clippy --locked -p trusted-server-adapter-cloudflare --example deadline-runtime --target wasm32-unknown-unknown --features cloudflare -- -D warnings
cf-deadline-run                    rc=0     31s  env ASDF_NODEJS_VERSION=24.20.0 PATH=<scratch wasm-bindgen 0.2.126 and wrangler 4.83.0>:$PATH node scripts/test-worker-auction-deadlines.mjs cloudflare --runtime <scratch wrangler>
spin-deadline-build                rc=0     53s  cargo build --locked -p trusted-server-adapter-spin --example deadline-runtime --target wasm32-wasip1 --features spin
spin-deadline-clippy               rc=0     43s  cargo clippy --locked -p trusted-server-adapter-spin --example deadline-runtime --target wasm32-wasip1 --features spin -- -D warnings
spin-deadline-run                  rc=0     31s  bash -c node scripts/test-worker-auction-deadlines.mjs spin --runtime "$(command -v spin)"
lint-domains                       rc=1     57s  cargo run --manifest-path crates/trusted-server-cli/Cargo.toml --target aarch64-apple-darwin --bin ts -- dev lint domains --changed-vs origin/main
end=2026-12-02T02:30:46Z status=[]

Not run locally: the Docker-based integration tests, integration tests (Fastly EC lifecycle), browser integration tests, trace runtime and browser acceptance and prepare integration artifacts jobs, and CodeQL. GitHub reports each as passing at this head, and those are GitHub's results, not mine.

GitHub checks at this head: 29 pass and 1 fails (ts dev lint domains (changed lines), not a required check). The required checks cargo fmt, cargo test, format-docs and format-typescript pass. These runs predate #1671 and #1501 on main. git merge-tree --write-tree origin/main with this head completes without conflicts.

Next actor: the PR author, for the corrections and dispositions on each thread. The spec item may need a maintainer decision instead.

Comment on lines +6639 to +6644
let toml_str = crate_test_settings_str().replace(
r#"origin_url = "https://origin.test-publisher.com""#,
&format!(
"origin_url = \"https://origin.test-publisher.com\"\norigin_client_ip_header = {header:?}"
),
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: blocking The changed-line URL-host lint fails on this helper.

Impact: AGENTS.md lists the changed-line URL-host lint as a PR gate, and the ts dev lint domains (changed lines) check is FAIL at b72119a72.

Evidence:

  • Check: cargo run --manifest-path crates/trusted-server-cli/Cargo.toml --target aarch64-apple-darwin --bin ts -- dev lint domains --changed-vs origin/main exits 1 at this head:
    crates/trusted-server-core/src/settings.rs:6640: disallowed host origin.test-publisher.com
    crates/trusted-server-core/src/settings.rs:6642: disallowed host origin.test-publisher.com
  • Both lines come from matching the fixture's origin_url line. [publisher] appears once in crate_test_settings_str() (test_support.rs:23, read at this head).

Requested correction: insert the field after the [publisher] header, so the helper no longer repeats the host and the shared fixture stays unchanged:

Suggested change
let toml_str = crate_test_settings_str().replace(
r#"origin_url = "https://origin.test-publisher.com""#,
&format!(
"origin_url = \"https://origin.test-publisher.com\"\norigin_client_ip_header = {header:?}"
),
);
let toml_str = crate_test_settings_str().replacen(
"[publisher]",
&format!("[publisher]\norigin_client_ip_header = {header:?}"),
1,
);

With it applied: cargo fmt --all -- --check exits 0, cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- origin_client_ip exits 0 (test result: ok. 8 passed), and ts dev lint domains --staged on the staged change exits 0 with no output.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: fixed in 83b12a2. The helper now inserts the field after [publisher] with replacen and names no real host. That commit came in with the identity-chain merges; my identical change was dropped as already applied when I rebased onto them.

At 26a6ff423, cargo run --manifest-path crates/trusted-server-cli/Cargo.toml --target aarch64-apple-darwin --bin ts -- dev lint domains --changed-vs origin/feat/1598-ec-route-fastly (the PR's base since the retarget) exits 0 with no findings.

/// [`Self::allow_async_html_finish`].
#[serde(default, skip_serializing_if = "Option::is_none")]
#[validate(custom(function = validate_origin_client_ip_header))]
pub origin_client_ip_header: Option<String>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: blocking This configuration key and the publisher request change have no reviewed spec or plan.

Impact: CONTRIBUTING.md requires a spec with its review rounds before a feature's implementation is reviewed. Lines 37-39, read at this head: "A feature adds or changes behavior that people outside the code rely on. That includes a new integration, route, CLI command, or configuration key, and any change to request handling". This line adds the configuration key publisher.origin_client_ip_header, and publisher.rs:5316-5320 changes the publisher-origin request. The PR body's Spec section says "Not a feature". The earlier review raised the same requirement in its body.

Requested correction: link a spec and plan for this setting that went through review, or record an explicit maintainer exception on this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: won't fix. The maintainer exception is recorded at #1607 (comment): aram356 waives the spec-and-plan requirement for this PR at 26a6ff423, scoped to the publisher.origin_client_ip_header setting and the publisher-origin request change.

What remains: no reviewed spec or plan describes the setting. Its design record is the PR description and the two guide sections, and a later change to the setting's behavior is not covered by the exception.

Comment thread docs/guide/fastly.md
Comment on lines +264 to +267
```toml
[publisher]
origin_client_ip_header = "fastly-client-ip"
```

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: blocking The headline example has not been checked on Fastly.

Impact: this PR exists so origins behind Fastly receive Fastly-Client-IP again. The test plan's only runtime item is unchecked: "Staging: with origin_client_ip_header = \"fastly-client-ip\", confirm the origin logs one Fastly-Client-IP holding the reader address, with and without [trusted_client_ip]".

Evidence: the PR's new tests read the header off StubHttpClient (publisher_origin_request_carries_configured_client_ip_header), which shows the request Trusted Server builds. None of the checks I ran (listed in the review body) sends a request through Fastly production to a backend, so what that backend receives for this header is untested here.

Requested correction: run the staging item and post the origin log lines. One Fastly-Client-IP holding the reader address in both configurations withdraws this finding. A missing, repeated or replaced value confirms it, and the example and docs then need to change.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: blocked. The staging item needs a deployed Fastly service and its origin logs, which this session does not have.

  • Next actor: aram356 or the PR author, jevansnyc.
  • Next step: deploy 26a6ff423 to a Fastly staging service with origin_client_ip_header = "fastly-client-ip". Request a page once without [trusted_client_ip] and once with it, through a fronting CDN that sends the configured header and secret, and post the origin's Fastly-Client-IP log lines for both.

Local evidence, which does not replace staging: the Fastly Wasm built at dd8d80a58 (the adapter code is unchanged at 26a6ff423) served by Viceroy 0.22.0, the repository pin. One request to /assets/logo.png carried a client-sent Fastly-Client-IP: 198.51.100.20 to a loopback origin:

case=with-setting setting=fastly-client-ip ts_status=200
origin: GET /assets/logo.png fastly-client-ip=["127.0.0.1"]
case=unset setting=unset ts_status=200
origin: GET /assets/logo.png fastly-client-ip=[]

With the setting, the origin received one value, the resolved peer address, and the spoofed copy was gone. Unset, the adapter's entry strip left the origin no value. Viceroy does not reproduce the Fastly edge between Trusted Server and a backend, and this run did not configure [trusted_client_ip], so the finding stays open until the staging lines are posted.

Comment on lines +4058 to +4063
let allowed = matches!(
name,
"fastly-client-ip" | "true-client-ip" | "x-forwarded-for"
) || (name.starts_with("x-")
&& !name.starts_with("x-ts-")
&& !INTERNAL_HEADERS.contains(&name));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: should-fix The validator accepts x-forwarded-host and x-forwarded-proto.

Impact: with origin_client_ip_header = "x-forwarded-host", every publisher-origin request carries X-Forwarded-Host: <resolved client IP>, so an origin that reads that header receives an IP address as the forwarded host. The PR description says validation rejects host and forwarded; these two names carry the same meaning.

Evidence:

  • Diff: the x- branch (lines 4061-4063) excludes only x-ts-* and INTERNAL_HEADERS. Neither name is in INTERNAL_HEADERS (constants.rs:68-92, read at this head). Both are in SPOOFABLE_FORWARDED_HEADERS (http_util.rs:47-53), which validate_trusted_forwarder (settings.rs:3238) already rejects.
  • Check: with "x-forwarded-host" and "x-forwarded-proto" added to validate_rejects_unsafe_origin_client_ip_headers, cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- validate_rejects_unsafe_origin_client_ip_headers exits 101 at this head: origin_client_ip_header "x-forwarded-host" should fail validation. With the line below also applied, cargo fmt --all -- --check exits 0 and cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- settings:: exits 0: test result: ok. 221 passed; 0 failed; 0 ignored; 0 measured; 3177 filtered out.

Requested correction: exclude the spoofable forwarding names from the x- branch:

Suggested change
let allowed = matches!(
name,
"fastly-client-ip" | "true-client-ip" | "x-forwarded-for"
) || (name.starts_with("x-")
&& !name.starts_with("x-ts-")
&& !INTERNAL_HEADERS.contains(&name));
let allowed = matches!(
name,
"fastly-client-ip" | "true-client-ip" | "x-forwarded-for"
) || (name.starts_with("x-")
&& !name.starts_with("x-ts-")
&& !SPOOFABLE_FORWARDED_HEADERS.contains(&name)
&& !INTERNAL_HEADERS.contains(&name));

Then add "x-forwarded-host" and "x-forwarded-proto" to the reject list after "x-ts-client-ip-auth", and x-forwarded-host to the Rejected example in docs/guide/configuration.md.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: fixed in e695ec8, as suggested. The x- branch now also excludes SPOOFABLE_FORWARDED_HEADERS (crates/trusted-server-core/src/settings.rs:4622 at 26a6ff423), and the validator's doc comment names both headers (line 4610). validate_rejects_unsafe_origin_client_ip_headers lists x-forwarded-host and x-forwarded-proto after x-ts-client-ip-auth. docs/guide/configuration.md lists both under Format (line 572) and x-forwarded-host in the Rejected example (line 578).

Evidence at dd8d80a58:

  • The targeted core run on the template-cache thread exits 0: test result: ok. 242 passed; 0 failed; 0 ignored; 0 measured; 3723 filtered out
  • Mutation: with the SPOOFABLE_FORWARDED_HEADERS line deleted, cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- validate_rejects_unsafe_origin_client_ip_headers exits 101: origin_client_ip_header "x-forwarded-host" should fail validation. Restoring the file left the worktree clean.

Comment thread docs/guide/configuration.md Outdated
Comment on lines +547 to +548
- Behind a fronting CDN, configure [`[trusted_client_ip]`](./fastly.md#cdn-fronted-client-ip) as well;
without it the resolved address is the CDN node, not the reader

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: should-fix [trusted_client_ip] changes the forwarded address only on Fastly.

Impact: operators on Axum, Cloudflare or Spin who follow this bullet still send a proxy address to the origin behind a load balancer or another CDN, which is the rate-limit risk docs/guide/fastly.md warns about.

Evidence (reads at this head):

  • The publisher handler forwards services.client_info().client_ip (publisher.rs:5319).
  • Cloudflare sets it from cf-connecting-ip (trusted-server-adapter-cloudflare/src/platform.rs:758-763), Spin from SpinRequestContext::client_addr (trusted-server-adapter-spin/src/platform.rs:804-807), and Axum from AxumRequestContext::remote_addr (trusted-server-adapter-axum/src/platform.rs:585-587).
  • This file, lines 813-816: "Axum, Cloudflare and Spin also use them for the masked client IP in both trace setup and traced publisher documents; their ordinary request handling continues to use the runtime-provided address."

Requested correction:

Suggested change
- Behind a fronting CDN, configure [`[trusted_client_ip]`](./fastly.md#cdn-fronted-client-ip) as well;
without it the resolved address is the CDN node, not the reader
- On Fastly behind a fronting CDN, configure
[`[trusted_client_ip]`](./fastly.md#cdn-fronted-client-ip) as well; without
it the resolved address is the CDN node, not the reader. Axum, Cloudflare and
Spin send the address their runtime reports, which `[trusted_client_ip]` does
not change, so behind a load balancer or another CDN it is the proxy address

Please make the same change by hand in the field doc comment (settings.rs:74-75), the CHANGELOG entry and trusted-server.example.toml:76. This suggestion sits next to the one on line 546; apply both with Add suggestion to batch. prettier --config docs/.prettierrc --check exits 0 with this change applied.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: fixed in dd8d80a and 26a6ff4. The bullet at docs/guide/configuration.md:563-570 is your suggestion with one change for the new base. The field doc comment (settings.rs:71-81), the CHANGELOG entry and trusted-server.example.toml:76-77 carry the Fastly-only scope by hand.

The change: since the retarget onto feat/1598-ec-route-fastly, Axum takes the client address from EdgeZero's checked ingress (crates/trusted-server-adapter-axum/src/platform.rs:94-101, NativeIngressMetadata::effective_client). When EdgeZero trusts the proxy, that address is the reader's from the forwarding header, so "behind a load balancer or another CDN it is the proxy address" no longer held for Axum. The bullet now ends: "Behind a load balancer or another CDN that is the proxy address. On Axum, set EDGEZERO__ADAPTER__TRUSTED_PROXY_CIDRS to the proxy's address and EDGEZERO__ADAPTER__FORWARDING_HEADER_FAMILY to the header family it sends (forwarded or x-forwarded) to send the reader's address instead".

Evidence:

  • Throwaway Axum probe at dd8d80a58 (not in this PR; adapted from scripts/smoke-axum.sh). With origin_client_ip_header = "fastly-client-ip", a loopback client sent Forwarded: for=198.51.100.30 and Fastly-Client-IP: 198.51.100.20 to /assets/logo.png:
    case=no-proxy-policy ts_status=200
    origin: GET /assets/logo.png fastly-client-ip=["127.0.0.1"] forwarded=[]
    case=trusted-loopback-proxy ts_status=200
    origin: GET /assets/logo.png fastly-client-ip=["198.51.100.30"] forwarded=[]
    
    The second case set EDGEZERO__ADAPTER__TRUSTED_PROXY_CIDRS=127.0.0.1/32 and EDGEZERO__ADAPTER__FORWARDING_HEADER_FAMILY=forwarded.
  • At 26a6ff423: docs/node_modules/.bin/prettier --config docs/.prettierrc --check docs/guide/configuration.md exits 0, and cd docs && npm run format exits 0: All matched files use Prettier code style!

Comment thread docs/guide/configuration.md Outdated
- Accepted: `fastly-client-ip`, `x-real-ip`
- Rejected: `forwarded`, `x-ts-client-ip-auth`

**Default**: When omitted, no client-IP header is sent to the origin.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: should-fix The default does not keep client-supplied copies away from the origin.

Impact: "no client-IP header is sent" reads as a promise that the origin never receives a client-chosen value. That holds only for Fastly-Client-IP on Fastly and Spin, so an operator relying on it could trust a spoofed header.

Evidence:

  • Check: a throwaway handler-level probe (not in this PR) with the field unset sent X-Real-IP, X-Forwarded-For and Fastly-Client-IP through handle_publisher_request. The recorded origin request printed: PROBE1607_DEFAULT origin saw [("x-real-ip", "198.51.100.20"), ("x-forwarded-for", "198.51.100.21"), ("fastly-client-ip", "198.51.100.22")].
  • Reads at this head: only adapter entry stripping removes any of them. Fastly strips SPOOFABLE_FORWARDED_HEADERS (trusted-server-adapter-fastly/src/compat.rs:75). Spin strips the same list and x-forwarded-for (trusted-server-adapter-spin/src/app.rs:297,305). A search of the Axum and Cloudflare adapters, and of EdgeZero v0.0.11 and v0.0.12, found no removal of these names.

Requested correction:

Suggested change
**Default**: When omitted, no client-IP header is sent to the origin.
**Default**: When omitted, Trusted Server adds no client-IP header, and a
client-supplied copy of a name the adapter does not strip at request entry (for
example `X-Real-IP`) reaches the origin unchanged.

The Purpose paragraph (lines 534-536) has the same scope problem: the strip it describes happens on Fastly and Spin only.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: fixed in dd8d80a. Default is your suggestion verbatim (docs/guide/configuration.md:580-582 at 26a6ff423). The Purpose paragraph (line 548) now scopes the strip to Fastly and Spin: "The Fastly and Spin adapters strip client-spoofable forwarding headers such as Fastly-Client-IP at request entry, so on those adapters the publisher origin gets no client address in that header and sees Trusted Server's own egress address as the peer". The field doc comment (settings.rs:71-81) says the same.

Evidence at dd8d80a58: your handler-level probe, re-run with the field unset, still prints PROBE1607_DEFAULT origin saw [("fastly-client-ip", "198.51.100.22"), ("x-real-ip", "198.51.100.20"), ("x-forwarded-for", "198.51.100.21")], which the new Default sentence describes. cd docs && npm run format exits 0 at 26a6ff423.

publisher-origin request
- Removes any client-supplied copy first, so the origin receives exactly one
value that the client cannot choose
- Omits the header when no client IP was resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: nit Say that template cache hits never reach the origin.

Impact: with the template cache on, a reader served a cached template never contacts the origin, so origin logs and rate limits see that reader only on a miss. The PR description notes the cache interaction; these docs do not.

Evidence: in the throwaway two-reader probe (not in this PR) posted on the publisher.rs:5320 thread, cargo test -p trusted-server-core --target aarch64-apple-darwin --lib -- probe1607 --nocapture --test-threads=1 printed PROBE1607 fastly-client-ip: cold=miss-stored warm=hit origin_fetches=1 sent=["192.0.2.7"] at this head: the second reader was a template hit, and the origin recorded one request.

Requested correction:

Suggested change
- Omits the header when no client IP was resolved
- Omits the header when no client IP was resolved
- Reaches the origin on template cache misses only: a template cache hit never
contacts the origin

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: fixed in dd8d80a with your suggestion (docs/guide/configuration.md:561-562 at 26a6ff423): "Reaches the origin on template cache misses only: a template cache hit never contacts the origin". cd docs && npm run format exits 0.

Comment thread docs/guide/fastly.md Outdated
Comment on lines +275 to +278
every reader, which can trip origin rate limits. If the request to `origin_url` passes back through a Fastly VCL service
that overwrites `Fastly-Client-IP` with `client.ip`, that service replaces the
value with Trusted Server's egress address, so point `origin_url` at the origin
directly or exempt that route from the overwrite.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER: nit Rewrap line 275.

Line 275 runs to about 120 columns, while the rest of the section wraps at 80. docs/.prettierrc sets proseWrap: preserve, so Prettier leaves it alone. With the change below, prettier --config docs/.prettierrc --check docs/guide/fastly.md exits 0.

Suggested change
every reader, which can trip origin rate limits. If the request to `origin_url` passes back through a Fastly VCL service
that overwrites `Fastly-Client-IP` with `client.ip`, that service replaces the
value with Trusted Server's egress address, so point `origin_url` at the origin
directly or exempt that route from the overwrite.
every reader, which can trip origin rate limits. If the request to `origin_url`
passes back through a Fastly VCL service that overwrites `Fastly-Client-IP` with
`client.ip`, that service replaces the value with Trusted Server's egress
address, so point `origin_url` at the origin directly or exempt that route from
the overwrite.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATOR: fixed in dd8d80a. The paragraph at docs/guide/fastly.md:274-278 now wraps at 80 columns like the rest of the section. cd docs && npm run format exits 0 at 26a6ff423: All matched files use Prettier code style!

PR #1607 moves from main onto PR #1662's branch, feat/1598-ec-route-fastly, the top of the identity chain trunk. PR #1662's head (round 14, 7bbe9bb) brings the identity integration chain, including EdgeZero's outbound requests, the scripted-client test harness and the removal of origin_host_header. The resolution follows Christian's resolution of the same merge in rc/pre-ramp (58a65ab), re-derived on this head.

crates/trusted-server-core/src/publisher.rs: #1607 calls set_origin_client_ip_header right after rewrite_origin_request. The chain removed rewrite_origin_request and builds the origin request with publisher_origin_request a few lines later. The resolution keeps the chain's builder and calls set_origin_client_ip_header on the request just before it, still after the template-cache key capture. #1607's publisher_origin_request_carries_configured_client_ip_header test is ported from StubHttpClient to the chain's PublisherUpstream, with the resolved client IP set on the services' client info.

crates/trusted-server-core/src/proxy.rs: both sides changed the test imports and added tests at the same place. The resolution keeps the chain's outbound and scripted-client imports and its asset_proxy_get_request_readback test, and ports #1607's handle_asset_proxy_request_omits_publisher_origin_client_ip_header to the chain's scripted client.

crates/trusted-server-core/src/settings.rs: #1607 added origin_client_ip_header to the two origin_host_header tests, which the chain removed along with origin_host_header. The resolution keeps the removal.

docs/guide/configuration.md: the chain added a Spin note to the end of origin_host_header_override, where #1607 adds the origin_client_ip_header section. The resolution keeps the Spin note, then #1607's section.

CHANGELOG.md: both sides added entries at the top of Added. The resolution keeps the chain's entries first, then #1607's.
settings_with_origin_client_ip_header added the key by rewriting the shared
test settings' origin_url line, which named origin.test-publisher.com. The
URL-host lint flags that host on lines this PR adds. The helper now inserts the
key under the [publisher] table header instead, so the test exercises the same
validation and names no host.
PR #1662's new head (14749b9) keeps the consent-string comment on the EC route fixture in identity_conformance.rs. The merge is clean.
PR #1662's new head (20f849f) merges PR #1661's head (a3c937f). It brings EdgeZero ef5cbf308, which includes EdgeZero #524 and names Fastly backends with the ez_b31v2_ prefix, and pin-project-lite 0.2.19 from PR #1506. It also brings PR #1626's mirror changes (mirror_provider_policy_denied, SharedIdWriteBackTime), the two smoke-test fixes in PR #1627 and PR #1537, and PR #1535's change that skips re-posting an unchanged Sourcepoint consent mirror. The merge is clean.
aram356 added a commit that referenced this pull request Dec 3, 2026
PR #1503 at 1d51b78: Add ts ec show and ts ec eids admin diagnostic commands
PR #1653 at f217902: Clarify and verify the Axum local config handoff
PR #1654 at e4e68bb: Verify pending record writes drain within shutdown grace
PR #1655 at 7d0cdb2: Configure EC lifetime and renew it on eligible visits (DEC-13)
PR #1659 at bd707f2: Verify geo consent paths on Axum and Fastly
PR #1660 at 87c52cd: Retry an after-response write that loses its CAS
PR #1666 at b1d7062: Verify identity gates and provider deadlines on Axum
PR #1710 at 3d33359: Apply pull-sync consent checks to identify
PR #1557 at 3982143: Carry Sourcepoint TCF consent to Trusted Server
PR #1667 at f9ac6bb: Present a client certificate on auction providers that set mtls
PR #1607 at b3a0b09: Send the resolved client IP to the publisher origin
PR #1709 at 635f06a: Keep the EC out of bid request IDs and gate user.id on EID consent
PR #1713 at e5f4d05: Apply consent rules to first-party click redirects
PR #1622 at dd2ee39: Report CMP consent to the EC route and merge its answer into Prebid
@aram356
aram356 changed the base branch from main to feat/1598-ec-route-fastly December 3, 2026 11:34
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Round 15 identity realignment: rc/identity is now at 391a08578, and EdgeZero is pinned to its rc/identity at ef5cbf308. This branch fast-forwarded from b72119a72 to b3a0b0987:

The base is now feat/1598-ec-route-fastly (#1662), so this PR sits on the identity chain. Its merges were clean.

Each merge message says what it carries and how any conflict was resolved.

Carries #1533's Axum startup-test port fix (779e446) and nothing
else. Owner commits pushed to other chain PRs since round 15 come in
with the next round.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Cascade of #1533's Axum startup-test port fix (779e44673): 1f1a8a787 merges it into this PR. There were no conflicts and nothing else changed. The fix moves free_loopback_port in crates/trusted-server-adapter-axum/tests/routes.rs below the ephemeral port range, and #1533's note has the details. Owner commits pushed to other chain PRs since round 15 come in with the next round. rc/identity is now 62f8e41e2.

The template cache key read the configured Vary headers before the
origin client-IP header was replaced, so it saw the client's copy or no
value. With template_cache_vary naming that header and an origin that
varies on it, readers with different resolved addresses shared one
cached template. Write the header right after the fastly-ssl strip,
still after the auction request snapshot, and cover two readers with a
regression test through the template cache.
origin_client_ip_header accepted x-forwarded-host and x-forwarded-proto,
so an operator could send the resolved client IP to the origin as its
forwarded host or scheme. Reject the SPOOFABLE_FORWARDED_HEADERS names
in the x- branch, as validate_trusted_forwarder already does, and list
them in the validation test and the configuration guide.
Only the Fastly adapter feeds [trusted_client_ip] into the resolved
client IP; Axum, Cloudflare and Spin forward the address their runtime
reports. Only Fastly and Spin strip Fastly-Client-IP at entry, and a
client-supplied copy of any other name reaches the origin when the
setting is unset. Say so in the configuration guide, the field doc
comment, the example config and the changelog, note that template cache
hits never reach the origin, and rewrap the long line in the Fastly
guide.
Since the retarget onto the identity chain, Axum reads the client address from EdgeZero's checked ingress, which resolves the reader behind a proxy that EDGEZERO__ADAPTER__TRUSTED_PROXY_CIDRS and EDGEZERO__ADAPTER__FORWARDING_HEADER_FAMILY trust. Say so instead of stating that Axum always sends the proxy address.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

CREATOR: Maintainer exception for the spec-and-plan requirement on this PR.

@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

CREATOR: Ready for re-review at 26a6ff423.

  • Account mode: one-account. Acting login aram356; PR author jevansnyc.
  • Base: feat/1598-ec-route-fastly at f6dbcaf13. The PR was retargeted onto the identity chain during this round, and the chain merges moved the head from b72119a72 to 1f1a8a787 before my commits. Those merges came from a separate identity-chain session that also pushes to this branch.
  • Commits this round: 02e73fae7 (template-cache ordering and regression test), e695ec870 (validator), dd8d80a58 (docs scope), 26a6ff423 (Axum trusted-proxy sentence, docs only).
Finding Disposition
Template-cache Vary ordering fixed in 02e73fae7
Changed-line URL-host lint fixed in 83b12a276
Spec and plan won't fix: maintainer exception
Fastly staging check blocked: needs a staging deploy by aram356 or jevansnyc; Viceroy evidence in the thread
Spoofable forwarding names fixed in e695ec870
[trusted_client_ip] scope fixed in dd8d80a58 and 26a6ff423
Default pass-through fixed in dd8d80a58
Template cache hits fixed in dd8d80a58
Rewrap fixed in dd8d80a58

The [trusted_client_ip] reply explains one departure from the suggested text: on this base, Axum sends the reader's address behind a proxy that EdgeZero trusts, shown by a local Axum probe.

Validation (macOS aarch64, 2026-12-03). The full prescribed suite ran at dd8d80a58: 99 steps, covering AGENTS.md gates 1-21, the HTML EOF checks, the template-cache harness and the four health-startup smokes. 26a6ff423 changes only docs/guide/configuration.md and was re-checked with the docs gates.

  • 91 steps exited 0 on the first pass, including: cargo fmt, all eight clippy aliases, cargo test-axum (143 passed), cargo test-cloudflare (74 passed), cargo test-spin (92 passed), parity (40 passed), vitest (3379 passed), the template-cache harness (esi 23, inline 9, purge 35 passed, 0 failed), the Fastly deadline and proxy-policy fixtures, both worker-deadline runtimes, async-html-finalization-local-test.sh axum --auction, and smoke-{fastly,axum,cloudflare,spin}.sh.
  • cargo test-fastly, cargo test-fastly-reuse, the Fastly identity-conformance run and async-html-finalization-local-test.sh fastly --release --auction first failed with unknown import: fastly_compute_runtime::has_domain_inspector, because cargo's runner resolved Viceroy 0.21.0 from the local Rust toolchain directory. Forced onto Viceroy 0.22.0 (the repository pin), all four exit 0. cargo test-fastly: 4452 passed, 0 failed, 40 ignored. test-fastly-reuse: 262 passed. The EOF Fastly control: 1 passed.
  • cargo test for the CLI and scripts/test-cli.sh first failed in smoke_setup_replaces_the_template_with_the_selected_listener (No version is set for command node), because the test clears the environment and the local Node shim then has no version. With the pinned Node 24.20.0 first on PATH, both exit 0: 973 and 985 passed, 0 failed.
  • cargo test --locked -p trusted-server-adapter-axum --features aws-dynamodb-ec failed once in tampered_envelope_serves_the_failure_router (should keep running after an initialization failure, exited with Some(ExitStatus(unix_wait_status(256)))). It then exited 0 on two plain re-runs; the change does not touch Axum startup.
  • Not run here: scripts/test-runtime-env.sh aarch64-unknown-linux-gnu, because that target's standard library is not installed on this host. CI's Linux job runs it.
  • Mutations at dd8d80a58: moving the header call back below the template cache key fails origin_client_ip_header_keys_shared_templates_by_resolved_ip (exit 101). Deleting the SPOOFABLE_FORWARDED_HEADERS exclusion fails validate_rejects_unsafe_origin_client_ip_headers (exit 101). The worktree was clean after each restore.
  • At 26a6ff423: cd docs && npm run format exits 0, and ts dev lint domains --changed-vs origin/feat/1598-ec-route-fastly exits 0 with no findings.

CI at 26a6ff423 was still pending when this was posted.

@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Merged #1627's runtime KV removal (7c2b84f45) into this branch as 11964d1b3, on top of 26a6ff423.

At the maintainer's request, that commit removes the generic runtime KV store trusted_server_runtime_kv. Nothing reads or writes it, and the managed Fastly deploy made every service provision and pay for it. edgezero.toml and the Fastly Hooks::stores() now declare only trusted_server_kv, and RuntimeServices::kv_store() is unavailable on every adapter.

Only that commit was merged, not the base branch's new head. Conflicts were resolved in edgezero.toml, the Fastly Hooks::stores() in app.rs, fastly.toml, the Viceroy template, the integration tests' config.rs, trusted-server.example.toml, docs/guide/architecture.md and docs/guide/edgezero.md. Only trusted_server_kv stays declared, this branch's record-store comment and local seeds are kept, and the runtime-KV lines are dropped. The Axum README and docs/guide/axum-dev.md keep this branch's Axum wording.

Checks on this head: no reference to the removed store remains and cargo fmt --check passes; clippy-fastly, clippy-axum, clippy-cloudflare and clippy-spin-native pass. rc/identity (b9dc3153e) passed the full CI gate list with the removal.

PR #1662's new head brings #1487's change that strips `ts-eids` from publisher-origin requests unless the operator opts in and #1646's fix that preserves filter headers through identity finalization.

crates/trusted-server-core/src/publisher.rs: #1607 now writes the
configured origin client-IP header right after the `fastly-ssl` strip so
the template cache key sees the resolved address, and #1487 (through
#1662) strips `ts-eids` from the origin request at the same spot unless
`forward_eids_cookie_to_origin` is on. Both are independent header edits
made before the cache key is built. The resolution keeps both, the
`ts-eids` strip first, so the client-IP write still sits directly above
the cache key it protects.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Round 17 identity realignment: rc/identity is now at 0ed862633, and EdgeZero stays pinned to its rc/identity at ef5cbf308. This branch fast-forwarded from 11964d1b3 to 07086f23e:

In publisher.rs the origin request now strips ts-eids (#1487) and then writes this PR's client-IP header, both before the template cache key is built.

Each merge message says what it carries and how any conflict was resolved.

aram356 added a commit that referenced this pull request Dec 3, 2026
PR #1503 at 6a8797e: Add ts ec show and ts ec eids admin diagnostic commands
PR #1557 at a435778: Carry Sourcepoint TCF consent to Trusted Server
PR #1607 at 07086f2: Send the resolved client IP to the publisher origin
PR #1627 at 5b7fc3d: Wire declared stores and document unsupported Axum KV
PR #1636 at d838931: Drain Axum after-response identity tasks on SIGTERM
PR #1653 at 5b86d9b: Clarify and verify the Axum local config handoff
PR #1654 at be495b3: Verify pending record writes drain within shutdown grace
PR #1655 at 888c5f1: Configure EC lifetime and renew it on eligible visits (DEC-13)
PR #1659 at 7b1d4a7: Verify geo consent paths on Axum and Fastly
PR #1660 at 64a1baa: Retry an after-response write that loses its CAS
PR #1667 at 1359722: Present a client certificate on auction providers that set mtls
PR #1709 at bc43a3e: Keep the EC out of bid request IDs and gate user.id on EID consent
PR #1710 at dc728a1: Apply pull-sync consent checks to identify
PR #1713 at ffa7597: Apply consent rules to first-party click redirects
PR #1722 at 070e2b0: Use applicable GPP sections from the CMP instead of header sections

PR #1666 at 4720b0b (Verify identity gates and provider deadlines on Axum) arrives through #1659, and PR #1622 at c878e6e (Report CMP consent to the EC route and merge its answer into Prebid) arrives through #1722. Every other chain PR arrives through the tips above. The tree is the conflict-free union of these tips and carries no resolution of its own.
@aram356

aram356 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Merged #1614's /_ts/ local answers (48930c270) into this branch as a8748fb7d, on top of 07086f23e.

Trusted Server owns the /_ts/ namespace (#1740). A request for /_ts or any /_ts/ path that no route handles now gets a local 404 on Fastly, Axum, Cloudflare and Spin, and never reaches the publisher origin. The path is matched after percent-decoding. Paths outside the namespace, such as /_tsx or /articles/_ts/x, still go to the publisher origin, and every routed /_ts/ path answers as before.

This merge takes #1662's new head (1e8c9997f), which carries 48930c270 and nothing else new to this branch. It was clean.

Checks on this head: no conflict markers; cargo fmt --all -- --check passes; the merge adds exactly #1614's change to this branch's files; it merges cleanly with every lower head in its stack; clippy-fastly, clippy-axum, clippy-cloudflare and clippy-spin-native pass. rc/identity (e72407155) passed the full CI gate list with the change.

This branch has not been deployed

No deployments
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.

Forward the resolved client IP to the publisher origin

3 participants