Honor publisher Host override and bypass IO for SVG assets#787
Honor publisher Host override and bypass IO for SVG assets#787ChristianPavilonis wants to merge 6 commits into
Conversation
|
Follow-up after testing the deployed branch: the first patch deployed as |
aram356
left a comment
There was a problem hiding this comment.
Summary
Correct, well-tested, and CI-green. The publisher Host-override is implemented through the right mechanism — origin_host_header_override → PlatformBackendSpec.host_header_override → BackendConfig::ensure() → Backend::override_host(...), which the Fastly SDK documents as forcing the outbound Host. The SVG Image Optimizer bypass is a genuine correctness fix with a focused regression test. No blocking issues; two non-blocking suggestions (inline) to make intent explicit and add the unit-testable half of the override coverage.
Non-blocking
♻️ refactor
- Document the Host
set_headernormalization — it's defensive only; the wire Host is forced by the backend'soverride_host, and it applies to every backend, not just the publisher origin. (crates/trusted-server-adapter-fastly/src/platform.rs:312— suggestion inline) - Add request-side override coverage — assert a configured
origin_host_header_overridereaches the outbound request's Host header viaStubHttpClient. (crates/trusted-server-core/src/publisher.rs— suggested test inline)
👍 praise
- SVG bypass checks both incoming and rewritten paths with a targeted regression test. (
crates/trusted-server-core/src/proxy.rs) - Backend name encodes the override (
_oh_suffix) so different overrides don't collide or get poisoned by first-registration-wins, and the value is validated against control characters. (crates/trusted-server-core/src/backend.rs)
⛏ nitpick
- History includes "Load Prebid split bundle synchronously" and its immediate revert (net-zero in the diff) — consider squashing on merge.
CI Status
- fmt: PASS
- clippy: PASS
- rust tests: PASS
- js tests: PASS
- integration / browser tests: PASS
| scheme: origin_scheme.clone(), | ||
| host: origin_host_without_port.to_string(), | ||
| port: parsed_origin.port(), | ||
| host_header_override: settings.publisher.origin_host_header_override.clone(), |
There was a problem hiding this comment.
♻️ refactor — The override wiring is currently only covered indirectly (backend-name encoding). The request-side half is unit-testable with the existing StubHttpClient: assert that a configured origin_host_header_override reaches the outbound request's Host header. (The Fastly override_host forcing still needs manual verification — it only runs in the Fastly runtime.) Suggested test for the #[cfg(test)] mod tests block in this file:
#[tokio::test]
async fn publisher_request_sends_configured_host_header_override() {
let mut settings = create_test_settings();
settings.publisher.origin_host_header_override = Some("www.example.com".to_string());
let registry =
IntegrationRegistry::new(&settings).expect("should create integration registry");
let stub = Arc::new(StubHttpClient::new());
stub.push_response(200, b"origin response".to_vec());
let services = build_services_with_http_client(
Arc::clone(&stub) as Arc<dyn crate::platform::PlatformHttpClient>
);
let req = HttpRequest::builder()
.method(Method::GET)
.uri("https://publisher.example/page")
.header(header::HOST, "publisher.example")
.body(EdgeBody::empty())
.expect("should build request");
handle_publisher_request(&settings, ®istry, &services, req)
.await
.expect("should proxy publisher request");
let recorded_headers = stub.recorded_request_headers();
let outbound = recorded_headers
.first()
.expect("should record one outbound origin request");
let host_header = outbound
.iter()
.find(|(name, _)| name.eq_ignore_ascii_case("host"))
.map(|(_, value)| value.as_str());
assert_eq!(
host_header,
Some("www.example.com"),
"should send the configured origin host header override to the backend"
);
}Co-authored-by: Aram Grigoryan <132480+aram356@users.noreply.github.com>
Summary
override_hostwhenpublisher.origin_host_header_overrideis configured..svg/.svgz.Changes
crates/trusted-server-core/src/platform/types.rshost_header_overridetoPlatformBackendSpec.crates/trusted-server-core/src/publisher.rspublisher.origin_host_header_overridewhen registering the publisher origin backend.crates/trusted-server-adapter-fastly/src/platform.rsPlatformBackendSpec::host_header_overrideintoBackendConfig::host_header_override; adds override-aware backend name test.crates/trusted-server-core/src/integrations/mod.rscrates/trusted-server-core/src/integrations/datadome/protection.rscrates/trusted-server-core/src/proxy.rscrates/trusted-server-core/src/platform/test_support.rsCloses
Closes #786
Test plan
cargo test --workspacecargo clippy --workspace --all-targets --all-features -- -D warningscargo fmt --all -- --checkcd crates/js/lib && npx vitest runcd crates/js/lib && npm run formatcd docs && npm run formatcargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1Checklist
unwrap()in production code — useexpect("should ...")println!)