Skip to content

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

Open
dhruv8sh wants to merge 12 commits into
feat/axum-identity-providersfrom
feat/sharedid-write-back
Open

dhruv8sh wants to merge 12 commits into
feat/axum-identity-providersfrom
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
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>

# Conflicts:
#	crates/trusted-server-adapter-fastly/src/app.rs
#	crates/trusted-server-core/src/ec/finalize.rs
#	docs/guide/configuration.md
@dhruv8sh
dhruv8sh removed this pull request from stack #1630 November 20, 2026 01:52
@dhruv8sh
dhruv8sh changed the base branch from feat/sharedid-cleanup to feat/axum-identity-providers November 20, 2026 01:54
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
PR #1532 now reads the native Geo profile path from
TRUSTED_SERVER__NATIVE_GEO_PROFILE_FILE instead of TS_NATIVE_GEO_PROFILE_FILE. No file in this PR
uses the old name after the merge, so the merge only takes the rename from
PR #1566. The merge had no conflicts.
aram356 added a commit that referenced this pull request Nov 24, 2026
PR #1532 now reads the native Geo profile path from
TRUSTED_SERVER__NATIVE_GEO_PROFILE_FILE instead of TS_NATIVE_GEO_PROFILE_FILE. No file in this PR
uses the old name after the merge, so the merge only takes the rename from
PR #1624. The merge had no conflicts.
@aram356

aram356 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

For #1532's rename of the native Geo profile variable to TRUSTED_SERVER__NATIVE_GEO_PROFILE_FILE, I pushed 006cdf561 here, one merge of this PR's base:

No file in this PR uses the old name after the merge, so it only takes the rename from #1566. The merge had no conflicts.

Correction: through #1566, this merge also carries five #1540 commits that #1566 had not merged before (CloudFront forwarding authentication, AWS ingress and Terraform demo prerequisites, the example deployment gate and the deployment guide). It is not only the rename.

This brings in 1f054c6 from #1488, which forwards ortb2.user.ext.eids
from the Prebid config into the auction EIDs, and a99dd66, a62601b,
d1eb75f and 394892b from #1489, which cap mirrored UID expiry at 30
days from the UTC day start and pass the request time into finalize. They
arrive through the chain's merges into #1639, #1640, #1612, #1628, #1623,
#1531, #1532, #1533, #1534, #1536, #1535, #1537, #1539, #1538, #1540 and
#1566, with #1536's, #1535's and #1566's moves of their finalize calls
onto FinalizeRequest. It also brings d5276ee, which publishes the native
AWS runtime files without GNU mv -T, and Christian's merge 5597d3e of
#1538 into #1540, which #1566's merge now carries.

The base now also carries the Axum serving line (#1613, #1616, #1617, #1615,
#1635, #1637 and #1627), which #1533 merged, and #1627's b958107, which
decodes the Spin discovery document with Response::json, and #1627's merge
of #1625 (006b45e), which pins Wrangler for the Cloudflare smoke and CI.

EC finalize docs: a conflict is the ec_finalize_response doc, where
this PR described the SharedID argument and #1489 replaced the argument
list with FinalizeRequest. The function doc keeps #1489's pointer to
FinalizeRequest, and this PR's write-back sentence moves to the
FinalizeRequest sharedid field, next to #1628's opt-out sentence, as #1662
words it.

EC finalize tests: run_write_back, the helper of this PR's SharedID
write-back tests, still used the old finalize arguments. It now passes a
FinalizeRequest at the fixed test request time NOW and seeds its live row
at NOW_SECS, the same change #1662 makes to this helper.

It also brings b2d4bfd from #1488, which records the known UID hashes
on lookup results with a setter, so the provider IDs the write planner
logs are not derived from them.

The base now also carries #1506's repin of EdgeZero to rc/identity at
d063a8e7 and its merge of main's Fastly SDK 0.13.3 upgrade (#1671): fastly
0.13.3, url 2.5.9 and Viceroy 0.22.0.

The base now also carries #1627's 4d0c1a2, which renames the generic
runtime KV store to trusted_server_runtime_kv, and #1488's a610152 and
9104fd3, which add hashed-email intake for the LiveRamp and ID5
identity providers.

Boxed identity provider: this PR forwards `keeps_stored_uids` and #1488
forwards `hashed_email_path` at the end of the `Box<P>` IdentityProvider
impl. The merge keeps both.
aram356 added a commit that referenced this pull request Nov 25, 2026
This brings in 1f054c6 from #1488, which forwards ortb2.user.ext.eids
from the Prebid config into the auction EIDs, and a99dd66, a62601b,
d1eb75f and 394892b from #1489, which cap mirrored UID expiry at 30
days from the UTC day start and pass the request time into finalize. They
arrive through the chain's merges into #1639, #1640, #1612, #1628, #1623,
#1531, #1532, #1533, #1534, #1536, #1535, #1537, #1539, #1538, #1540,
#1566, #1624, #1641, #1642 and #1646, with #1646's move of the request
time into IdentityApp::finalize. It also brings d5276ee, which publishes
the native AWS runtime files without GNU mv -T, and Christian's merge
5597d3e of #1538 into #1540, through #1566's merge.

The base now also carries the Axum serving line (#1613, #1616, #1617, #1615,
#1635, #1637 and #1627), which #1533 merged, and #1627's b958107, which
decodes the Spin discovery document with Response::json, and #1627's merge
of #1625 (006b45e), which pins Wrangler for the Cloudflare smoke and CI.

This PR already carries #1646's head 461aa0d, so the merge adds only
#1646's new merge 166944769 of #1642 and the chain below it, including the
identity conformance check that now strips the mirrored UID's exp.

It also brings b2d4bfd from #1488, which records the known UID hashes
on lookup results with a setter, so the provider IDs the write planner
logs are not derived from them.

Restacking on the Axum serving line conflicts in the Axum startup tests,
where #1617 waits for /ready, since liveness stays up after a caught
initialization failure, and this PR rewrites the wait to retry a port
collision and to require the child's own ready lifecycle event.

Axum startup tests: wait_ready keeps this PR's collision retry and
lifecycle check, then probes #1617's /ready and returns the /health
response once the child is ready.

The fixture drains each child's output through this PR's log readers, so
#1617's assert_serves_failure_router reaps the stopped child and reads
those captured logs instead of collecting the pipes, which the readers
already own.

The base now also carries #1506's repin of EdgeZero to rc/identity at
d063a8e7 and its merge of main's Fastly SDK 0.13.3 upgrade (#1671): fastly
0.13.3, url 2.5.9 and Viceroy 0.22.0.

This PR now stacks on #1661 instead of #1646, so rc/identity can take both
as plain merges. #1661 sits on #1656 and #1626, which sit on #1646, so the
merge also brings #1626 (provider opt-outs and legacy EID expiry on Fastly
and Axum), #1656 (the configurable Edge Cookie browser gate) and #1661
(refusing EC creation when a trusted JA4 contradicts the User-Agent).

Fastly identity conformance fixture: #1661 records each scenario's runtime
TLS JA4 through a RuntimeTlsJa4 middleware in place of derived device
signals, takes the User-Agent from the scenario and drops the browser flag.
This PR adds geo consent requests with their own trusted client IP settings
and no browser device signals. The merge assembles the conformance app with
#1661's middleware and keeps this PR's geo_configured flag and
producer_settings. It sends the scenario's User-Agent unless the API request
supplies one, and inserts the scenario's JA4 only for requests without a geo
consent exchange, because this PR derived device signals only for those.

The base now also carries #1627's 4d0c1a2, which renames the generic
runtime KV store to trusted_server_runtime_kv, #1488's a610152 and
9104fd3, which add hashed-email intake for the LiveRamp and ID5
identity providers, #1646's aa31559, which gates identity writes for
rejected clients, and #1626's d07f789, which withholds a mirrored UID
while another source owner is opted out.

Fastly conformance JA4: the rebuilt #1661 merge supplies a trusted Python
JA4 behind the Chrome User-Agent for #1646's known non-browser API
requests, and this PR inserts the scenario's JA4 only without a geo
consent exchange, with its producer_settings. The merge keeps both: a
known non-browser request gets the Python JA4, any other request the
scenario's JA4 unless it is a geo consent exchange.

This PR's head moves to e8015ca, its clean merge of #1646's aa31559,
which the base already carries, so it adds no change beyond the base.

Axum lib.rs: the base now carries #1636, through #1626's merge of it, whose
after_response_drain_tests module sits where this PR adds its
geo_conformance module. The crate keeps both test modules.
aram356 added a commit that referenced this pull request Nov 25, 2026
This brings in 1f054c6 from #1488, which forwards ortb2.user.ext.eids
from the Prebid config into the auction EIDs, and a99dd66, a62601b,
d1eb75f and 394892b from #1489, which cap mirrored UID expiry at 30
days from the UTC day start and pass the request time into finalize. They
arrive through the chain's merges into #1639, #1640, #1612, #1628, #1623,
#1531, #1532, #1533, #1534, #1536, #1535, #1537, #1539, #1538, #1540,
#1566, #1624, #1641, #1642 and #1646, with #1646's move of the request
time into IdentityApp::finalize. It also brings d5276ee, which publishes
the native AWS runtime files without GNU mv -T, and Christian's merge
5597d3e of #1538 into #1540, through #1566's merge.

The base now also carries the Axum serving line (#1613, #1616, #1617, #1615,
#1635, #1637 and #1627), which #1533 merged, and #1627's b958107, which
decodes the Spin discovery document with Response::json, and #1627's merge
of #1625 (006b45e), which pins Wrangler for the Cloudflare smoke and CI.

The merge also brings the 12 #1646 commits this PR lacked, from 48a43ae
to 461aa0d: dhruv8sh's page-phase lookup and /auction EID work
(48a43ae, 82fe088, 1d0a74f, 838586e and his chain merges a061c01,
ecf16e8, e1d23a0, edcf4c5 and 9a020e1), the merge 9cad928 of
#1641 into #1642, and prk-Jr's "Merge providers-awaited into shared
identity" (4ffbaf8) and "Restore Fastly auction browser gating"
(461aa0d).

Edge cookies guide: a conflict is the request lifecycle paragraph.
The merge takes #1646's sentences on positive identity cookies, core
expiries and /auction body EIDs, and keeps this PR's closing sentences on
the default ec.sliding_refresh = false flow and sliding renewal.

Fastly adapter tests: 82fe088 from #1646 removed the navigation-lookups
thread-local and the page-lookups argument of apply_edgezero_ec_finalize,
since the handler now collects page lookups onto the EC context. This PR's
sliding_ec_renews_held_publisher_identity_before_terminal_privacy test
drops its two take_navigation_lookups calls and passes no page lookups to
finalize. Its configuration has no record store or providers, so no
lookups were collected before either, and its assertions are unchanged.

It also brings b2d4bfd from #1488, which records the known UID hashes
on lookup results with a setter, so the provider IDs the write planner
logs are not derived from them.

The base now also carries #1506's repin of EdgeZero to rc/identity at
d063a8e7 and its merge of main's Fastly SDK 0.13.3 upgrade (#1671): fastly
0.13.3, url 2.5.9 and Viceroy 0.22.0.

This PR now stacks on #1661 instead of #1646, so rc/identity can take both
as plain merges. #1661 sits on #1656 and #1626, which sit on #1646, so the
merge also brings #1626 (provider opt-outs and legacy EID expiry on Fastly
and Axum), #1656 (the configurable Edge Cookie browser gate) and #1661
(refusing EC creation when a trusted JA4 contradicts the User-Agent).

Cloudflare route tests: both PRs add a test at the end of the file. The
merge keeps both, this PR's
sliding_ec_configuration_preserves_unsupported_platform_responses and
#1661's ec_route_creates_no_record_whatever_the_bot_management_ja4.

Fastly sliding EC test: #1617, which now sits below this PR, answers GET
/health through the router's probe hook as an operational response, which
carries no EC state. This PR's
sliding_ec_renews_held_publisher_identity_before_terminal_privacy routes
/health through the router and expected EC state on every path but the
unsupported EC route, so it now also accepts the liveness probe without EC
state. Its check that /health issues no renewal cookie is unchanged.

The base now also carries #1627's 4d0c1a2, which renames the generic
runtime KV store to trusted_server_runtime_kv, #1488's a610152 and
9104fd3, which add hashed-email intake for the LiveRamp and ID5
identity providers, #1646's aa31559, which gates identity writes for
rejected clients, and #1626's d07f789, which withholds a mirrored UID
while another source owner is opted out.

Settings: this PR's MaxAgeDays and #1488's HashedEmailSource are both
added before Ec in settings.rs; the merge keeps both.

This PR's head moves to fbe5670, its merge of #1646's aa31559, which
models admitted clients in the core sliding tests, finalizes them with
the store gate and adds refused_client_gets_no_renewal_or_record_io, and
adds the proposal's review log. Taken as the change from the old head
668d501, the new head would replay #1646 commits the base already
carries in rebuilt form. The merge takes only fbe5670's own resolution,
the change from a plain merge of 668d501 and aa31559 to fbe5670:
the sliding tests and the proposal apply cleanly, and its Fastly sliding
test port is the one this merge already made.
aram356 added a commit that referenced this pull request Nov 25, 2026
…1622 into rc/identity

#1622 (244ca26) now carries the whole chain, each PR merging the one below
it:

- #1506 (c197404) repins EdgeZero to rc/identity at d063a8e7, which
  carries EdgeZero main's Fastly SDK 0.13.3 upgrade through every EdgeZero PR
  here, and merges Trusted Server main's upgrade (#1671): fastly 0.13.3, url
  2.5.9 and Viceroy 0.22.0.
- #1614, #1525, #1526, #1487 and #1488 take it in turn. #1488 also adds
  b2d4bfd, which records known UID hashes with a setter.
- #1489, the identity spine (#1639, #1640, #1612, #1628 and #1623), #1531 and
  #1532.
- The Axum serving line: #1613, #1616, #1617, #1615, #1635, #1637 and #1627,
  chained, with #1627's b958107 decoding the Spin discovery document with
  Response::json and #1627's merge of #1625, which brings #1625's Wrangler pin
  into the chain.
- The held line on #1627: #1533, #1534, #1536, #1535, #1537, #1539, #1538,
  #1540, #1566, #1624, #1641, #1642 and #1646. #1646 keeps its own shared
  after-response runner in ec::app::lookups.
- #1636 (72096cd) on #1646 (b5a5f62), draining Axum
  after-response identity tasks on SIGTERM through #1646's shared runner.
- The EC route line on #1636: #1626 (067531e), which merges #1636, the
  draft #1656, #1661, #1662 and #1622, and through #1622's merge of it,
  #1620's round-6 head.

Each conflict was resolved in the PR that sits higher. This merge is clean.

Since the last update the chain also takes #1488's hashed-email intake
(a610152 and 9104fd3) and its POST, body and header options for the
status call (f063a76), #1627's split of the generic runtime KV store into
trusted_server_runtime_kv (4d0c1a2), #1646's gate on identity writes for
rejected clients (aa31559) its native container test of the failure router
(4f4c036) and that test's header check on an ordinary route (71a573a),
#1626's withholding of a mirrored UID while another source owner is opted
out (d07f789), and #1617's description of the Axum startup failure router
(6d174a8) and of the startup failures that still exit before listening
(4c07cad). #1636 no longer sits in the Axum serving line; it arrives
through #1626, which merges it on top of #1646. Its new head adopts #1646's
after-response runner in place of the one rc/identity took with cf1102c.

Cloudflare guide: #1627's merge of #1625 now keeps both #1625's tool version
clause and #1627's TRUSTED_SERVER_RUNTIME_KV binding in the smoke paragraph,
and fixes #1625's smoke script test for #1617's Python floor and Worker
build, and #1537's merge fixes its ts stub for #1537's storage template
step, so this merge needs no resolution.
@aram356

aram356 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed 00a67cb19, a merge of #1566's new head 4612efcb0. It brings the Axum serving line, #1627's trusted_server_runtime_kv split, #1488's hashed-email intake, #1489's FinalizeRequest and request time, #1540's d5276eebf and 5597d3e4e through #1566's merge, and #1506's repin of EdgeZero to rc/identity at d063a8e7 with main's Fastly SDK upgrade (#1671). Resolutions:

#1566's new head 6f01fee brings #1537's b181544, "Accept any Fastly EC
store link name at startup", which #1537's owner merged up through #1539,
#1538 and #1540. The merge is clean.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed 178636542, a merge of #1566's new head 6f01fee7c. It brings #1537's b181544a0, "Accept any Fastly EC store link name at startup", which #1537's owner merged up through #1539, #1538 and #1540. The merge had no conflicts.

Takes #1566's new head 7d2eda9, which carries #1506's repin of EdgeZero to
rc/identity at 459bd27d (42e0c46): PR 275 at 0e2a58ae, the stack's test
fixes and EdgeZero 536's bounded record update, RecordHandle::update.

The merge is clean.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed bce4943cf, a merge of #1566's new head 7d2eda90f, which brings #1506's repin of EdgeZero to rc/identity at 459bd27d (42e0c46c7): EdgeZero #275 at 0e2a58ae, the EdgeZero stack's test fixes and EdgeZero #536's bounded record update, RecordHandle::update. The merge had no conflicts.

@prk-Jr prk-Jr 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 the PR's own change (593cb67de) against the merge base with feat/axum-identity-providers (7d2eda90f). The later commits are merges of #1566.

The write-back mechanics look right. decide_write_back covers the WB-3 matrix. I checked cyrb53, the handler order (TCF, USP, GPP, COPPA "0") and the hash >>> 8 byte encoding against Prebid's consentHandler.ts and getConsentHash(). The _cst value is URL-encoded on write, and Prebid's getCookie decodes it. keeps_stored_uids is applied after the existing freshness filter and recounts correctly.

Requesting changes for one blocking issue.

Blocking

1. SharedID creation turns on before the localStorage opt-out is visible to the server (SID-2)

Prebid's sharedIdSystem treats a reader as opted out when _pubcid_optout is in either the cookie or localStorage (hasOptedOut() reads both, whatever the configured storage type). The server only sees the cookie. Copying a localStorage opt-out into the cookie is T20 (#1599), which this PR leaves open.

This PR turns creation on by default for every deployment with cookie storage, on two paths:

  • with_prebid_sharedid_cookie defaults generate = true for the sharedid provider.
  • created_sharedid_update always creates for browser ingest, with no setting to turn it off.

Scenario: a reader opted out through localStorage only, with Purposes 1 and 4 granted, opens a page. The server creates a UUID, stores it under pubcid.org, sets _pubcid and _pubcid_cst, and server-side bid requests then carry that ID. Prebid on the page sees the opt-out and suppresses the ID client-side, so the server ends up sending an identifier the reader declined. Before this PR, generation was off by default for exactly this reason. The provider module doc still says so: sharedid.rs lines 22-24, "Generation is off by default: Prebid may keep its opt-out in localStorage, which the server cannot see".

Minimal fix, either of:

  • Keep creation opt-in until T20 lands. Leave the provider's generate default off, and gate created_sharedid_update behind the same setting or an explicit one.
  • Stack this PR on T20, so the cookie copy of a localStorage opt-out exists before creation turns on by default.

Write-back of an existing stored value doesn't have this problem in the same way, so it can stay as it is.

Non-blocking

2. Stale provider module doc. In crates/trusted-server-identity-providers/src/sharedid.rs, lines 17-18 say "when Prebid later writes a different one, the cookie's ID replaces the generated one". keeps_stored_uids now makes the stored ID win. Lines 22-24 still say generation is off by default.

3. Docs describe write-back for every adapter. edge-cookies.md says a consented navigation writes the cookie back and creates a SharedID. Only the Fastly adapter builds SharedIdRequest::for_write_back. Axum's NativeEcRequest::read still uses from_request, so on Axum write_back is None and there is no creation, write-back or expiry. That matches the issue's scope ("verified on Fastly", Axum in #1581), but the guide should say it is Fastly-only for now.

Verification

  • cargo test -p trusted-server-core --lib sharedid (host target): 65 passed.
  • cargo test -p trusted-server-core --lib coordinator: 100 passed.
  • cargo test -p trusted-server-identity-providers sharedid: 13 passed.
  • Checked Prebid's sharedIdSystem.ts (opt-out read), consentHandler.ts and userId getConsentHash()/setValueInCookie in the repo's pinned prebid.js.
  • CI at bce4943cf: everything passes except local-provider-image. It fails with the same invalid-envelope must not listen assertion in scripts/test-native-container.mjs on #1566's head, and this PR touches no startup or container code, so it is pre-existing and unrelated.
  • Not run: the full CI gate list, Viceroy tests, or a runtime check against a live Prebid page.

config
.settings
.entry(sharedid::GENERATE_SETTING)
.or_insert(serde_json::Value::Bool(true));

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.

Blocking (see the review body). Defaulting generate to true here means a reader who opted out of SharedID through localStorage _pubcid_optout, which Prebid honours but the server can't see until T20, gets a SharedID created, stored and sent server-side. Please keep this opt-in until T20 lands.

Comment on lines +297 to +298
// A reader with no SharedID anywhere gets one in this write.
if navigation && let Some(created) = created_sharedid_update(sharedid, registry) {

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.

Blocking, same root cause. Browser-ingest creation has no setting at all, so the localStorage opt-out gap affects every cookie-storage deployment, even one without a sharedid provider. Please gate this behind the provider's setting or an explicit one until T20 makes the opt-out visible here.

Comment on lines +17 to +18
//! response writes that cookie back from the row; when Prebid later writes a
//! different one, the cookie's ID replaces the generated one. When Prebid

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.

Non-blocking: with keeps_stored_uids, a different cookie no longer replaces the stored ID; the stored ID wins and is written back. Lines 22-24 below also still say generation is off by default.


The SharedID cookie follows a similar path but is written directly by Prebid's SharedID module rather than by TSJS. The server reads the cookie named by the `storage.name` of the `sharedId` entry in [`integrations.prebid.managed_user_ids`](./configuration.md), and reads the legacy `sharedId` cookie when no such entry has storage settings. With `storage.type = "html5"` there is no cookie to read. The ID is stored under the `pubcid.org` partner, the source Prebid sends it under, or under a `sharedid.org` partner when only that one is configured. A record that still holds it under `sharedid.org` is moved to `pubcid.org` on its next write, keeping any SharedID already stored under `pubcid.org`. Bidders receive it once, as source `pubcid.org` with `atype` 1, whichever of the record, the cookies or the `/auction` body carried it. A `_pubcid_optout` cookie keeps the SharedID out of the record and out of bid requests.

When Prebid stores the SharedID in a cookie (`storage.type` `cookie` or `cookie&html5`), a consented top-level navigation writes that cookie back from the EC record if the request carries none or a different value, so the stored SharedID wins. The cookie uses Prebid's `storage.name` and the EC cookie domain, is not `HttpOnly`, and is `Secure; SameSite=Lax` for one year. The response also keeps Prebid's `<name>_cst` consent-hash companion consistent, so Prebid does not rewrite the cookie from script; an unchanged cookie and companion get no `Set-Cookie`. Creation is always on with cookie storage: a consented navigation from a reader with no SharedID and no `_pubcid_optout` gets a random UUID, stored in the same navigation's page-load write (by the `sharedid` identity provider when one is configured, otherwise as a browser-ingested ID), so it adds no KV write. A stored SharedID always wins over a different cookie value, on both paths. With TCF Purpose 4 denied the cookies are left alone; with EC consent denied or `_pubcid_optout` present both are expired.

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.

Non-blocking: only the Fastly adapter uses SharedIdRequest::for_write_back. Axum still builds from_request, so it does no creation, write-back or expiry yet. Please say this is Fastly-only for now (Axum follows in #1581).

#1566's new head 602c628 brings #1539's cf4e815, "Expect the failure router in the native container test". The merge is clean.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed b6c2ff235, a merge of #1566's new head 602c628e7, which brings #1539's cf4e815d4, the native container test's failure-router expectation. The merge had no conflicts. It clears local-provider-image, which failed here with "invalid-envelope must not listen".

Takes #1566's new head baa2e43, which carries #1506's repin of EdgeZero to
rc/identity at 1619078a (8edc50e), a revert that removes EdgeZero 522
(portable Fastly record providers) and 524 (outbound mTLS client
identities).

The merge is clean.
@aram356

aram356 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed 5ab4e6b3e.

Takes #1566's new head baa2e43, which carries #1506's repin of EdgeZero to rc/identity at 1619078a (8edc50e), a revert that removes IABTechLab/edgezero#522 (portable Fastly record providers) and IABTechLab/edgezero#524 (outbound mTLS client identities).

The merge is clean.

@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 PR #1624 at 5ab4e6b3e against its live feat/axum-identity-providers base at baa2e4354. The blockers are in the new consent and opt-out paths, compatibility with Prebid's cookies, and preserving the stored ID across provider configurations. The cleanup comments are marked non-blocking.

All 78 existing focused SharedID tests passed. Fourteen additional Rust probes reproduced the reported behavior through core finalization or the provider coordinator and write planner. Prebid 10.26.0 and cookie-jar checks reproduced the script rewrite and domain mismatch using the server's actual header values. These were not full Fastly or Safari runs.

/// Without a cookie to write back to, this reads what
/// [`Self::from_request`] reads.
#[must_use]
pub fn for_write_back<B>(storage: &SharedIdStorage, req: &Request<B>) -> Self {

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. Read opt-out across all Cookie fields

A consented request with _pubcid_optout=1 in its second Cookie field still minted a UUID, persisted it, and returned it in Set-Cookie. from_request calls extract_cookie_value, which reads only the first field. The provider joins the fields but treats _pubcid_optout= as absent, while core treats it as present. Use one opt-out presence rule across all fields for both paths.

.kv_snapshot()
.entry_for(&ec_id)
.filter(|entry| entry.consent.ok);
let stored = entry.and_then(|entry| stored_sharedid(entry, &source));

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. Honor the source's vendor-consent gate on write-back

With Purposes 1 and 4 granted and the configured vendor denied, the test UID was absent from ordinary EID output but present in the new JavaScript-readable cookie. Check the selected source's existing consent policy before setting either cookie. Deletion should remain independent of that policy.

ec_context.set_after_response_permit(after_response);
}
// Write-back reads the row as the page-load write left it.
if navigation {

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.

R3. Don't write back from a snapshot after losing the conditional write

In the reproduced race, the withdrawal tombstone stayed in KV, but the losing navigation still returned the pre-withdrawal ID. A failed CAS leaves the old Present snapshot intact. Distinguish a known conflict from a no-op and skip value and companion writes on conflict. Cookie expiry can still run, and no KV retry is needed.

let consent_withdrawn = ec_consent_withdrawn(ec_context.consent());

if !consent_allows_ec {
expire_sharedid_on_denied_consent(settings, sharedid, navigation, response);

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.

R4. Expire opted-out browser cookies without requiring an EC record

The opt-out control expired both cookies; the same request expired neither with no graph, EC ID, or registered SharedID partner. EC-denial expiry already happens at this point without those dependencies. Put the request-only opt-out cleanup here too, before record-dependent work.

.raw_us_privacy
.as_ref()
.map_or_else(|| serde_json::Value::Null, |usp| serde_json::json!(usp));
let gpp = consent.raw_gpp_string.as_ref().map_or_else(

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.

R5. Compute the consent companion from the inputs Prebid actually hashes

For the GPP fixture, Trusted Server hashed the decoded section list and emitted G+tjgQ==; Prebid 10.26.0 hashed the CMP applicability list and expected v1YpWQ==. The no-TC-string case also differed when the CMP explicitly reported gdprApplies=false. Both server hashes triggered Prebid's script-write path. The expected hash prevented it. Carry the CMP hash inputs separately from normalized enforcement data, and treat unavailable inputs as unknown.

.and_then(|entry| entry.ids.get(source.as_str()))
.is_some_and(|record| record.has_live_uid(lookup.now))
});
recount_found(&mut found);

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.

R13. Consolidate the cookie precedence checks

Non-blocking. The two flags each filter and recount the same result. When fixing retention, select the precedence policy once and filter/recount once. Preserve the default cookie-wins rule and UID2's expiry-based rule.

)
}

fn append_set_cookie(response: &mut Response<EdgeBody>, cookie: &str) {

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.

R14. Reuse the existing Set-Cookie helper

Non-blocking. ec/cookies.rs:179 already parses, appends, and logs an invalid raw header. Replace these calls with super::cookies::append_cookie and drop the duplicate helper. Keep the SharedID serialization here.

.or_insert_with(|| serde_json::Value::from(vec![cookie]));
config
.settings
.entry(sharedid::GENERATE_SETTING)

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.

R15. Name the provider setup helper after what it does

Non-blocking. with_prebid_sharedid_cookie now defaults generation on with cookie storage and overrides it off for HTML5-only storage. Rename the helper and its callers to apply_prebid_sharedid_storage or equivalent.

/// configured cookie, and `None` unless Prebid stores it in a cookie, since
/// Prebid would not read a server-written value from anywhere else.
#[must_use]
pub fn write_back_cookie(&self) -> Option<&str> {

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.

R16. Keep write-back implementation details private

Non-blocking. This method is only used in this module. GENERATE_SETTING in the provider crate can likewise be pub(super). Keep for_write_back public for adapters and give it the # Examples section required by AGENTS.md.

Suggested change
pub fn write_back_cookie(&self) -> Option<&str> {
fn write_back_cookie(&self) -> Option<&str> {

}

#[tokio::test(flavor = "current_thread")]
async fn sharedid_is_not_created_without_consent_storage_or_with_an_opt_out() {

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.

R17. Reuse the HTML5-only request fixture

Non-blocking. The HTML5-only request built here is the same as the setup at line 2077. Reuse one fixture and keep the separate behavioral assertions.

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

4 participants