Skip to content

Create and write back SharedID from the EC record - #1624

Open
dhruv8sh wants to merge 1 commit into
feat/sharedid-cleanupfrom
feat/sharedid-write-back
Open

dhruv8sh wants to merge 1 commit into
feat/sharedid-cleanupfrom
feat/sharedid-write-back

Conversation

@dhruv8sh

@dhruv8sh dhruv8sh commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • On a consented document navigation, the server sets the SharedID cookie from the EC record when the browser has none or a different value. It keeps Prebid's <name>_cst consent-hash companion consistent, so Prebid does not rewrite the cookie from script, which Safari caps. A _pubcid_optout cookie or denied EC consent expires both cookies. Denied EID consent (Purpose 4) leaves the browser's cookies alone (SID-2, SID-6).
  • Creation is always on with cookie storage (DEC-7: a browser may block Prebid.js from loading at all). A consented navigation from a reader with no SharedID and no _pubcid_optout gets a UUID v4, stored in the navigation's single page-load write, so it adds no KV write. The sharedid identity provider creates it when configured (generate now defaults to on with cookie storage); otherwise it joins browser ingest under the pubcid.org partner. With html5 storage only, nothing is created or set.
  • The stored SharedID wins over a different cookie value on both paths (SID-5). Providers can opt into keeps_stored_uids, and the sharedid provider does, so its cookie no longer replaces a live stored UID.

Stacks on #1584's PR (feat/sharedid-cleanup), which stacks on #1489; review only the commit above it. The SharedID cookie name, opt-out read and canonical pubcid.org EID come from that PR.

Choices made for this PR

  • <name>_cst assumes TCF, GPP and USP: the hash is computed the way Prebid computes it with all three consent modules present.
  • The cookie lifetime is always one year (Max-Age 365 days). It is not taken from Prebid's configured expires.
  • Write-back runs after the page-load write and never writes the record. It reads the record once when the request has not read it yet.
  • An explicit generate = false on the sharedid provider is honoured.

Changes

File Change
crates/trusted-server-core/src/ec/sharedid.rs Write-back decision, Set-Cookie building, _cst consent hash, creation of a SharedID for browser ingest
crates/trusted-server-core/src/ec/finalize.rs Create on consented navigations; write back after the page-load write; expire on opt-out or denied EC consent
crates/trusted-server-core/src/ec/provider.rs, ec/coordinator/mod.rs keeps_stored_uids provider hook: a live stored UID wins over a cookie UID
crates/trusted-server-identity-providers/src/lib.rs, src/sharedid.rs generate defaults on with cookie storage and is forced off for local storage; stored ID wins
crates/trusted-server-adapter-fastly/src/app.rs Carry the request's <name>_cst cookie
docs/guide/edge-cookies.md, docs/guide/configuration.md Write-back, creation and the sharedid provider default

Closes

Closes #1593

Acceptance criteria, verified on Fastly and in core tests:

  • WB-3: a present record and an absent cookie give both cookies, with Prebid's name and Domain, not HttpOnly, Secure; SameSite=Lax, one year.
  • WB-3: a consented first visit with no SharedID anywhere gets one created, stored and set; a reader with _pubcid_optout gets none.
  • WB-3: with storage.type = html5, the server neither creates nor sets a SharedID.
  • WB-3: an equal cookie with a consistent <name>_cst gives no Set-Cookie.
  • WB-3: an equal cookie with a missing or different <name>_cst re-sets only the companion.
  • WB-3: Purpose 1 denied, or _pubcid_optout, expires both.
  • WB-3: Purpose 4 denied with Purpose 1 granted gives no Set-Cookie and leaves the browser's cookie alone.
  • WB-3: Prebid's extend with a pixelUrl keeps working alongside it. The GET that answers pixelUrl is T19.
  • SID-2: the cookie opt-out is covered here. The localStorage-only opt-out needs the injected script to copy it into the cookie, which is T20 (Injected script calls the EC route on consent and merges the IDs into Prebid #1599).
  • SID-5: a stored SharedID survives a request carrying a different cookie value, with and without the sharedid provider.
  • SID-6 on each supported adapter: covered on Fastly. Other adapters wait for the shared conformance suite (T5, Cut Trusted Server over to EdgeZero PR 275 #1507).

Spec

Spec: server-side identity on every adapter (WB-3, SID-2, SID-5, SID-6, DEC-7); plan task T13.

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
  • JS tests: no JS changes in this PR
  • JS format: no JS changes in this PR
  • Docs format: cd docs && npm run format
  • WASM build: cargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1
  • Manual testing via fastly compute serve
  • Other: CLI tests, integration --test parity, scripts/lint-wasm-clock.sh, ts dev lint domains --changed-vs feat/s2s-eid-collection-providers

Checklist

  • Feature PRs: spec linked above, ending in a review log of two or more agent review rounds
  • Changes follow AGENTS.md conventions
  • No unwrap() in production code — use expect("should ...")
  • Uses log macros (not println!)
  • New code has tests
  • No secrets or credentials committed

…ations

When Prebid stores SharedID in a cookie, a consented navigation sets that cookie from the record if the request has none or a different value, and keeps Prebid's <name>_cst consent-hash companion consistent. Unchanged cookies get no Set-Cookie. A denied EC consent or _pubcid_optout expires both cookies, and with TCF Purpose 4 denied the browser's cookie is left alone.

Creation is always on with cookie storage: a consented navigation from a reader with no SharedID and no _pubcid_optout gets a random UUID inside the navigation's single page-load write, so it adds no KV write. The sharedid identity provider generates by default with cookie storage (an explicit generate setting is honoured, and it is forced off when Prebid keeps SharedID in local storage only); without that provider the UUID joins browser ingest under the pubcid.org partner.

A stored SharedID wins over a different cookie value on both paths: providers can opt into keeps_stored_uids, and the sharedid provider does. Write-back runs after the page-load write, never writes the record, and reads it once when the request has not.

Closes #1593

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
@dhruv8sh
dhruv8sh force-pushed the feat/sharedid-write-back branch from 4102c32 to 593cb67 Compare November 18, 2026 16:09
@dhruv8sh
dhruv8sh changed the base branch from feat/identity-app-in-core to feat/sharedid-cleanup November 18, 2026 16:09
@dhruv8sh
dhruv8sh added this pull request to stack #1621 November 18, 2026 16:10
@dhruv8sh
dhruv8sh removed this pull request from stack #1621 November 18, 2026 16:50
@dhruv8sh
dhruv8sh added this pull request to stack #1630 November 18, 2026 16:50

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.

Create and write back SharedID in the shared app

1 participant