Skip to content

Apply consent rules to first-party click redirects - #1713

Open
prk-Jr wants to merge 2 commits into
mainfrom
fix/1693-click-redirect-disclosure
Open

prk-Jr wants to merge 2 commits into
mainfrom
fix/1693-click-redirect-disclosure

Conversation

@prk-Jr

@prk-Jr prk-Jr commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Apply current-request consent to first-party click EC disclosure, preserving signed redirects when disclosure is denied.
  • Redact EC values and remove URL-bearing click metadata from logs.
  • Base and target: main (db36dc0e). Both branches are affected; this keeps the fix independent of rc/identity's broader identity changes. Main lacks the disclosure helper, so this adds the same small predicate already on RC.

Changes

File Change
crates/trusted-server-core/src/consent/mod.rs Add the RC-equivalent disclosure predicate using existing consent functions.
crates/trusted-server-core/src/proxy.rs Accept request EC context, gate EC insertion, redact logs, and add consent/preservation regressions.
crates/trusted-server-adapter-fastly/src/app.rs Pass the existing request EC context into click handling.
crates/trusted-server-adapter-axum/src/app.rs Build the geo-aware request EC context for clicks.
crates/trusted-server-adapter-cloudflare/src/app.rs Build the geo-aware request EC context for clicks.
crates/trusted-server-adapter-spin/src/app.rs Build the geo-aware request EC context for clicks.

Previously clicks appended an available cookie/header EC regardless of consent and logged the full EC/target. Now insertion requires disclosure consent; denial leaves the validated target unchanged, including an existing signed query. Signed-target, HMAC, and expiry validation still run before disclosure. Info/debug click logs redact the EC and omit target URLs.

Closes

Closes #1693

Related jurisdiction policy

This patch applies the existing disclosure predicate; it does not change jurisdiction detection. Country-only US geography still selects NonRegulated, including Cloudflare's country-only geolocation, so US opt-outs remain unenforced on that path until the separate #1705 fix in #1718. Purpose 4 refusal and GPC remain gated by this patch. The guide and API reference now describe current-request consent, denied-target preservation and redacted click logging.

Spec

Not a feature; this fixes an existing consent-disclosure bug.

Test plan

The following evidence was collected during implementation, before publication. No gates or tests were rerun for commit/PR creation; the installed URL-host commit hook was deferred to CI with a command-scoped override. Full required gates remain for PR CI. Tools used for prior scoped checks: Rust 1.98.1, Node 24.20.0, Viceroy 0.22.0.

  • Fail-first consent regressions: Purpose 4 refusal and California opt-out/GPC exposed unwanted ts-ec; both pass with the fix. Full consent retains it.
  • Core proxy suite: 156 passed, including signing/rebuild, tampering, expiry, and consent/preservation cases.
  • Adapter tests: Axum first-party routes 5; Spin first-party routes 8; Cloudflare route registration 1; Fastly named-route dispatch 2 under Viceroy. Core click tests under Viceroy: 7 passed.
  • Scoped clippy: core/Axum native; Cloudflare/Spin native; core/Fastly WASI; Cloudflare WASM; Spin WASI, with supported features and warnings denied.
  • Formatting and diff whitespace checks.
  • Local Axum curl and actual info-log sink checks, detailed below.
  • Full required PR CI gates; awaiting hosted results. Current-revision hosted checks complete.

Pre-publication independent local review: READY TO REQUEST REVIEW for the scoped implementation checks, with zero blocking code findings and zero outstanding optional findings. One private-helper documentation mismatch was corrected and rechecked. The readiness decision uses source inspection and scoped test/lint evidence; it is separate from hosted CI and deployed-runtime qualification.

Local runtime verification: VERIFIED for the real Axum application router/server over TCP, using fictional settings and fixed Germany geo through the existing service-injection API. Default dev geo is unavailable and therefore fails disclosure closed; this fixture explicitly exercises both consent branches. Curl observed:

Purpose 4 refused: 302
Location: https://example.com/landing?campaign=fake

Full consent: 302
Location: https://example.com/landing?campaign=fake&ts-ec=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.FAKE01

Full consent plus GPC: 302
Location: https://example.com/landing?campaign=fake

Repeated full consent also retained the EC. Invalid signatures returned 403 under both consent outcomes. The actual info log sink emitted four redacted records, with no full EC or target URL:

INFO [trusted_server_core::proxy] redirect params_present=true ec_id=aaaaaaaa…

No browser or deployed runtime was exercised. The owned local server was stopped after verification.

RC trial: a commit-free three-way integration of the final patch into origin/rc/identity (c3e33666), with main confirmed as its ancestor, found conflicts in crates/trusted-server-adapter-spin/src/app.rs (fallible request/service setup) and crates/trusted-server-core/src/proxy.rs (production/test imports). RC's Axum patch applies textually but needs state.identity.read_request / ec.context in place of main's absent-on-RC build_ec_context. The consent helper applies cleanly and is identical. Conflicts were recorded; the disposable trial worktree was restored and removed. No merge commit was created or pushed.

Checklist

  • Bug fix; feature spec requirement does not apply.
  • Changes follow AGENTS.md conventions.
  • No new production unwrap() or logging via println!.
  • New behavior has regression tests.
  • Only fictional test values; no secrets or credentials committed.
  • Operator configuration, environment files, and editor configuration untouched.

@prk-Jr prk-Jr self-assigned this Nov 30, 2026
@prk-Jr
prk-Jr marked this pull request as ready for review December 1, 2026 11:26

@ChristianPavilonis ChristianPavilonis 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.

Reviewed 57f2772ee against main (db36dc0ec).

Approving so I'm not blocking, on the understanding that you'll handle the comments before merging. The click gate itself looks right.

R1 · Nonblocking: docs/guide/creative-processing.md still describes the old click behavior. This one sits outside the diff, so it's here instead of inline. Lines 139-146 still say /first-party/click "appends the request's ts-ec value to the landing URL and logs the click with it" and that "both endpoints forward whatever EC ID the request carries". After this PR, click only appends ts-ec when current-request consent allows it and logs a redacted prefix, while /first-party/proxy still forwards unconditionally. Please reword that paragraph and keep "neither switch is a consent control". The dated design spec with the same wording can stay as it is.

Questions:

  • When consent is denied, a ts-ec the creative already signed into the target still goes through (click_consent_refusal_preserves_existing_signed_query locks that in). Stripping it wouldn't affect signature validation, because the target is rewritten after validation. Is keeping it intended?
  • The info log also drops tsurl, Referer and User-Agent. The issue only asked to redact the EC and drop the EC-bearing target. Was losing the click destination in logs deliberate?

Checks: cargo test -p trusted-server-core --lib -- click proxy_disclosure allows_eid (25 passed), native clippy on core, cargo fmt --check. I relied on CI for the adapter and wasm targets.

}

#[test]
fn click_consent_purpose_four_controls_ec_disclosure() {

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.

R2 · P3: the expired, non-US GPC and unknown-jurisdiction denials have no tests. allows_proxy_ec_disclosure is !ctx.expired && !ctx.gpc && allows_ec_creation(ctx) && allows_eid_persistence(ctx), but none of these click tests can fail on the first two terms. In a US state, allows_ec_creation already rejects GPC. The shared helper sets check_expiration = false, so expired is never true. The EcContext::default() tests carry no EC, so the fail-closed path for missing geo isn't covered either. Dropping !ctx.expired && !ctx.gpc while resolving the RC conflicts in proxy.rs would keep every test green.

The simplest fix is to port RC's proxy_disclosure_requires_current_consent_beyond_creation table test into consent/mod.rs unchanged; TcfBuilder already exists on main. That also keeps the two branches identical. Alternatively, add click cases for GPC under DE or non-regulated, an expired TC string, and an EC with an unknown jurisdiction.

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.

Apply the proxy disclosure rule to first-party click redirects

2 participants