From d3eedbf31f79a4b7c757c37b186b0a8e12268cb9 Mon Sep 17 00:00:00 2001 From: prk-Jr Date: Mon, 30 Nov 2026 19:59:56 +0530 Subject: [PATCH 1/4] Apply consent rules to first-party click redirects --- crates/trusted-server-adapter-axum/src/app.rs | 3 +- .../src/app.rs | 3 +- .../trusted-server-adapter-fastly/src/app.rs | 2 +- crates/trusted-server-adapter-spin/src/app.rs | 9 +- crates/trusted-server-core/src/consent/mod.rs | 6 + crates/trusted-server-core/src/proxy.rs | 202 ++++++++++++++---- 6 files changed, 181 insertions(+), 44 deletions(-) diff --git a/crates/trusted-server-adapter-axum/src/app.rs b/crates/trusted-server-adapter-axum/src/app.rs index 0b1858e208..a1ea44d478 100644 --- a/crates/trusted-server-adapter-axum/src/app.rs +++ b/crates/trusted-server-adapter-axum/src/app.rs @@ -549,7 +549,8 @@ fn named_route_handler( handle_first_party_proxy(&state.settings, &services, req).await } NamedRouteHandler::FirstPartyClick => { - handle_first_party_click(&state.settings, &services, req).await + let ec_context = build_ec_context(&state, &services, &req); + handle_first_party_click(&state.settings, &services, &ec_context, req).await } NamedRouteHandler::FirstPartySign => { handle_first_party_proxy_sign(&state.settings, &services, req).await diff --git a/crates/trusted-server-adapter-cloudflare/src/app.rs b/crates/trusted-server-adapter-cloudflare/src/app.rs index 668b025ccb..d114829a23 100644 --- a/crates/trusted-server-adapter-cloudflare/src/app.rs +++ b/crates/trusted-server-adapter-cloudflare/src/app.rs @@ -687,7 +687,8 @@ fn build_router(state: &Arc) -> RouterService { .get( "/first-party/click", make_handler(Arc::clone(&state), |s, services, req| async move { - handle_first_party_click(&s.settings, &services, req).await + let ec_context = build_ec_context(&s.settings, &services, &req); + handle_first_party_click(&s.settings, &services, &ec_context, req).await }), ) .get( diff --git a/crates/trusted-server-adapter-fastly/src/app.rs b/crates/trusted-server-adapter-fastly/src/app.rs index 69675e2669..390dffed84 100644 --- a/crates/trusted-server-adapter-fastly/src/app.rs +++ b/crates/trusted-server-adapter-fastly/src/app.rs @@ -724,7 +724,7 @@ async fn run_named_route( handle_first_party_proxy(&state.settings, services, req).await } NamedRouteHandler::FirstPartyClick => { - handle_first_party_click(&state.settings, services, req).await + handle_first_party_click(&state.settings, services, &ec.ec_context, req).await } NamedRouteHandler::FirstPartySign => { handle_first_party_proxy_sign(&state.settings, services, req).await diff --git a/crates/trusted-server-adapter-spin/src/app.rs b/crates/trusted-server-adapter-spin/src/app.rs index 9edce69fa3..c04da44d9b 100644 --- a/crates/trusted-server-adapter-spin/src/app.rs +++ b/crates/trusted-server-adapter-spin/src/app.rs @@ -753,9 +753,12 @@ fn build_router(state: &Arc) -> RouterService { async move { let services = s.services_for_request(&ctx); let req = ctx.into_request(); - Ok(handle_first_party_click(&s.settings, &services, req) - .await - .unwrap_or_else(|e| http_error(&e))) + let ec_context = build_ec_context(&s.settings, &services, &req); + Ok( + handle_first_party_click(&s.settings, &services, &ec_context, req) + .await + .unwrap_or_else(|e| http_error(&e)), + ) } }; diff --git a/crates/trusted-server-core/src/consent/mod.rs b/crates/trusted-server-core/src/consent/mod.rs index 76aa6ad859..e47baddda8 100644 --- a/crates/trusted-server-core/src/consent/mod.rs +++ b/crates/trusted-server-core/src/consent/mod.rs @@ -499,6 +499,12 @@ pub(crate) fn allows_eid_persistence(ctx: &ConsentContext) -> bool { } } +/// Decide whether current-request consent permits creative proxy EC disclosure. +#[must_use] +pub(crate) fn allows_proxy_ec_disclosure(ctx: &ConsentContext) -> bool { + !ctx.expired && !ctx.gpc && allows_ec_creation(ctx) && allows_eid_persistence(ctx) +} + // --------------------------------------------------------------------------- // EC consent gating // --------------------------------------------------------------------------- diff --git a/crates/trusted-server-core/src/proxy.rs b/crates/trusted-server-core/src/proxy.rs index fcbcafbc76..e9b1553bb5 100644 --- a/crates/trusted-server-core/src/proxy.rs +++ b/crates/trusted-server-core/src/proxy.rs @@ -16,11 +16,13 @@ use crate::cache_policy::{ apply_no_store_private_to_headers, cache_control_headers_are_private_or_no_store, remove_edge_cache_headers, }; +use crate::consent::allows_proxy_ec_disclosure; use crate::constants::{ HEADER_ACCEPT, HEADER_ACCEPT_ENCODING, HEADER_ACCEPT_LANGUAGE, HEADER_REFERER, HEADER_USER_AGENT, HEADER_X_FORWARDED_FOR, }; use crate::creative::{CreativeCssProcessor, CreativeHtmlProcessor, first_party_url}; +use crate::ec::{EcContext, log_id}; use crate::edge_cookie::get_ec_id; use crate::error::TrustedServerError; use crate::platform::{ @@ -1618,7 +1620,9 @@ pub async fn handle_first_party_proxy( /// Accepts the same parameters as the proxy scheme, but instead of proxying the /// content, it validates the URL and issues a 302 redirect to the reconstructed /// target URL. This avoids parsing/downloading the content and lets the browser -/// navigate directly to the destination under first-party control. +/// navigate directly to the destination under first-party control. The request +/// consent context gates EC disclosure; denied consent leaves the validated +/// target unchanged. /// /// # Errors /// @@ -1626,12 +1630,13 @@ pub async fn handle_first_party_proxy( pub async fn handle_first_party_click( settings: &Settings, _services: &RuntimeServices, + ec: &EcContext, req: Request, ) -> Result, Report> { let SignedTarget { target_url: full_for_token, - tsurl, had_params, + .. } = reconstruct_and_validate_signed_target(settings, &req.uri().to_string())?; let ec_id = match get_ec_id(&req) { @@ -1643,12 +1648,14 @@ pub async fn handle_first_party_click( }; let mut redirect_target = full_for_token.clone(); - if let Some(ref ec_id_value) = ec_id { + if allows_proxy_ec_disclosure(ec.consent()) + && let Some(ref ec_id_value) = ec_id + { match url::Url::parse(&redirect_target) { Ok(mut url) => { upsert_ec_query_param(&mut url, ec_id_value); redirect_target = url.to_string(); - log::debug!("forwarding EC ID to target url {}", redirect_target); + log::debug!("forwards EC ID to click target: {}", log_id(ec_id_value)); } Err(e) => { log::warn!("failed to parse target url for EC ID forwarding: {:?}", e); @@ -1656,25 +1663,10 @@ pub async fn handle_first_party_click( } } - // Log click metadata for observability - let ua = req - .headers() - .get(HEADER_USER_AGENT) - .and_then(|h| h.to_str().ok()) - .unwrap_or(""); - let referer = req - .headers() - .get(HEADER_REFERER) - .and_then(|h| h.to_str().ok()) - .unwrap_or(""); log::info!( - "redirect tsurl={} params_present={} target={} referer={} ua={} ec_id={}", - tsurl, + "redirect params_present={} ec_id={}", had_params, - redirect_target, - referer, - ua, - ec_id.as_deref().unwrap_or("") + ec_id.as_deref().map(log_id).unwrap_or_default() ); // 302 redirect to target URL @@ -2109,7 +2101,6 @@ pub async fn handle_first_party_proxy_rebuild( #[derive(Debug)] struct SignedTarget { target_url: String, - tsurl: String, had_params: bool, } @@ -2158,8 +2149,8 @@ fn parse_request_target(req_url: &str) -> Result = - handle_first_party_click(&settings, &noop_services(), req) + handle_first_party_click(&settings, &noop_services(), &EcContext::default(), req) .await .expect_err("expected error"); assert_eq!(err.current_context().status_code(), StatusCode::BAD_GATEWAY); @@ -3173,9 +3166,10 @@ mod tests { sig ), ); - let resp = handle_first_party_click(&settings, &noop_services(), req) - .await - .expect("should redirect"); + let resp = + handle_first_party_click(&settings, &noop_services(), &EcContext::default(), req) + .await + .expect("should redirect"); assert_eq!(resp.status(), StatusCode::FOUND); let loc = resp .headers() @@ -3208,7 +3202,14 @@ mod tests { HeaderValue::from_static("ec-123"), ); - let resp = handle_first_party_click(&settings, &noop_services(), req) + let ec = EcContext::new_for_test( + None, + crate::consent::ConsentContext { + jurisdiction: crate::consent::jurisdiction::Jurisdiction::NonRegulated, + ..crate::consent::ConsentContext::default() + }, + ); + let resp = handle_first_party_click(&settings, &noop_services(), &ec, req) .await .expect("should redirect"); @@ -3228,6 +3229,131 @@ mod tests { }); } + fn click_tc_string(purpose_four: bool) -> String { + let mut bytes = [0_u8; 29]; + bytes[0] = 2 << 2; + // Grant all purposes except Purpose 4 in the refusal control. + bytes[19..22].fill(0xff); + if !purpose_four { + bytes[19] &= !(1 << 4); + } + URL_SAFE_NO_PAD.encode(bytes) + } + + async fn click_with_consent( + cookie: &str, + gpc: bool, + geo: &GeoInfo, + target: &str, + ) -> Response { + let mut settings = create_test_settings(); + // Synthetic TC strings use a fixed epoch so these tests do not age out. + settings.consent.check_expiration = false; + let signed = creative::build_click_url( + &settings, + target, + &settings.publisher.effective_public_origin(), + ); + let mut req = build_http_request(Method::GET, signed); + req.headers_mut().insert( + header::COOKIE, + HeaderValue::from_str(&format!("ts-ec=fictional-click-ec-1234567890; {cookie}")) + .expect("should build consent cookie"), + ); + if gpc { + req.headers_mut() + .insert("sec-gpc", HeaderValue::from_static("1")); + } + let services = noop_services(); + let ec_context = + EcContext::read_from_request_with_geo(&settings, &req, &services, Some(geo)) + .expect("should read click consent"); + if cookie.starts_with("euconsent-v2=") { + assert!( + ec_context.consent().tcf.is_some(), + "should decode the TC cookie before exercising the click handler" + ); + } + handle_first_party_click(&settings, &services, &ec_context, req) + .await + .expect("should redirect signed click") + } + + fn click_geo(country: &str, region: Option<&str>) -> GeoInfo { + GeoInfo { + country: country.to_owned(), + region: region.map(str::to_owned), + city: "Fictional city".to_owned(), + continent: "Fictional continent".to_owned(), + latitude: 0.0, + longitude: 0.0, + metro_code: 0, + asn: None, + } + } + + #[test] + fn click_consent_purpose_four_controls_ec_disclosure() { + futures::executor::block_on(async { + let target = "https://example.com/landing?campaign=fake"; + for purpose_four in [false, true] { + let cookie = format!("euconsent-v2={}", click_tc_string(purpose_four)); + let response = + click_with_consent(&cookie, false, &click_geo("DE", None), target).await; + assert_eq!( + response.status(), + StatusCode::FOUND, + "should redirect in both consent states" + ); + let location = + response_header(&response, header::LOCATION).expect("should return Location"); + if purpose_four { + let parsed = url::Url::parse(location).expect("should parse Location"); + assert!( + parsed.query_pairs().any(|(key, value)| key == "ts-ec" + && value == "fictional-click-ec-1234567890"), + "should disclose EC with full consent" + ); + } else { + assert_eq!( + location, target, + "should preserve target exactly when Purpose 4 is refused" + ); + } + } + }); + } + + #[test] + fn click_consent_refusal_preserves_existing_signed_query() { + futures::executor::block_on(async { + let target = "https://example.com/landing?campaign=fake&ts-ec=signed-example-value"; + let cookie = format!("euconsent-v2={}", click_tc_string(false)); + let response = click_with_consent(&cookie, false, &click_geo("DE", None), target).await; + assert_eq!( + response_header(&response, header::LOCATION), + Some(target), + "should preserve the signed target without replacing its existing query" + ); + }); + } + + #[test] + fn click_consent_us_opt_out_and_gpc_withhold_ec() { + futures::executor::block_on(async { + let target = "https://example.com/landing?campaign=fake"; + for (cookie, gpc) in [("us_privacy=1YYY", false), ("us_privacy=1YNN", true)] { + let response = + click_with_consent(cookie, gpc, &click_geo("US", Some("CA")), target).await; + assert_eq!( + response_header(&response, header::LOCATION), + Some(target), + "should leave the target unchanged after a US opt-out or GPC" + ); + } + }); + } + #[test] fn proxy_rebuild_adds_and_removes_params() { futures::executor::block_on(async { @@ -3490,9 +3616,10 @@ mod tests { .body(EdgeBody::empty()) .expect("should build origin-form click request"); - let resp = handle_first_party_click(&settings, &noop_services(), req) - .await - .expect("origin-form click should succeed"); + let resp = + handle_first_party_click(&settings, &noop_services(), &EcContext::default(), req) + .await + .expect("origin-form click should succeed"); assert_eq!( resp.status(), @@ -3829,7 +3956,6 @@ mod tests { ); let st = reconstruct_and_validate_signed_target(&settings, &first_party) .expect("reconstruct ok"); - assert_eq!(st.tsurl, "https://cdn.example/asset.js"); assert!(st.had_params); assert_eq!(st.target_url, canonical_clear_url(clear)); } @@ -3845,7 +3971,6 @@ mod tests { ); let st = reconstruct_and_validate_signed_target(&settings, &first_party) .expect("reconstruct ok"); - assert_eq!(st.tsurl, clear); assert!(!st.had_params); assert_eq!(st.target_url, clear); } @@ -3904,9 +4029,10 @@ mod tests { &settings.publisher.effective_public_origin(), ); let req = build_http_request(Method::GET, first_party); - let resp = handle_first_party_click(&settings, &noop_services(), req) - .await - .expect("should redirect"); + let resp = + handle_first_party_click(&settings, &noop_services(), &EcContext::default(), req) + .await + .expect("should redirect"); assert_eq!(resp.status(), StatusCode::FOUND); let cc = response_header(&resp, header::CACHE_CONTROL).unwrap_or(""); assert!(cc.contains("no-store")); From 57f2772ee95577e99192d6a0e6d75d8fac1986bb Mon Sep 17 00:00:00 2001 From: prk-Jr Date: Tue, 1 Dec 2026 16:36:42 +0530 Subject: [PATCH 2/4] Document consent checks for click redirects --- docs/guide/api-reference.md | 9 ++++--- docs/guide/first-party-proxy.md | 42 ++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/docs/guide/api-reference.md b/docs/guide/api-reference.md index a84707f492..81c127f282 100644 --- a/docs/guide/api-reference.md +++ b/docs/guide/api-reference.md @@ -499,13 +499,16 @@ Click tracking redirect endpoint. **Response:** - **Status:** `302 Found` -- **Location:** Reconstructed target URL with EC ID injected +- **Location:** Reconstructed target URL, with an available EC ID injected only + when current-request consent permits disclosure **Behavior:** - Validates `tstoken` against reconstructed URL -- Injects `ts-ec` query parameter -- Logs click metadata (tsurl, referer, user agent) +- Injects `ts-ec` only when current-request consent permits both EC use and EID + disclosure; denial preserves the validated target and its existing query +- Logs parameter presence and a redacted EC ID, omitting target URLs, referer + and user agent - Does not proxy content (redirect only) **Contract:** Auth: signed query token. A valid request returns `302` with diff --git a/docs/guide/first-party-proxy.md b/docs/guide/first-party-proxy.md index 4e94b7ef41..cece8470fb 100644 --- a/docs/guide/first-party-proxy.md +++ b/docs/guide/first-party-proxy.md @@ -112,14 +112,10 @@ GET /first-party/click?tsurl=https://advertiser.example.com/landing&tstoken=sign **Behavior**: 1. **Validates** the `tstoken` signature -2. **Appends** `ts-ec` parameter to target URL +2. **Appends** an available `ts-ec` only when current-request consent permits disclosure 3. **Issues** 302 redirect to target (browser navigates directly) -4. **Logs** click metadata: - - Target URL base (`tsurl`) - - Whether parameters were present - - Full reconstructed URL - - Referer, User-Agent - - EC ID (if available) +4. **Logs** whether parameters were present and a redacted EC ID (if available), + without target URLs, Referer or User-Agent **Example**: @@ -136,7 +132,7 @@ Click URL in creative: ``` -User clicks → Server responds: +With an existing EC and current-request disclosure consent, the server responds: ``` HTTP/1.1 302 Found @@ -426,7 +422,8 @@ This ensures downstream endpoints receive consistent IDs even through redirect c ### Click ID Forwarding -Click redirects also forward EC IDs: +Click redirects forward an existing EC ID when current-request consent permits +disclosure: ```html ``` -User clicks → redirect includes ID: +With disclosure consent, the redirect includes the ID: ``` 302 Found @@ -442,12 +439,21 @@ Location: https://advertiser.example.com?ts-ec=user123 ``` ::: tip Forwarding Conditions -EC IDs are only forwarded when: - -1. Consent rules permitted the EC ID to be issued (issuance is gated per jurisdiction) -2. ID exists in request (header/cookie) -3. Integration hasn't disabled forwarding (`forward_ec_id: false`) - ::: +Click redirects forward EC IDs only when an ID exists in the request and the +current request permits both EC use and EID disclosure. TCF requires Purposes 1 +and 4 where applicable; expired consent, GPC, applicable US opt-outs and unknown +jurisdiction block disclosure. Consent at the time the EC was issued is not +sufficient. + +US opt-outs here follow the detected jurisdiction. Country-only US geography +currently selects `NonRegulated`, so this check alone does not enforce those +opt-outs when the state is unresolved, including Cloudflare's country-only +geolocation. The strict US fallback is a separate jurisdiction-policy fix. + +When disclosure is denied, the redirect preserves the validated signed target +and its existing query without appending an EC ID. Content-proxy calls have a +separate forwarding control, `forward_ec_id: false`. +::: ## Configuration @@ -734,9 +740,11 @@ Proxy requests emit detailed logs: ``` proxy: origin response status=200 ct=text/html cl=1234 accept=text/html url=https://... proxy: likely pixel detected size=43 url=https://tracker.example.com/p.gif -click: tsurl=https://advertiser.example.com had_params=true target=... referer=... ua=... tsid=... +redirect params_present=true ec_id=aaaaaaaa… ``` +The click redirect log omits target URLs, Referer, User-Agent and the full EC ID. + ### Diagnostic Headers Add custom headers for debugging: From cae7801b17b2011a4f28484a6541a1cabe4f5dd7 Mon Sep 17 00:00:00 2001 From: Aram Grigoryan <132480+aram356@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:39:11 -0800 Subject: [PATCH 3/4] Point click disclosure docs at the consent model The click forwarding tip said country-only US geography selects NonRegulated and that a strict US fallback was a separate fix. Jurisdiction detection belongs to #1718, which makes a missing or unreadable US region strict, so the sentence would go stale once both land. The tip now says US opt-outs follow the same jurisdiction and consent rules as EC creation and links the Consent Model section instead of describing detection. --- docs/guide/first-party-proxy.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/guide/first-party-proxy.md b/docs/guide/first-party-proxy.md index 82f90470c4..fdcafaa9c6 100644 --- a/docs/guide/first-party-proxy.md +++ b/docs/guide/first-party-proxy.md @@ -489,10 +489,8 @@ and 4 where applicable; expired consent, GPC, applicable US opt-outs and unknown jurisdiction block disclosure. Consent at the time the EC was issued is not sufficient. -US opt-outs here follow the detected jurisdiction. Country-only US geography -currently selects `NonRegulated`, so this check alone does not enforce those -opt-outs when the state is unresolved, including Cloudflare's country-only -geolocation. The strict US fallback is a separate jurisdiction-policy fix. +US opt-outs here apply under the same jurisdiction and consent rules as EC +creation; see the [Consent Model](/guide/edge-cookies#consent-model). When disclosure is denied, the redirect preserves the validated signed target and its existing query without appending an EC ID. Creative fetches follow the From 91ff4240a145cff077f940a6f7f3185e71894d2b Mon Sep 17 00:00:00 2001 From: prk-Jr Date: Fri, 4 Dec 2026 15:47:44 +0530 Subject: [PATCH 4/4] Cover click consent disclosure at the handler --- crates/trusted-server-core/src/consent/mod.rs | 6 +- crates/trusted-server-core/src/proxy.rs | 105 ++++++++++++++++++ docs/guide/creative-processing.md | 10 +- docs/guide/first-party-proxy.md | 6 +- 4 files changed, 120 insertions(+), 7 deletions(-) diff --git a/crates/trusted-server-core/src/consent/mod.rs b/crates/trusted-server-core/src/consent/mod.rs index d1a917245f..5993546b69 100644 --- a/crates/trusted-server-core/src/consent/mod.rs +++ b/crates/trusted-server-core/src/consent/mod.rs @@ -517,7 +517,11 @@ pub(crate) fn allows_eid_persistence(ctx: &ConsentContext) -> bool { } } -/// Decide whether current-request consent permits creative proxy EC disclosure. +/// Decide whether current-request consent permits disclosing the EC ID to a third party. +/// +/// Used by creative proxy fetches and first-party click redirects. Requires +/// unexpired consent, no GPC signal in any jurisdiction, EC creation consent +/// and EID persistence consent, including TCF Purposes 1 and 4 where applicable. #[must_use] pub(crate) fn allows_proxy_ec_disclosure(ctx: &ConsentContext) -> bool { !ctx.expired && !ctx.gpc && allows_ec_creation(ctx) && allows_eid_persistence(ctx) diff --git a/crates/trusted-server-core/src/proxy.rs b/crates/trusted-server-core/src/proxy.rs index 0c7aad7361..3e83386fcb 100644 --- a/crates/trusted-server-core/src/proxy.rs +++ b/crates/trusted-server-core/src/proxy.rs @@ -2346,9 +2346,12 @@ mod tests { reconstruct_and_validate_signed_target, }; use crate::cache_policy::{CachePolicy, EdgeCacheHeader}; + use crate::consent::ConsentContext; + use crate::consent::jurisdiction::Jurisdiction; use crate::constants::{HEADER_ACCEPT, HEADER_X_FORWARDED_FOR}; use crate::creative; use crate::ec::EcContext; + use crate::edge_cookie::get_ec_id; use crate::error::{IntoHttpResponse, TrustedServerError}; use crate::outbound::{ BUFFERED_TIMEOUT, DEFAULT_BUFFERED_RESPONSE_BYTES, REDIRECT_CHAIN_DEADLINE, @@ -3852,6 +3855,108 @@ mod tests { }); } + #[test] + fn click_disclosure_applies_current_context_with_an_available_ec() { + futures::executor::block_on(async { + // Arrange: every case carries an EC; only consent differs. + let settings = create_test_settings(); + let target = "https://example.com/landing?campaign=fake"; + let ec_id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.FAKE01"; + let allowed = ConsentContext { + jurisdiction: Jurisdiction::NonRegulated, + ..ConsentContext::default() + }; + for (name, consent, disclose) in [ + ("allowed", allowed.clone(), true), + ("unknown jurisdiction", ConsentContext::default(), false), + ( + "expired consent", + ConsentContext { + expired: true, + ..allowed.clone() + }, + false, + ), + ( + "non-US GPC", + ConsentContext { + gpc: true, + ..allowed.clone() + }, + false, + ), + ] { + let signed = creative::build_click_url( + &settings, + target, + &settings.publisher.effective_public_origin(), + ); + let mut request = build_http_request(Method::GET, signed); + request.headers_mut().insert( + header::COOKIE, + HeaderValue::from_str(&format!("ts-ec={ec_id}")) + .expect("should build EC cookie"), + ); + assert_eq!( + get_ec_id(&request) + .expect("should read request EC") + .as_deref(), + Some(ec_id), + "should make an EC available to the click handler for {name}" + ); + let context = EcContext::new_for_test(Some(ec_id.to_owned()), consent); + + // Act + let response = + handle_first_party_click(&settings, &noop_services(), &context, request) + .await + .expect("should redirect a signed click"); + + // Assert + assert_eq!( + response.status(), + StatusCode::FOUND, + "should preserve navigation for {name}" + ); + let expected = if disclose { + format!("{target}&ts-ec={ec_id}") + } else { + target.to_owned() + }; + assert_eq!( + response_header(&response, header::LOCATION), + Some(expected.as_str()), + "should apply current-request disclosure consent for {name}" + ); + } + }); + } + + #[test] + fn click_decoded_non_us_gpc_withholds_ec() { + futures::executor::block_on(async { + let target = "https://example.com/landing?campaign=fake"; + let cookie = format!("euconsent-v2={}", click_tc_string(true)); + for gpc in [false, true] { + let response = + click_with_consent(&cookie, gpc, &click_geo("DE", None), target).await; + let location = + response_header(&response, header::LOCATION).expect("should return Location"); + if gpc { + assert_eq!( + location, target, + "should withhold an available EC for GPC outside the US" + ); + } else { + assert!( + location.ends_with("&ts-ec=fictional-click-ec-1234567890"), + "should deliver the EC for the otherwise identical decoded consent" + ); + } + } + }); + } + #[test] fn click_consent_refusal_preserves_existing_signed_query() { futures::executor::block_on(async { diff --git a/docs/guide/creative-processing.md b/docs/guide/creative-processing.md index e63af6e8d5..11c3714919 100644 --- a/docs/guide/creative-processing.md +++ b/docs/guide/creative-processing.md @@ -137,16 +137,18 @@ guard installs its listeners but never acts, because no link carries `data-tsclick`. Both switches also decide where the visitor's EC ID goes. `/first-party/click` -retains its existing behavior: it appends the request's `ts-ec` value to the -landing URL and logs the click with it. The `/first-party/proxy` asset path instead +appends an available request EC ID to the landing URL only when current-request +consent permits EC use and EID disclosure. Its logs use a redacted EC prefix and +omit the target URL, Referer and User-Agent. The `/first-party/proxy` asset path instead uses the [creative disclosure policy](/guide/first-party-proxy#ec-id-disclosure): only a valid canonical cookie EC, affirmative current-request consent and an explicit HTTPS recipient grant permit disclosure. By default, proxied assets receive no EC. With `rewrite_clicks = false`, creative links stop forwarding EC through click rewriting; with `rewrite_clicks = true` and `rewrite_creatives = false`, landing pages can receive it while assets load direct. -The rewrite switches are not consent controls; the proxy policy evaluates consent -again at disclosure, while the click contract remains separate. +The rewrite switches are not consent controls. Both disclosure paths evaluate +current-request consent; creative proxy fetches also require the endpoint grants +above. The same switches decide which creative endpoints answer. `/first-party/proxy` and `/first-party/sign` answer only while diff --git a/docs/guide/first-party-proxy.md b/docs/guide/first-party-proxy.md index eb2a745a89..0d1faed4dc 100644 --- a/docs/guide/first-party-proxy.md +++ b/docs/guide/first-party-proxy.md @@ -510,8 +510,10 @@ US opt-outs here apply under the same jurisdiction and consent rules as EC creation; see the [Consent Model](/guide/edge-cookies#consent-model). When disclosure is denied, the redirect preserves the validated signed target -and its existing query without appending an EC ID. Creative fetches follow the -endpoint grants above instead. +and its existing query without appending an EC ID. A `ts-ec` value already +embedded in that signed target is preserved too; this click gate controls +insertion of the request's EC, not arbitrary tracking parameters supplied by the +creative. Creative fetches follow the endpoint grants above instead. ::: ## Configuration