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
6 changes: 5 additions & 1 deletion crates/trusted-server-adapter-axum/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,11 @@ fn named_route_handler(
}
NamedRouteHandler::AdminEidsLookup => {
let partner_registry = PartnerRegistry::from_ec(&state.settings.ec)?;
handle_admin_eids_lookup(&partner_registry, &req)
handle_admin_eids_lookup(
&partner_registry,
state.settings.sharedid_storage().cookie_name(),
&req,
)
}
NamedRouteHandler::LegacyAdminDenied => Ok(legacy_admin_alias_denied()),
NamedRouteHandler::Identify => answer_identify_locally(&state.settings, &req),
Expand Down
6 changes: 5 additions & 1 deletion crates/trusted-server-adapter-cloudflare/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ fn router_builder(state: &Arc<AppState>) -> RouterBuilder {
"/_ts/admin/eids",
make_handler(Arc::clone(&state), |s, _services, req| async move {
let partner_registry = PartnerRegistry::from_ec(&s.settings.ec)?;
handle_admin_eids_lookup(&partner_registry, &req)
handle_admin_eids_lookup(
&partner_registry,
s.settings.sharedid_storage().cookie_name(),
&req,
)
}),
)
.post(
Expand Down
86 changes: 73 additions & 13 deletions crates/trusted-server-adapter-fastly/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ use trusted_server_core::auction::{
};
use trusted_server_core::cache_policy::EdgeCacheHeader;
use trusted_server_core::config_payload::DEFAULT_SECRET_STORE_ID;
use trusted_server_core::constants::{COOKIE_SHAREDID, COOKIE_TS_EIDS, ENV_FASTLY_SERVICE_VERSION};
use trusted_server_core::constants::{COOKIE_TS_EIDS, ENV_FASTLY_SERVICE_VERSION};
use trusted_server_core::ec::admin::{
deny_admin_diagnostic_fallback, handle_admin_ec_lookup, handle_admin_eids_lookup,
};
Expand All @@ -126,6 +126,7 @@ use trusted_server_core::ec::kv::KvIdentityGraph;
use trusted_server_core::ec::page_load::NavigationPermit;
use trusted_server_core::ec::provider::{ClientSignals, RequestCookies};
use trusted_server_core::ec::registry::PartnerRegistry;
use trusted_server_core::ec::sharedid::{SharedIdRequest, SharedIdStorage};
use trusted_server_core::ec::{EcContext, EcKvSnapshot, EidSyncSource};
use trusted_server_core::edge_app::install_edge_policies;
use trusted_server_core::error::{TrustedServerError, http_error, startup_error};
Expand Down Expand Up @@ -215,6 +216,8 @@ pub(crate) struct AppState {
pub(crate) page_identity: Option<Arc<ProviderCoordinator>>,
/// Coordinator for providers collected after the response, if any.
pub(crate) after_response_identity: Option<Arc<ProviderCoordinator>>,
/// Where Prebid keeps the `SharedID`, resolved once per sandbox.
pub(crate) sharedid_storage: SharedIdStorage,
}

impl AppState {
Expand Down Expand Up @@ -264,6 +267,8 @@ pub(crate) fn build_state_from_settings(
})?
.map(Arc::new);

let sharedid_storage = settings.sharedid_storage();

Ok(Arc::new(AppState {
settings: Arc::new(settings),
orchestrator: Arc::new(orchestrator),
Expand All @@ -272,6 +277,7 @@ pub(crate) fn build_state_from_settings(
partner_registry,
page_identity,
after_response_identity,
sharedid_storage,
}))
}

Expand Down Expand Up @@ -393,7 +399,7 @@ pub(crate) struct EcFinalizeState {
/// settings when this is set.
pub(crate) use_finalize_kv: bool,
pub(crate) eids_cookie: Option<String>,
pub(crate) sharedid_cookie: Option<String>,
pub(crate) sharedid: SharedIdRequest,
}

/// Identity lookups dispatched for this navigation, collected before finalize.
Expand Down Expand Up @@ -601,7 +607,7 @@ struct EcRequestState {
kv_graph: Option<KvIdentityGraph>,
finalize_kv_graph: Option<KvIdentityGraph>,
eids_cookie: Option<String>,
sharedid_cookie: Option<String>,
sharedid: SharedIdRequest,
is_real_browser: bool,
/// Geo lookup result reused by the pre-route request-filter step so it does
/// not repeat the lookup the legacy path also shares between EC setup and
Expand All @@ -620,7 +626,7 @@ impl EcRequestState {
ec_context: self.ec_context,
use_finalize_kv: self.finalize_kv_graph.is_some(),
eids_cookie: self.eids_cookie,
sharedid_cookie: self.sharedid_cookie,
sharedid: self.sharedid,
}
}
}
Expand Down Expand Up @@ -661,6 +667,7 @@ fn device_signals_for(req: &Request) -> DeviceSignals {
/// legacy `route_request` step by step.
fn build_ec_request_state(
settings: &Settings,
sharedid_storage: &SharedIdStorage,
services: &RuntimeServices,
req: &Request,
) -> EcRequestState {
Expand All @@ -676,7 +683,7 @@ fn build_ec_request_state(
}

let eids_cookie = crate::extract_cookie_value(req, COOKIE_TS_EIDS);
let sharedid_cookie = crate::extract_cookie_value(req, COOKIE_SHAREDID);
let sharedid = SharedIdRequest::from_request(sharedid_storage.cookie_name(), req);

let geo_info = services
.geo()
Expand Down Expand Up @@ -720,7 +727,7 @@ fn build_ec_request_state(
kv_graph,
finalize_kv_graph,
eids_cookie,
sharedid_cookie,
sharedid,
is_real_browser,
geo_info,
setup_error,
Expand Down Expand Up @@ -840,7 +847,9 @@ async fn execute_named(
let kv = crate::maybe_identity_graph(&state.settings);
handle_admin_ec_lookup(kv.as_ref(), &registry, &req).await
}
NamedRouteHandler::AdminEidsLookup => handle_admin_eids_lookup(&registry, &req),
NamedRouteHandler::AdminEidsLookup => {
handle_admin_eids_lookup(&registry, state.sharedid_storage.cookie_name(), &req)
}
_ => unreachable!("admin diagnostics should use early dispatch"),
}
.unwrap_or_else(|error| http_error(&error));
Expand All @@ -854,7 +863,7 @@ async fn execute_named(
return Ok(http_error(&report));
}

let mut ec = build_ec_request_state(&state.settings, &services, &req);
let mut ec = build_ec_request_state(&state.settings, &state.sharedid_storage, &services, &req);
apply_cookie_opt_outs(&state, &req, &mut ec);
// EcContext creation errors short-circuit before filters, mirroring legacy:
// the legacy path returns its error response before running filter_request.
Expand Down Expand Up @@ -996,7 +1005,7 @@ async fn run_named_route(
/// response finalization.
async fn run_batch_sync(state: &AppState, req: Request) -> Response {
let eids_cookie = crate::extract_cookie_value(&req, COOKIE_TS_EIDS);
let sharedid_cookie = crate::extract_cookie_value(&req, COOKIE_SHAREDID);
let sharedid = SharedIdRequest::from_request(state.sharedid_storage.cookie_name(), &req);

let identity_graph =
crate::maybe_identity_graph(&state.settings).filter(|_| req.method() == Method::POST);
Expand All @@ -1016,7 +1025,7 @@ async fn run_batch_sync(state: &AppState, req: Request) -> Response {
ec_context: EcContext::default(),
use_finalize_kv: false,
eids_cookie,
sharedid_cookie,
sharedid,
});
response
}
Expand Down Expand Up @@ -1049,7 +1058,7 @@ async fn dispatch_fallback(
return http_error(&report);
}

let mut ec = build_ec_request_state(&state.settings, services, &req);
let mut ec = build_ec_request_state(&state.settings, &state.sharedid_storage, services, &req);
apply_cookie_opt_outs(state, &req, &mut ec);
if let Some(report) = ec.setup_error.take() {
let response = http_error(&report);
Expand Down Expand Up @@ -2153,6 +2162,7 @@ mod tests {
partner_registry: Arc::new(PartnerRegistry::empty()),
page_identity: None,
after_response_identity: None,
sharedid_storage: trusted_server_core::ec::sharedid::SharedIdStorage::Unconfigured,
});
TrustedServerApp::routes_for_state(&state)
}
Expand Down Expand Up @@ -3616,7 +3626,7 @@ mod tests {
kv_graph: None,
finalize_kv_graph: None,
eids_cookie: None,
sharedid_cookie: None,
sharedid: super::SharedIdRequest::default(),
is_real_browser: true,
geo_info: None,
setup_error: None,
Expand Down Expand Up @@ -4104,6 +4114,51 @@ mod tests {
);
}

#[test]
fn ec_request_state_reads_the_configured_sharedid_cookie() {
let mut settings = test_settings();
settings
.integrations
.insert_config(
"prebid",
&serde_json::json!({
"enabled": true,
"external_bundle_url": "https://assets.example/prebid/trusted-prebid.js",
"bundle": { "modules": { "bidder": ["exampleBidderBidAdapter"] } },
"managed_user_ids": [
{ "name": "sharedId", "storage": { "type": "cookie", "name": "_pubcid" } }
],
}),
)
.expect("should configure Prebid");
let state = build_state_from_settings(settings).expect("should build app state");
let req = request_builder()
.method(Method::GET)
.uri("https://www.example.com/article")
.header(header::COOKIE, "sharedId=legacy-id; _pubcid=configured-id")
.body(Body::empty())
.expect("should build request");
let context = context_with_client(
empty_request(Method::GET, "/article"),
ScriptedHttpClient::forbidding().http_client(),
);
let services =
build_per_request_services(&state, &context).expect("should build request services");

let ec = super::build_ec_request_state(
&state.settings,
&state.sharedid_storage,
&services,
&req,
);

assert_eq!(
ec.sharedid.readable_value(),
Some("configured-id"),
"should read the cookie named by Prebid's storage.name, not `sharedId`"
);
}

#[test]
fn after_response_lookups_run_only_for_real_browsers() {
let mut settings = test_settings();
Expand Down Expand Up @@ -4142,7 +4197,12 @@ mod tests {
let services =
build_per_request_services(&state, &context).expect("should build request services");
let req = browser_request();
let mut ec = super::build_ec_request_state(&state.settings, &services, &req);
let mut ec = super::build_ec_request_state(
&state.settings,
&state.sharedid_storage,
&services,
&req,
);
assert!(
ec.is_real_browser,
"should classify the request as a browser"
Expand Down
4 changes: 2 additions & 2 deletions crates/trusted-server-adapter-fastly/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ async fn apply_edgezero_ec_finalize(
finalize_kv_graph.as_ref(),
&partner_registry,
ec_state.eids_cookie.as_deref(),
ec_state.sharedid_cookie.as_deref(),
&ec_state.sharedid,
response,
)
.await;
Expand Down Expand Up @@ -1486,7 +1486,7 @@ mod tests {
ec_context,
use_finalize_kv: false,
eids_cookie: None,
sharedid_cookie: None,
sharedid: trusted_server_core::ec::sharedid::SharedIdRequest::default(),
});

let state = finalize_response(&mut page, &inputs);
Expand Down
4 changes: 2 additions & 2 deletions crates/trusted-server-adapter-fastly/src/post_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ mod tests {
ec_context,
use_finalize_kv: false,
eids_cookie: None,
sharedid_cookie: None,
sharedid: trusted_server_core::ec::sharedid::SharedIdRequest::default(),
},
after_response: None,
}
Expand Down Expand Up @@ -446,7 +446,7 @@ mod tests {
Some(&kv),
&app.partner_registry,
None,
None,
&trusted_server_core::ec::sharedid::SharedIdRequest::default(),
&mut response,
));
state.partner_registry = app.partner_registry();
Expand Down
9 changes: 7 additions & 2 deletions crates/trusted-server-adapter-spin/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,13 @@ fn router_builder(state: &Arc<AppState>) -> RouterBuilder {
let s = Arc::clone(&s);
async move {
let req = ctx.into_request()?;
let result = PartnerRegistry::from_ec(&s.settings.ec)
.and_then(|registry| handle_admin_eids_lookup(&registry, &req));
let result = PartnerRegistry::from_ec(&s.settings.ec).and_then(|registry| {
handle_admin_eids_lookup(
&registry,
s.settings.sharedid_storage().cookie_name(),
&req,
)
});
Ok::<Response, EdgeError>(result.unwrap_or_else(|e| http_error(&e)))
}
};
Expand Down
Loading
Loading