From 4da025b199e3e78091aafa0b499c9358df74ae51 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 2 Dec 2026 16:41:07 +1300 Subject: [PATCH] Gallery: /g/ responses, errors included, send Cross-Origin-Resource-Policy: cross-origin as well as Access-Control-Allow-Origin: *, from the security headers middleware, so published screenshots load on sites with cross-origin isolation (COEP require-corp); nothing else sets either header; request tests for both --- server/frontend/content/docs/gallery.md | 2 +- server/src/controllers/gallery.rs | 2 -- server/src/security_headers.rs | 8 ++++++++ server/tests/requests/gallery.rs | 3 +++ server/tests/requests/hosts.rs | 19 +++++++++++++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/server/frontend/content/docs/gallery.md b/server/frontend/content/docs/gallery.md index 10a659d8..2ee24737 100644 --- a/server/frontend/content/docs/gallery.md +++ b/server/frontend/content/docs/gallery.md @@ -59,7 +59,7 @@ Always the approved version on the default branch: what the next build there wou The manifest changes only when an image does, so a site can build its own gallery from it. Light and dark, or phone and desktop, are separate screenshots with their own URLs; pairing them is up to your page. -Both URLs work from any site (`Access-Control-Allow-Origin: *`). They take no query parameters: anything else is a 404. +Both URLs work from any site (`Access-Control-Allow-Origin: *`), including one that turns on cross-origin isolation (`Cross-Origin-Resource-Policy: cross-origin`). They take no query parameters: anything else is a 404. ## Caching and cost diff --git a/server/src/controllers/gallery.rs b/server/src/controllers/gallery.rs index 0fa152a7..6347a2d0 100644 --- a/server/src/controllers/gallery.rs +++ b/server/src/controllers/gallery.rs @@ -101,7 +101,6 @@ async fn manifest( let mut r = Json(body).into_response(); let h = r.headers_mut(); h.insert(header::CACHE_CONTROL, HeaderValue::from_static(CACHE)); - h.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, HeaderValue::from_static("*")); Ok(r) } @@ -152,7 +151,6 @@ async fn image( h.insert(header::X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff")); h.insert(header::CONTENT_SECURITY_POLICY, HeaderValue::from_static("default-src 'none'; sandbox")); h.insert(header::CACHE_CONTROL, HeaderValue::from_static(CACHE)); - h.insert(header::ACCESS_CONTROL_ALLOW_ORIGIN, HeaderValue::from_static("*")); if let Ok(v) = HeaderValue::from_str(&etag) { h.insert(header::ETAG, v); } diff --git a/server/src/security_headers.rs b/server/src/security_headers.rs index be1cd9d5..28886fd8 100644 --- a/server/src/security_headers.rs +++ b/server/src/security_headers.rs @@ -30,6 +30,9 @@ const CLOUDFLARE_REPORT: &str = "https://cloudflareinsights.com"; static POLICY: OnceLock = OnceLock::new(); +const CROSS_ORIGIN_RESOURCE_POLICY: header::HeaderName = + header::HeaderName::from_static("cross-origin-resource-policy"); + /// `'sha256-…'` for each inline `