diff --git a/backend/windmill-api/src/lib.rs b/backend/windmill-api/src/lib.rs index ee03ff1825..7c274af630 100644 --- a/backend/windmill-api/src/lib.rs +++ b/backend/windmill-api/src/lib.rs @@ -238,6 +238,7 @@ lazy_static::lazy_static! { } + // Compliance with cloud events spec. pub async fn add_webhook_allowed_origin( req: axum::extract::Request, @@ -260,6 +261,7 @@ pub async fn add_webhook_allowed_origin( next.run(req).await } + #[cfg(not(feature = "tantivy"))] type IndexReader = (); diff --git a/backend/windmill-api/src/static_assets.rs b/backend/windmill-api/src/static_assets.rs index d5656fb6c1..48bd94081c 100644 --- a/backend/windmill-api/src/static_assets.rs +++ b/backend/windmill-api/src/static_assets.rs @@ -10,6 +10,8 @@ use axum::{body::Body, extract::OriginalUri, http::Response, response::IntoRespo #[cfg(feature = "static_frontend")] use axum::http::header; +#[cfg(feature = "static_frontend")] +use http::HeaderValue; use hyper::Uri; #[cfg(feature = "static_frontend")] @@ -17,6 +19,12 @@ use mime_guess::mime; #[cfg(feature = "static_frontend")] use rust_embed::RustEmbed; +// Content Security Policy configuration +#[cfg(feature = "static_frontend")] +lazy_static::lazy_static! { + static ref CSP_POLICY: String = std::env::var("CSP_POLICY").unwrap_or_default(); +} + // static_handler is a handler that serves static files from the pub async fn static_handler(OriginalUri(original_uri): OriginalUri) -> StaticFile { StaticFile(original_uri) @@ -51,6 +59,13 @@ fn serve_path(path: &str) -> Response { let mut res = Response::builder() .header(header::CONTENT_TYPE, mime.as_ref()) .header(header::ACCESS_CONTROL_ALLOW_ORIGIN, "*"); + + // Add Content-Security-Policy header for static assets when policy is set + if !CSP_POLICY.is_empty() { + if let Ok(header_value) = HeaderValue::try_from(CSP_POLICY.as_str()) { + res = res.header("Content-Security-Policy", header_value); + } + } if mime.as_ref() == mime::APPLICATION_JAVASCRIPT || mime.as_ref() == mime::TEXT_JAVASCRIPT || path.ends_with(".wasm")