Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
ff782e0
Quantize auction transport timeouts to stabilize Fastly backend names
prk-Jr Jul 8, 2026
35e872b
Stream publisher origin bodies end-to-end on Fastly
prk-Jr Jul 8, 2026
affb46c
Harden the streaming publisher pipeline after review
prk-Jr Jul 8, 2026
2c64f3c
Emit processor_init_error telemetry on streaming finalize failure
prk-Jr Jul 8, 2026
b95813c
Fix Prebid User ID diagnostics
ChristianPavilonis Jul 10, 2026
e94430e
Order Prebid imports for lint
ChristianPavilonis Jul 10, 2026
b56adcb
Preserve vendor-specific OpenRTB atype values
ChristianPavilonis Jul 10, 2026
b52b415
Dump full SSAT prebid responses in ts-debug auction comment
prk-Jr Jul 10, 2026
48db8bf
Surface prebid HTTP error status and body in auction dump
prk-Jr Jul 10, 2026
08de9c4
Merge branch 'main' into feat/ssat-write-prebid-response-debug
prk-Jr Jul 10, 2026
d5871da
Stop leaking prebid error body into the public auction response
prk-Jr Jul 13, 2026
1cb8adf
Merge remote-tracking branch 'origin/feat/ssat-write-prebid-response-…
prk-Jr Jul 13, 2026
b577451
Merge branch 'main' into streaming-pipeline-async-core
aram356 Jul 13, 2026
4e8e3bf
Merge branch 'main' into quantize-auction-transport-timeouts
aram356 Jul 13, 2026
b56a0a1
Add design spec for SSAT inline creative rendering
prk-Jr Jul 13, 2026
6e8c48f
Add implementation plan for SSAT inline creative rendering
prk-Jr Jul 13, 2026
16e9d95
Correct plan call graph, add TsjsApi type + beacon steps, note precon…
prk-Jr Jul 13, 2026
34018e4
Revise SSAT inline-creative plan/spec per review
prk-Jr Jul 13, 2026
a1b844d
Refine plan test details per second review
prk-Jr Jul 13, 2026
6649875
Always include adm in bid map; gate only debug_bid blob
prk-Jr Jul 13, 2026
e2b13bb
Gate GAM-bypass adm injection on per-bid debug_bid
prk-Jr Jul 13, 2026
cb60fd2
Apply prettier formatting to spec/plan docs
prk-Jr Jul 13, 2026
c8ae53f
Harden Fastly publisher streaming against review findings
prk-Jr Jul 14, 2026
5512d85
Address auction transport-timeout review findings
prk-Jr Jul 14, 2026
62a2dd0
Add Prebid error diagnostics
ChristianPavilonis Jul 10, 2026
ef61953
Suppress fabricated empty Prebid bidder params
prk-Jr Jul 14, 2026
0acac4b
Preserve Prebid ad units across GPT refreshes
ChristianPavilonis Jul 14, 2026
c59a064
Handle deferred Prebid delivery refreshes
ChristianPavilonis Jul 14, 2026
310e62f
Use HTTP status error type for Prebid failures
ChristianPavilonis Jul 14, 2026
641e512
Merge remote-tracking branch 'origin/feat/ssat-write-prebid-response-…
ChristianPavilonis Jul 15, 2026
e93de21
Merge remote-tracking branch 'origin/add-prebid-error-diagnostics' in…
ChristianPavilonis Jul 15, 2026
af6367a
Merge remote-tracking branch 'origin/feat/ssat-render-inline-creative…
ChristianPavilonis Jul 15, 2026
e6d8d83
Merge remote-tracking branch 'origin/fix/prebid-suppress-empty-bidder…
ChristianPavilonis Jul 15, 2026
e80c164
Merge remote-tracking branch 'origin/fix/prebid-refresh-auctions' int…
ChristianPavilonis Jul 15, 2026
1159407
Merge branch 'main' into feat/ssat-render-inline-creative
prk-Jr Jul 15, 2026
6b4e82e
Make auction creative rewriting optional
ChristianPavilonis Jul 15, 2026
1ccf3fa
Merge remote-tracking branch 'origin/feature/optional-creative-rewrit…
ChristianPavilonis Jul 15, 2026
2aa2a9e
Improve APS auction diagnostics
ChristianPavilonis Jul 15, 2026
ba3bad9
Log APS responses in test environment
ChristianPavilonis Jul 15, 2026
1610e9d
Add first-class APS OpenRTB integration
ChristianPavilonis Jul 16, 2026
26afb47
Merge APS OpenRTB integration for deployment testing
ChristianPavilonis Jul 16, 2026
eb8f37c
Resolve APS test scanning alerts
ChristianPavilonis Jul 16, 2026
43ac72a
Merge APS scan alert fixes
ChristianPavilonis Jul 16, 2026
1c98302
Run SSAT inline creative through the sanitize/rewrite boundary and de…
prk-Jr Jul 16, 2026
e87b6e6
Merge branch 'main' into streaming-pipeline-async-core
prk-Jr Jul 16, 2026
e80cbb7
Flush streaming body encoder per chunk so output decodes before finish
prk-Jr Jul 16, 2026
5cdaf3d
Stream the ready prefix before collecting the held auction
prk-Jr Jul 16, 2026
43499f8
Correct Content-Length framing for bodiless 204/205 responses
prk-Jr Jul 16, 2026
0976cfb
Emit abandoned-auction telemetry for bodiless dispatched responses
prk-Jr Jul 16, 2026
5d6fc21
Apply rustfmt after the edition-2024 merge
prk-Jr Jul 16, 2026
4828512
Harden Fastly backend naming and transport-timeout quantization
prk-Jr Jul 16, 2026
baddbdc
Merge remote-tracking branch 'origin/main' into quantize-auction-tran…
prk-Jr Jul 16, 2026
1569a06
Log APS responses at info level
ChristianPavilonis Jul 16, 2026
77f3521
Update predict_name tests for digest-based backend names
prk-Jr Jul 16, 2026
1923031
logs and whatnot
ChristianPavilonis Jul 16, 2026
954b799
Merge pull request #865 from IABTechLab/quantize-auction-transport-ti…
ChristianPavilonis Jul 16, 2026
5bbb8f6
Merge pull request #867 from IABTechLab/streaming-pipeline-async-core
ChristianPavilonis Jul 16, 2026
a241166
Merge branch 'main' into fix-prebid-user-id-diagnostics
aram356 Jul 16, 2026
6381ac5
Merge pull request #887 from IABTechLab/fix-prebid-user-id-diagnostics
ChristianPavilonis Jul 16, 2026
b3f5b11
Add APS inventory identity overrides
ChristianPavilonis Jul 16, 2026
397a4d6
Trace winning auction bids to rendered creatives on the page
prk-Jr Jul 16, 2026
cdd4d07
Merge APS OpenRTB integration
ChristianPavilonis Jul 16, 2026
9f898e2
Render APS bids from the trustedServer Prebid adapter
ChristianPavilonis Jul 16, 2026
96fec88
Merge APS Prebid adapter rendering fix into July RC
ChristianPavilonis Jul 16, 2026
d0b18b4
Emit absolute first-party URLs for inline SSAT creatives
prk-Jr Jul 17, 2026
58706b4
Merge pull request #922 from IABTechLab/trace-auction-winners-to-crea…
ChristianPavilonis Jul 17, 2026
b96a7ec
Fix release candidate CI
ChristianPavilonis Jul 17, 2026
7f448bc
Add APS auction debug metadata
ChristianPavilonis Jul 17, 2026
5c40c6e
Merge branch 'issue-764-aps-openrtb' into rc/july
ChristianPavilonis Jul 17, 2026
e55d985
Preserve Prebid bidder parameter string types
ChristianPavilonis Jul 18, 2026
5eef5f1
Satisfy Clippy for override normalization
ChristianPavilonis Jul 18, 2026
76dd06b
Merge branch 'main' into feat/ssat-render-inline-creative
aram356 Jul 19, 2026
5d7f696
Fix ext.trusted_server.request_host to use the publisher domain
prk-Jr Jul 20, 2026
0807060
Merge branch preserve-prebid-bid-param-string-types into rc/july
ChristianPavilonis Jul 20, 2026
9f042f7
Resolve publisher test merge conflict
ChristianPavilonis Jul 20, 2026
d8961fa
Merge branch 'fix/auction-request-host' into rc/july
prk-Jr Jul 20, 2026
cd57004
Use configured publisher domain for navigation-path auction requests
aram356 Jul 20, 2026
65c34a6
Merge PR #937 (configured publisher domain for navigation-path auctio…
aram356 Jul 20, 2026
e7f7e17
Merge branch 'main' into fix/auction-request-publisher-host
prk-Jr Jul 21, 2026
bad87ae
Merge branch 'main' into feat/ssat-render-inline-creative
prk-Jr Jul 21, 2026
b2e736e
Resolve pbRender bid by requesting slot, not first hb_adid match
prk-Jr Jul 21, 2026
d97ac1d
Size inline creative render from the winning bid dimensions
prk-Jr Jul 21, 2026
f0f4a7f
Expand ${AUCTION_PRICE} before rewriting inline creatives
prk-Jr Jul 21, 2026
d0e00a6
Build inline creative URLs from the request origin
prk-Jr Jul 21, 2026
3a7e7e2
Preserve cached bid dimensions and price in the PBS Cache fallback
prk-Jr Jul 21, 2026
395abd6
Reconcile SSAT inline-creative design and plan with implementation
prk-Jr Jul 21, 2026
ebd23b2
Allow too_many_arguments on collect_stream_auction
prk-Jr Jul 21, 2026
44c2bb8
Omit zero creative dimensions so the bridge falls back
prk-Jr Jul 21, 2026
f4e0a79
Scope the pbRender in-flight guard to the slot, not the bare adId
prk-Jr Jul 21, 2026
6a1db09
Fix React #418 hydration mismatch from ad-slot injection on Next.js A…
aram356 Jul 21, 2026
41345fc
Merge branch 'main' into rc/july
aram356 Jul 21, 2026
eaa8fed
Merge PR #945 (React #418 hydration mismatch fixes) into rc/july
aram356 Jul 21, 2026
d4131c5
Merge feat/ssat-render-inline-creative into rc/july
prk-Jr Jul 21, 2026
3ebcf8f
Defer initial adInit until after React hydration on Next.js App Router
aram356 Jul 21, 2026
ea2ab5e
Revert "Merge PR #945 (React #418 hydration mismatch fixes) into rc/j…
aram356 Jul 21, 2026
6fb5426
Merge remote-tracking branch 'origin/fix/react418-hydration-safety' i…
aram356 Jul 21, 2026
436a932
Detect GPT initial load configuration
ChristianPavilonis Jul 22, 2026
26fdfe8
Merge branch 'fix/gpt-set-config-initial-load-detection' into rc/july
ChristianPavilonis Jul 22, 2026
4a020e2
Attribute navigation auction telemetry to the configured publisher do…
aram356 Jul 22, 2026
66bc16f
Merge PR #937 follow-up (navigation telemetry publisher domain) into …
aram356 Jul 22, 2026
123393b
Merge main into rc/july after PR #937 landed
aram356 Jul 22, 2026
be02574
Document SSAT root document 304 prevention
prk-Jr Jul 22, 2026
19c3a25
Clarify unexpected origin 304 telemetry
prk-Jr Jul 22, 2026
1eb09cb
Plan SSAT root document 304 prevention
prk-Jr Jul 22, 2026
3360e6a
Handle oversized HEAD response metadata
ChristianPavilonis Jul 22, 2026
8bdbd61
Add platform HTTP cache bypass option
prk-Jr Jul 22, 2026
87f9319
Merge branch 'fix/head-content-length-limit' into rc/july
ChristianPavilonis Jul 22, 2026
15f4565
Bypass Fastly cache for marked HTTP requests
prk-Jr Jul 22, 2026
92f4169
Prevent SSAT publisher document revalidation
prk-Jr Jul 22, 2026
fc5611a
Reject unexpected SSAT origin 304 responses
prk-Jr Jul 22, 2026
79f6053
Format SSAT 304 implementation plan
prk-Jr Jul 22, 2026
28dd578
Merge branch 'fix/ssat-root-document-304' into rc/july
prk-Jr Jul 22, 2026
78bb93e
Make creative sanitization opt-in and restore creative iframe origin …
aram356 Jul 22, 2026
f59fd85
Add gam_unit_path template parser
prk-Jr Jul 23, 2026
9a71f55
Add request-path section derivation
prk-Jr Jul 23, 2026
7575873
Add section_root, unit-template compile/render, and startup validation
prk-Jr Jul 23, 2026
860ed0b
Render gam_unit_path template per request across initial and SPA paths
prk-Jr Jul 23, 2026
21a3523
Add spec and plan for per-section gam_unit_path
prk-Jr Jul 23, 2026
070fd94
Document per-section gam_unit_path templating
prk-Jr Jul 23, 2026
20f5f8e
Use fictional example values in tests and docs
prk-Jr Jul 23, 2026
dbdaea7
Merge branch 'main' into 954-per-section-gam-unit-path
prk-Jr Jul 23, 2026
3df591f
Revert "Merge pull request #922 from IABTechLab/trace-auction-winners…
ChristianPavilonis Jul 23, 2026
050ad9c
Add privacy-safe auction-to-creative tracing
ChristianPavilonis Jul 23, 2026
fd1cbd8
Clarify auction trace console evidence
ChristianPavilonis Jul 23, 2026
423e6c5
Trace publisher-owned GPT slot lifecycles
ChristianPavilonis Jul 23, 2026
653ae8a
Harden trace console lifecycle diagnostics
ChristianPavilonis Jul 24, 2026
2d0c4f7
Merge branch 'main' of github.com:IABTechLab/trusted-server into rc/july
ChristianPavilonis Jul 24, 2026
77ad775
Register APS renderer via requestId so it survives Prebid field strip…
aram356 Jul 24, 2026
2d2f657
Format docs/guide/configuration.md with Prettier
aram356 Jul 24, 2026
f0a275b
Address review feedback on gam_unit_path templating
prk-Jr Jul 24, 2026
bfc1cb9
Merge remote-tracking branch 'origin/954-per-section-gam-unit-path' i…
prk-Jr Jul 24, 2026
1199471
Merge remote-tracking branch 'origin/954-per-section-gam-unit-path' i…
prk-Jr Jul 24, 2026
a07edd2
Exclude GAM paths from Prebid refresh auctions
ChristianPavilonis Jul 24, 2026
76c5626
Prevent duplicate GPT slot requests
ChristianPavilonis Jul 24, 2026
8932cb9
Merge branch 'fix/duplicate-gpt-slots' into rc/july
ChristianPavilonis Jul 24, 2026
b65e1ae
Gate publisher GPT requests until targeting is ready
ChristianPavilonis Jul 24, 2026
7de7aad
Merge branch 'fix/duplicate-gpt-slots' into rc/july
ChristianPavilonis Jul 24, 2026
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
29 changes: 29 additions & 0 deletions .github/actions/setup-integration-test-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ runs:
TRUSTED_SERVER__PROXY__CERTIFICATE_CHECK: "false"
run: cargo build -p trusted-server-adapter-axum

- name: Set up Node.js for browser fixtures
if: ${{ inputs.build-test-images == 'true' }}
uses: actions/setup-node@v4
with:
node-version: ${{ steps.node-version.outputs.node-version }}
cache: npm
cache-dependency-path: crates/trusted-server-js/lib/package-lock.json

- name: Build external Prebid fixture bundle
if: ${{ inputs.build-test-images == 'true' }}
shell: bash
run: |
rm -rf "$GITHUB_WORKSPACE/target/integration-test-artifacts/prebid"
mkdir -p "$GITHUB_WORKSPACE/target/integration-test-artifacts/prebid"
npm ci --prefix crates/trusted-server-js/lib
npm run --prefix crates/trusted-server-js/lib build:prebid-external -- \
--adapters=rubicon \
--user-id-modules=sharedIdSystem \
--out "$GITHUB_WORKSPACE/target/integration-test-artifacts/prebid"

- name: Build WordPress test container
if: ${{ inputs.build-test-images == 'true' }}
shell: bash
Expand All @@ -109,6 +129,15 @@ runs:
-t test-nextjs:latest \
crates/trusted-server-integration-tests/fixtures/frameworks/nextjs/

- name: Build ad-trace test container
if: ${{ inputs.build-test-images == 'true' }}
shell: bash
run: |
docker build \
-f crates/trusted-server-integration-tests/fixtures/frameworks/ad-trace/Dockerfile \
-t test-ad-trace:latest \
.

- name: Add wasm32-unknown-unknown target for Cloudflare build
if: ${{ inputs.build-cloudflare == 'true' }}
shell: bash
Expand Down
34 changes: 31 additions & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
cp -r crates/trusted-server-adapter-cloudflare/build/. "$CF_BUILD_ARTIFACT_PATH/"
docker save \
--output "$DOCKER_ARTIFACT_PATH" \
test-wordpress:latest test-nextjs:latest
test-ad-trace:latest test-wordpress:latest test-nextjs:latest

- name: Upload integration test artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -183,7 +183,16 @@ jobs:
with:
node-version: ${{ steps.shared-setup.outputs.node-version }}
cache: npm
cache-dependency-path: crates/trusted-server-integration-tests/browser/package-lock.json
cache-dependency-path: |
crates/trusted-server-integration-tests/browser/package-lock.json
crates/trusted-server-js/lib/package-lock.json

- name: Build TSJS browser fixtures
working-directory: crates/trusted-server-js/lib
run: |
npm ci
npm run build
npm run build:prebid-external

- name: Install Playwright
working-directory: crates/trusted-server-integration-tests/browser
Expand Down Expand Up @@ -228,10 +237,29 @@ jobs:
path: crates/trusted-server-integration-tests/browser/playwright-report-wordpress/
retention-days: 7

- name: Run browser tests (ad trace contract)
if: always()
working-directory: crates/trusted-server-integration-tests/browser
env:
WASM_BINARY_PATH: ${{ env.WASM_ARTIFACT_PATH }}
INTEGRATION_ORIGIN_PORT: ${{ env.ORIGIN_PORT }}
VICEROY_CONFIG_PATH: ${{ env.ARTIFACTS_DIR }}/configs/viceroy-ad-trace.toml
TEST_FRAMEWORK: ad-trace
PLAYWRIGHT_HTML_REPORT: playwright-report-ad-trace
run: npx playwright test tests/ad-trace/auction-trace.spec.ts

- name: Upload Playwright report (ad trace contract)
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report-ad-trace
path: crates/trusted-server-integration-tests/browser/playwright-report-ad-trace/
retention-days: 7

- name: Upload Playwright traces and screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-traces
path: crates/trusted-server-integration-tests/browser/test-results/
path: crates/trusted-server-integration-tests/browser/test-results-*/
retention-days: 7
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **Breaking** — Replaced the legacy APS contextual integration with APS OpenRTB at `/e/pb/bid`. APS configuration now uses canonical `account_id` (`pub_id` remains a compatibility alias), no longer requires APS-specific slot IDs, and defaults script creative eligibility off. Operators must update the endpoint, disable native APS demand for Trusted Server cohorts, and prepare GAM/Universal Creative targeting for `hb_bidder=aps` before rollout.
- **Breaking** — `bid_param_zone_overrides` inner values must now be JSON objects; previously non-object or empty values (`"header" = "x"`, `"header" = {}`) were accepted and silently produced a dead rule at runtime. They now fail at startup with a configuration error. Operators upgrading should audit their `bid_param_zone_overrides` config for non-object zone entries.
- **Breaking** — Sourcepoint browser module inclusion now requires explicit `[integrations.sourcepoint].enabled = true`; operators relying on the previous unconditional Sourcepoint module should enable the integration before upgrading.
- Added optional APS `inventory_domain` and `inventory_page_origin` overrides for deployments whose edge hostname differs from the APS-authorized inventory identity.
- Preserved APS renderer capabilities through the client-side `trustedServer` Prebid adapter, allowing its generated `hb_adid` to render through GAM and Prebid Universal Creative instead of producing an empty creative.

### Security

- Validate synthetic ID format on inbound values from the `x-synthetic-id` header and `synthetic_id` cookie; values that do not match the expected format (`64-hex-hmac.6-alphanumeric-suffix`) are discarded and a fresh ID is generated rather than forwarded to response headers, cookies, or third-party APIs

### Added

- Added opt-in APS HTTP debug metadata for controlled test sites, exposing the direct request and response under `/auction` provider metadata using the Prebid Server `debug.httpcalls` shape.
- Added the default-true `[auction].rewrite_creatives` option. Setting it to `false` preserves mandatory `/auction` creative sanitization while skipping first-party resource/click URL rewriting and creative TSJS injection.
- Added typed APS renderer transport for direct auctions and GAM/Prebid Universal Creative, using a minimized one-bid envelope, a fragment-bound nonce, and an opaque sandboxed renderer endpoint.
- Added Osano consent mirror integration docs and public enablement guidance.
- Implemented basic authentication for configurable endpoint paths (#73)
- Added integrations guide with example `testlight` integration
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ version = "0.1.0"

[workspace.dependencies]
anyhow = "1"
async-stream = "0.3"
async-trait = "0.1"
axum = "0.8"
base64 = "0.22"
Expand Down
5 changes: 3 additions & 2 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ INFO: Running 2 bidders in parallel
INFO: Requesting bids from: prebid
INFO: Prebid returned 2 bids (time: 120ms)
INFO: Requesting bids from: aps
INFO: APS (MOCK): returning 2 bids in 80ms
INFO: GAM mediation: slot 'header-banner' won by 'amazon-aps' at $2.50 CPM
INFO: APS requests bids for 2 impressions
INFO: APS returns 2 accepted bids in 80ms
INFO: GAM mediation: slot 'header-banner' won by 'aps' at $2.50 CPM
```

### Verify Provider Registration
Expand Down
3 changes: 2 additions & 1 deletion crates/trusted-server-adapter-axum/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use trusted_server_core::settings_data::{

use trusted_server_core::platform::RuntimeServices;

use crate::middleware::{AuthMiddleware, FinalizeResponseMiddleware};
use crate::middleware::{AdTracePrepareMiddleware, AuthMiddleware, FinalizeResponseMiddleware};
use crate::platform::{AxumPlatformConfigStore, build_runtime_services};

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -540,6 +540,7 @@ fn build_router(state: &Arc<AppState>) -> RouterService {

let mut router = RouterService::builder()
.middleware(FinalizeResponseMiddleware::new(Arc::clone(&state.settings)))
.middleware(AdTracePrepareMiddleware::new(Arc::clone(&state.settings)))
.middleware(AuthMiddleware::new(Arc::clone(&state.settings)));

router = router.route("/health", Method::GET, |_ctx: RequestContext| async {
Expand Down
46 changes: 46 additions & 0 deletions crates/trusted-server-adapter-axum/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use edgezero_core::context::RequestContext;
use edgezero_core::error::EdgeError;
use edgezero_core::http::{HeaderValue, Response};
use edgezero_core::middleware::{Middleware, Next};
use edgezero_core::response::IntoResponse;
use trusted_server_core::auth::enforce_basic_auth;
use trusted_server_core::constants::HEADER_X_GEO_INFO_AVAILABLE;
use trusted_server_core::settings::Settings;
Expand Down Expand Up @@ -38,6 +39,51 @@ impl Middleware for FinalizeResponseMiddleware {
async fn handle(&self, ctx: RequestContext, next: Next<'_>) -> Result<Response, EdgeError> {
let mut response = next.run(ctx).await?;
apply_finalize_headers(&self.settings, &mut response);
trusted_server_core::integrations::ad_trace::finalize_response(&mut response);
Ok(response)
}
}

// ---------------------------------------------------------------------------
// AdTracePrepareMiddleware
// ---------------------------------------------------------------------------

/// Prepares and sanitizes the request before auth, routing, or downstream use.
pub struct AdTracePrepareMiddleware {
settings: Arc<Settings>,
}

impl AdTracePrepareMiddleware {
#[must_use]
pub fn new(settings: Arc<Settings>) -> Self {
Self { settings }
}
}

#[async_trait(?Send)]
impl Middleware for AdTracePrepareMiddleware {
async fn handle(&self, mut ctx: RequestContext, next: Next<'_>) -> Result<Response, EdgeError> {
let decision = match trusted_server_core::integrations::ad_trace::prepare_request(
&self.settings,
ctx.request_mut(),
) {
Ok(decision) => decision,
Err(report) => {
log::error!("ad trace request preparation failed: {report:?}");
return Ok(crate::app::http_error(&report));
}
};
let mut response = match next.run(ctx).await {
Ok(response) => response,
Err(error) => {
log::error!("request handler failed after ad trace preparation: {error:?}");
error.into_response()?
}
};
trusted_server_core::integrations::ad_trace::attach_response_decision(
&decision,
&mut response,
);
Ok(response)
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/trusted-server-adapter-cloudflare/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use trusted_server_core::request_signing::{
};
use trusted_server_core::settings::Settings;

use crate::middleware::{AuthMiddleware, FinalizeResponseMiddleware};
use crate::middleware::{AdTracePrepareMiddleware, AuthMiddleware, FinalizeResponseMiddleware};
use crate::platform::build_runtime_services;

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -432,6 +432,7 @@ fn build_router(state: &Arc<AppState>) -> RouterService {

let mut router = RouterService::builder()
.middleware(FinalizeResponseMiddleware::new(Arc::clone(&state.settings)))
.middleware(AdTracePrepareMiddleware::new(Arc::clone(&state.settings)))
.middleware(AuthMiddleware::new(Arc::clone(&state.settings)))
.get(
"/.well-known/trusted-server.json",
Expand Down
45 changes: 45 additions & 0 deletions crates/trusted-server-adapter-cloudflare/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use edgezero_core::context::RequestContext;
use edgezero_core::error::EdgeError;
use edgezero_core::http::{HeaderValue, Response};
use edgezero_core::middleware::{Middleware, Next};
use edgezero_core::response::IntoResponse;
use trusted_server_core::auth::enforce_basic_auth;
use trusted_server_core::constants::HEADER_X_GEO_INFO_AVAILABLE;
use trusted_server_core::settings::Settings;
Expand Down Expand Up @@ -46,6 +47,50 @@ impl Middleware for FinalizeResponseMiddleware {

let mut response = next.run(ctx).await?;
apply_finalize_headers(&self.settings, geo_available, &mut response);
trusted_server_core::integrations::ad_trace::finalize_response(&mut response);
Ok(response)
}
}

// ---------------------------------------------------------------------------
// AdTracePrepareMiddleware
// ---------------------------------------------------------------------------

pub struct AdTracePrepareMiddleware {
settings: Arc<Settings>,
}

impl AdTracePrepareMiddleware {
#[must_use]
pub fn new(settings: Arc<Settings>) -> Self {
Self { settings }
}
}

#[async_trait(?Send)]
impl Middleware for AdTracePrepareMiddleware {
async fn handle(&self, mut ctx: RequestContext, next: Next<'_>) -> Result<Response, EdgeError> {
let decision = match trusted_server_core::integrations::ad_trace::prepare_request(
&self.settings,
ctx.request_mut(),
) {
Ok(decision) => decision,
Err(report) => {
log::error!("ad trace request preparation failed: {report:?}");
return Ok(crate::app::http_error(&report));
}
};
let mut response = match next.run(ctx).await {
Ok(response) => response,
Err(error) => {
log::error!("request handler failed after ad trace preparation: {error:?}");
error.into_response()?
}
};
trusted_server_core::integrations::ad_trace::attach_response_decision(
&decision,
&mut response,
);
Ok(response)
}
}
Expand Down
Loading
Loading