Skip to content

Apply strict US consent when the state is unresolved - #1718

Open
prk-Jr wants to merge 1 commit into
mainfrom
fix/1705-us-no-region-strict
Open

prk-Jr wants to merge 1 commit into
mainfrom
fix/1705-us-no-region-strict

Conversation

@prk-Jr

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

Copy link
Copy Markdown
Collaborator

Summary

  • Apply existing strict US consent rules when country is US and the state is absent or unreadable, closing the signal-free EC creation/GPC gap.
  • Preserve configured state matches, readable unlisted states and non-US policy; document the fallback and add fail-first adapter/policy regressions.
  • Keep the pseudo-state out of protocol fields and display it as US in logs.

Base/target: main (db36dc0e), where the shared detector lives. rc/identity is runtime/integration qualification only: its newer identity lifecycle is outside this fix. #1708's general refusal/all-states changes, adapter production changes and EdgeZero changes are excluded.

Changes

File Change
crates/trusted-server-core/src/consent/jurisdiction.rs Add strict country-only US fallback and log label; cover missing/malformed/listed/unlisted/non-US inputs and configured overrides.
crates/trusted-server-core/src/consent/mod.rs Test no-signal, grant, malformed GPP, US Privacy and GPC handling through the real pipeline.
crates/trusted-server-core/src/auction/openrtb/tests.rs Verify pseudo-state regs behavior and exact US Privacy/GPP/section-ID forwarding.
crates/trusted-server-adapter-axum/src/app.rs Test actual adapter context construction and generation denial/grant with supplied country-only US geo.
crates/trusted-server-adapter-cloudflare/src/app.rs Test actual Cloudflare header projection, context construction and generation denial/grant.
crates/trusted-server-adapter-fastly/src/app.rs Test actual Fastly context construction and generation denial/grant under Viceroy.
docs/guide/edge-cookies.md State the missing/unreadable US-region consent rule and preserved unlisted-state behavior.
docs/guide/gdpr-compliance.md Document strict US fallback without inventing GDPR applicability or a GPP section.

Closes

Closes #1705

Spec

Not a feature: focused bug fix. No new configuration or provider behavior.

Adapter behavior

Adapter Before After
Fastly US with absent or raw unreadable region falls to NonRegulated, allowing signal-free EC generation. US fallback denies signal-free generation; a valid US GPP non-opt-out grant permits generation. Existing country/region producer is unchanged.
Cloudflare cf-ipcountry: US supplies no region and selects NonRegulated. Real header projection selects strict US policy. Native adapter regression verifies denied generation and the valid-GPP generation control. Main's publisher route still lacks the EC mint/finalize lifecycle.
Axum Main's geo provider returns no location, retaining Unknown; injected country-only US selects NonRegulated. Default unavailable-geo behavior remains Unknown. With supplied US geo, actual adapter context construction selects strict US policy. Main's publisher lifecycle still cannot mint/finalize an EC cookie, including with a valid grant.
Spin NullGeo supplies neither country nor region, retaining Unknown. Unchanged. Shared US fallback applies if US geo is supplied; no geo source or new header trust is introduced.

Consumers checked

  • allows_ec_creation: matches the US variant, ignores payload; no signal denies, valid US GPP grant permits, explicit opt-outs deny.
  • has_explicit_ec_withdrawal: matches the variant; absence denies creation without asserting withdrawal.
  • GPC-to-US-Privacy synthesis: matches the variant and publisher defaults; no state lookup.
  • Auction admission: remains known non-GDPR; EC denial alone does not deny the auction.
  • Shared OpenRTB build_regs: standard/Prebid omit empty regs; US signals remain non-GDPR unless an actual EU signal applies. APS uses the applicability bit. The pseudo-state is never serialized.
  • Prebid forwarding subset: copies jurisdiction without interpreting its payload.
  • Legacy Prebid regs: forwards raw US Privacy/GPP and actual section IDs without a state lookup.
  • Test-only legacy APS regs and mock-adserver output: use applicability and raw signals, not state payload.
  • Consent/EC logs: display country-only policy as US, preserving labels such as US-CA.
  • Per-state lookups: only the initial configured privacy_states membership test; none downstream. GPP decoding aggregates US sections independently of geographic state.
  • On rc/identity, proxy EC disclosure delegates to the existing EC permission gate, so the fallback also tightens disclosure there.

Test plan

Hosted PR CI is green for c1c948d476 (merge 1ac9304 against db36dc0e): all 30 reported checks passed, including adapter tests, target-matched lint, docs/JS and integration/runtime suites. Local checks and scratch-RC runtime evidence below are separate. Live main ab5c24f73 merges cleanly; those runs did not execute that newer pairing.

  • Full Rust test/lint matrix — GitHub Actions.
  • JS build/tests/format and docs/Markdown format gates — GitHub Actions.
  • Remaining applicable CI gates — GitHub Actions.
  • Fail-first policy/adapter regressions and focused tests.
  • Target-matched clippy for touched crates, Rust format, diff whitespace, and two-guide formatting.
  • Actual RC Axum HTTP baseline/fixed comparison using managed local providers and persistent records.

Fail-first evidence: missing/unreadable US-region and logging assertions fail on the base; all three adapter regressions fail at NonRegulated versus UsState("US") before the correction.

Passing focused checks with Rust 1.98.1, Node 24.20.0 and Viceroy 0.22.0:

  • Core consent tests: 121 passed, covering missing/unreadable region, listed/unlisted regions, publisher overrides, non-US preservation, GPC, malformed/valid GPP and US Privacy.
  • OpenRTB consent matrix: passed, including exact GDPR/US Privacy/GPP/section-ID forwarding for the pseudo-state.
  • Core EC lifecycle group: 17 passed.
  • Country-only US regression: passed for Axum, Cloudflare native and Fastly/Viceroy. Each calls real adapter context construction and actual generation, with no-signal denial and __gpp=DBABLA~BVQqAAAAAgA.QA grant control. These are adapter-context/generation tests, not end-to-end cookie-finalization claims.
  • Core + Axum native clippy (--all-targets --all-features), Cloudflare native clippy (--all-targets), core + Fastly WASI clippy (--all-targets --all-features), and Cloudflare Worker WASM library clippy (--features cloudflare): passed with -D warnings.
  • Rust format, diff whitespace and formatting of the two changed guides: passed.

Representative test commands:

cargo +1.98.1 test --locked -p trusted-server-core --lib consent::
cargo +1.98.1 test --locked -p trusted-server-core --lib auction::openrtb::tests::consent_matrix
cargo +1.98.1 test --locked -p trusted-server-core --lib ec::tests::
cargo +1.98.1 test --locked -p trusted-server-adapter-axum -p trusted-server-adapter-cloudflare --lib country_only_us --no-fail-fast
cargo +1.98.1 test --locked -p trusted-server-adapter-fastly --target wasm32-wasip1 country_only_us

The full CI suite was intentionally not run locally; the hosted results above cover the reviewed revision.

rc/identity trial integration

A literal git merge --no-commit --no-ff of signed commit c1c948d476ac1cc76bceb1f997e32cc50b5078e1 into rc/identity at c3e33666, in a disposable scratch worktree, found conflicts in:

  • crates/trusted-server-adapter-axum/src/app.rs
  • crates/trusted-server-adapter-cloudflare/src/app.rs
  • crates/trusted-server-core/src/consent/jurisdiction.rs
  • crates/trusted-server-core/src/consent/mod.rs
  • docs/guide/edge-cookies.md

Axum/Cloudflare test-module insertions overlap RC startup tests; jurisdiction comments and its old no-region expectation overlap; consent-test imports overlap; the EC guide overlaps RC storage wording. Fastly tests, the OpenRTB matrix and GDPR guide applied textually cleanly. Integration also needs RC's newer GeoInfo fixture shape and adjustments to existing RC country-only/unreadable-region policy assertions and conformance expectations. Preserve the RC identity/storage flow and #1708's independent scope.

The literal merge confirmed the earlier uncommitted-patch preview: the same five conflicted files, with no new conflicts. The trial merge was aborted and the clean scratch worktree removed after preserving conflict evidence. No RC merge commit or RC push was made.

Independent review and runtime evidence

Independent local review found zero blocking code findings and zero optional findings. After runtime qualification confirmed that the reviewed source was unchanged, its readiness label is READY TO REQUEST REVIEW for the scoped main policy fix. That label does not certify main Axum's missing identity lifecycle or a combined RC deployment.

Main Axum HTTP routing with injected US/no-region geo returned the article and no EC cookie for both no signal and a valid GPP grant. The positive cookie control failed because main does not run publisher EC generation/finalization. This preexisting limitation remains unchanged and is not hidden by the supplementary result.

Supplementary runtime verdict: VERIFIED on scratch RC integration. Only the exact reviewed production detector/display code was overlaid into rc/identity at c3e33666; RC tests/docs were not backported for the runtime build. The actual Axum executable ran through its managed startup, local prepared config/secrets, persistent record binding, and existing protected loopback CloudFront geo provider, with synthetic assertions and a controlled HTTP origin. No manual generation/finalization was added.

Request Unmodified RC RC with reviewed fix
US, no region header, no signal EC minted and persisted No EC cookie
US, no region header, valid US GPP non-opt-out EC minted and persisted EC minted and persisted
US, no region header, same GPP plus GPC EC minted and persisted No EC cookie
Listed CA, no signal No EC No EC
Unlisted WY, no signal EC minted and persisted EC minted and persisted
Non-US JP, no signal EC minted and persisted EC minted and persisted
Invalid CloudFront region assertion Unknown geo; no EC Unknown geo; no EC

Both matrices passed all seven expectations. The required country-only requests exposed x-geo-country: US, no region header, and the controlled publisher article with HTTP 200. The positive cookie was __gpp=DBABLA~BVQqAAAAAgA.QA. Every minted EC was confirmed through the authenticated admin lookup: HTTP 200, consent.ok=true, tombstone=false.

The invalid-region CloudFront control is rejected by the pinned SDK before reaching the detector, withholding all geography. It proves unchanged fail-closed behavior, not the core unreadable-region fallback. Core fail-first tests cover the latter. No EdgeZero change is included.

The RC runtime qualifies local application routing, managed provider handoff, persistence and finalization with synthetic inputs. It does not qualify real CloudFront/ALB protection, a deployed environment, other adapter runtimes, or main's EC cookie lifecycle. Both owned servers stopped. No browser, DataDome access, staging/production proxy or deployment was used.

Checklist

Feature spec review: not applicable to this bug fix.

  • Changes follow AGENTS.md conventions.
  • No production unwrap() introduced.
  • Logging uses log macros; no production logger installed.
  • New behavior has fail-first regression coverage.
  • Tests/docs use fictional data; no operator configuration or credentials included.
  • Main base/target, narrow Apply US rules to a US request with no resolved state on every adapter #1705 scope, consumer audit, RC integration conflicts, review and runtime limits are disclosed.
  • Hosted CI gates complete for the reviewed revision.

@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 12:12

@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 c1c948d47 against main (db36dc0ec).

Approving so I'm not blocking, on the understanding that you'll handle the comments before merging. Behavior matches #1705, and the Fastly, Axum and Cloudflare country-only tests all pass.

Question: the fallback applies even when consent.us_states.privacy_states = []. A resolved US reader is then non-regulated while an unresolved one is strict, and on Cloudflare, which never sets a region, all US traffic gets gated despite no configured states. Is that intended, or should the fallback require at least one configured state? No test covers the empty list.

Worth noting in the PR description: the log label changes from non-regulated to US for this traffic, and on Cloudflare this affects all US requests, including existing ECs no longer being forwarded without a signal.

Checks: core consent and OpenRTB consent-matrix tests (122 passed), country_only_us tests for Axum, Cloudflare and Fastly (Viceroy 0.22.0), cargo fmt --check.


// A resolved US country still requires US consent when its state is
// missing or unreadable; losing state detail must not remove the gate.
return Jurisdiction::UsState("US".to_owned());

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.

R1 · Nonblocking: name the "unresolved US state" sentinel once. Reusing UsState is the right call, since it makes every existing match apply the strict rules. But the literal "US" is now relied on here, in the Display guard, and in 13 test sites across core, OpenRTB and three adapters. A future consumer that reads the payload as a state code (say, per-state GPP section selection) has to know the convention, and nothing enforces it. A Jurisdiction::UNRESOLVED_US_STATE constant or a Jurisdiction::us_unresolved() constructor used everywhere would keep the shape and drop the scattered literal.

- **Unknown**: Fail-closed when jurisdiction cannot be determined.

A request whose country is `US` but whose region is missing or unreadable uses
`UsState("US")`: the same strict US consent rules, without inferring a state.

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 · Nit: describe the label operators see, not the Rust value. These guides use policy labels elsewhere ("US State", "Non-regulated"). Operators will see jurisdiction=US in logs, not UsState("US"). Something like "the US (state unresolved) policy, logged as jurisdiction=US" would fit. Same in docs/guide/gdpr-compliance.md:123.

Resolution of conflicting signals is configurable (restrictive,
newest, or permissive).
- A request with country `US` and a missing or unreadable region uses the
strict US rules (`UsState("US")`). Without a consent signal, no new EC is

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.

Same wording note as in edge-cookies.md (R2).

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 US rules to a US request with no resolved state on every adapter

2 participants