Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Breaking:** An EC is now minted, and the EC row written, only on a top-level publisher navigation: a `GET` with `Sec-Fetch-Dest: document`, `Sec-Fetch-Mode: navigate` and no `prefetch` in `Sec-Purpose`. Clients that send no Fetch Metadata get no EC, a navigation answered with a 301, 302, 303, 307 or 308 redirect mints none, integration proxies no longer mint one, and prefetches and prerenders never mint or write. Each navigation makes at most one conditional page-load write; a consent withdrawal's tombstone is still written on any request that carries the EC cookie.
- **Breaking:** Browser EIDs from the `/auction` request body are no longer stored, and `/auction` and `/_ts/page-bids` no longer write browser EIDs from `ts-eids` or `sharedId`. Those cookies are ingested on the next top-level navigation.
- **Breaking:** An EC minted on the current navigation is no longer sent as `user.id` to bidders, that navigation's auction does not carry the browser's `ts-eids`, and identity providers that send the EC ID are not called for it, until a later navigation finds its row. Providers whose requests do not carry the EC ID run on that first navigation within `identity_budget_ms`, and their results go into the write that creates the row. Identity providers are also not called for an EC cookie whose row does not exist.
- **Breaking (bidder-visible):** With an EC KV store, an EC is sent to bidders as `user.id`, and as the `ts-{ec}` request ID, on the navigation auction, `/_ts/page-bids` and `/auction` only when the request read a consented row for it (#1549). An EC cookie whose row is missing, unreadable or a withdrawal tombstone now gets no `user.id` and a random `ts-req-` request ID, where bidders used to receive an EC that orphan recovery then replaced. To decide this, `/_ts/page-bids` and `/auction` read the row whenever an EC store exists, no longer only when partners are configured, and so does a navigation without Fetch Metadata that runs an auction. Without an EC KV store, as on Axum, Cloudflare and Spin, which hold no EC rows, the consented EC is still sent as before.
- This release registers no identity provider kind, so `ts config push` rejects an enabled `[[ec.identity_providers]]` entry and every runtime refuses to start with one; configure providers with `enabled = false` until a kind ships.
- A consent withdrawal keeps the `ts-ec` cookie while its tombstone cannot be written (after bounded CAS retries, or when the row cannot be read), so the next request carrying the cookie retries. Previously the cookie was expired first.
- **Breaking:** Axum, Cloudflare and Spin refuse to start when an enabled identity provider is configured, and Fastly refuses to start when an enabled provider names a `kind` this build does not include.
Expand Down
195 changes: 188 additions & 7 deletions crates/trusted-server-core/src/auction/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,11 @@ pub async fn handle_auction(
ec_context.set_client_eids(eids.clone());
}

// Resolve partner EIDs from the KV identity graph when the user has a valid
// EC and both KV and partner stores are available. Gate the read on a
// present registry: without one, `resolve_auction_eids` yields no
// server-side EIDs, so the snapshot would be an unused billable KV read.
let auction_kv_snapshot = match (kv, ec_id.as_deref(), registry) {
(Some(graph), Some(ec_id), Some(_)) => graph.load_snapshot(ec_id).await,
// Read the EC's row whenever an EC store exists: it decides whether the
// EC may go to bidders as `user.id` (see `bidder_ec_id`), and with a
// partner registry it supplies the server-side EIDs.
let auction_kv_snapshot = match (kv, ec_id.as_deref()) {
(Some(graph), Some(ec_id)) => graph.load_snapshot(ec_id).await,
_ => EcKvSnapshot::NotRead,
};
// Hand the loaded row to the request context so response finalization —
Expand All @@ -357,6 +356,7 @@ pub async fn handle_auction(
ec_context.set_kv_snapshot(auction_kv_snapshot.clone());
}
let eids = resolve_auction_eids(&auction_kv_snapshot, registry, ec_context);
let bidder_ec_id = bidder_ec_id(ec_id.as_deref(), kv, &auction_kv_snapshot);

// Look up geo for device info.
let geo = services
Expand All @@ -374,7 +374,7 @@ pub async fn handle_auction(
services,
&http_req,
consent_context,
ec_id.as_deref(),
bidder_ec_id,
geo,
)?;

Expand Down Expand Up @@ -551,6 +551,27 @@ pub(crate) fn resolve_auction_eids(
)
}

/// The EC ID bidders may receive, as `user.id` and in a `ts-{ec}` request ID.
///
/// With an EC store, only an EC whose consented row `snapshot` holds is sent,
/// the rule identity providers follow: a cookie EC with no row may never have
/// been issued, and orphan recovery replaces it on the navigation. Without an
/// EC store no EC has a row or is replaced, so `ec_id` passes unchanged.
pub(crate) fn bidder_ec_id<'ec>(
ec_id: Option<&'ec str>,
kv: Option<&KvIdentityGraph>,
snapshot: &EcKvSnapshot,
) -> Option<&'ec str> {
let ec_id = ec_id?;
if kv.is_none() {
return Some(ec_id);
}
snapshot
.entry_for(ec_id)
.is_some_and(|entry| entry.consent.ok)
.then_some(ec_id)
}

pub(crate) fn resolve_client_auction_eids(
raw: Option<&JsonValue>,
cookie_value: Option<&str>,
Expand Down Expand Up @@ -1941,6 +1962,166 @@ mod tests {
);
}

/// Runs `/auction` for a cookie EC against `graph` and returns the bid
/// request the bidder received.
async fn bid_request_for_cookie_ec(graph: &KvIdentityGraph, ec_id: &str) -> serde_json::Value {
let settings = create_test_settings();
let orchestrator = orchestrator_with(AuctionConfig {
enabled: true,
providers: AuctionConfig::legacy_provider_map(&["eid-capture"]),
timeout_ms: 2000,
mediator: None,
..Default::default()
});
let clock = TestClock::new();
let bidders = ScriptedHttpClient::new(&clock);
bidders.respond_to(
http::Method::POST,
EID_CAPTURE_ENDPOINT,
ScriptedReply::status(StatusCode::NO_CONTENT),
);
let services = build_services_with_outbound_client(&bidders, &clock);
let mut ec_context = make_ec_context(Jurisdiction::NonRegulated, Some(ec_id));
let req = Request::builder()
.method("POST")
.uri("https://publisher.example.com/auction")
.body(EdgeBody::from(
serde_json::to_vec(&json!({
"adUnits": [
{
"code": "div-gpt-ad-1",
"mediaTypes": { "banner": { "sizes": [[300, 250]] } }
}
]
}))
.expect("should serialize body"),
))
.expect("should build auction request");

let _ = handle_auction(
&settings,
&orchestrator,
Some(graph),
None,
&mut ec_context,
&services,
req,
)
.await;

let sent = bidders.requests();
assert_eq!(
sent.len(),
1,
"should send the auction request to the bidder"
);
serde_json::from_slice(&sent[0].body).expect("should send a JSON bid request")
}

#[tokio::test]
async fn auction_omits_user_id_for_a_cookie_ec_without_a_row() {
// Arrange
let graph = KvIdentityGraph::in_memory("test_store");
let ec_id = format!("{}.norow1", "a".repeat(64));

// Act
let body = bid_request_for_cookie_ec(&graph, &ec_id).await;

// Assert
assert!(
body["user"]["id"].is_null(),
"should not send a cookie EC with no row as user.id: {body}"
);
assert!(
!body.to_string().contains(&ec_id),
"should not send the EC anywhere in the bid request"
);
}

#[tokio::test]
async fn auction_sends_user_id_for_a_cookie_ec_with_a_consented_row() {
// Arrange
let graph = KvIdentityGraph::in_memory("test_store");
let ec_id = format!("{}.hasrow", "a".repeat(64));
let mut live = crate::ec::kv_types::KvEntry::tombstone(1000);
live.consent.ok = true;
graph
.create(&ec_id, &live)
.await
.expect("should seed live row");

// Act
let body = bid_request_for_cookie_ec(&graph, &ec_id).await;

// Assert
assert_eq!(
body["user"]["id"].as_str(),
Some(ec_id.as_str()),
"should send an EC with a consented row as user.id"
);
}

#[test]
fn bidder_ec_id_requires_a_consented_row_with_an_ec_store() {
// Arrange
let graph = KvIdentityGraph::in_memory("test_store");
let ec_id = format!("{}.ABC123", "a".repeat(64));
let mut live = crate::ec::kv_types::KvEntry::tombstone(1000);
live.consent.ok = true;
let present = |entry: &crate::ec::kv_types::KvEntry| EcKvSnapshot::Present {
ec_id: ec_id.clone(),
entry: Box::new(entry.clone()),
generation: Some(1),
};
let cases = [
(EcKvSnapshot::NotRead, None, "an unread row"),
(
EcKvSnapshot::Missing {
ec_id: ec_id.clone(),
},
None,
"a missing row",
),
(
EcKvSnapshot::Failed {
ec_id: ec_id.clone(),
},
None,
"an unreadable row",
),
(
present(&crate::ec::kv_types::KvEntry::tombstone(1000)),
None,
"a withdrawal tombstone",
),
(present(&live), Some(ec_id.as_str()), "a consented row"),
];

for (snapshot, expected, label) in cases {
// Act
let sent = bidder_ec_id(Some(&ec_id), Some(&graph), &snapshot);

// Assert
assert_eq!(sent, expected, "should decide user.id for {label}");
}
}

#[test]
fn bidder_ec_id_passes_the_ec_without_an_ec_store() {
// Arrange
let ec_id = format!("{}.ABC123", "a".repeat(64));

// Act
let sent = bidder_ec_id(Some(&ec_id), None, &EcKvSnapshot::NotRead);

// Assert
assert_eq!(
sent,
Some(ec_id.as_str()),
"should keep the EC where no EC store holds rows"
);
}

#[tokio::test]
async fn auction_strips_client_eids_when_ec_identity_denied() {
// US-state opt-out via GPC: the server-side auction consent gate still
Expand Down
Loading
Loading