| @@ -102,6 +102,17 @@ const SECURITY: [(header::HeaderName, &str); 4] = [ |
| | (header::CACHE_CONTROL, "no-store"), |
| | ]; |
| | |
| | /// Headers for a raw file, which is repository content served from this site's own origin. |
| | /// The sandbox makes a file opened directly (an SVG, say) a unique origin with no scripts, so |
| | /// even a policy mistake can't let it act as the signed-in visitor. Inline styles are allowed |
| | /// so SVGs draw as their authors meant; nothing may load from anywhere. |
| | const RAW_SECURITY: [(header::HeaderName, &str); 4] = [ |
| | (header::CONTENT_SECURITY_POLICY, "sandbox; default-src 'none'; style-src 'unsafe-inline'; img-src data:"), |
| | (header::X_CONTENT_TYPE_OPTIONS, "nosniff"), |
| | (header::REFERRER_POLICY, "no-referrer"), |
| | (header::CACHE_CONTROL, "no-store"), |
| | ]; |
| | |
| | impl View { |
| | /// The response for `visitor`, who may need a download slot for a raw file. |
| | async fn response(self, visitor: Visitor) -> Response { |
| @@ -155,13 +166,13 @@ async fn raw_response(visitor: Visitor, command: std::process::Command, size: us |
| | Some("jpg" | "jpeg") => "image/jpeg", |
| | Some("gif") => "image/gif", |
| | Some("webp") => "image/webp", |
| | // Safe to serve as an image: the page's policy blocks any script inside it. |
| | // Safe to serve as an image: the sandbox (see RAW_SECURITY) blocks any script inside it. |
| | Some("svg") => "image/svg+xml", |
| | _ if binary => "application/octet-stream", |
| | _ => "text/plain; charset=utf-8", |
| | }; |
| | let body = output.body(prefix, None, permit, std::time::Duration::from_secs(300)); |
| | let mut response = (SECURITY, [(header::CONTENT_TYPE, kind)], body).into_response(); |
| | let mut response = (RAW_SECURITY, [(header::CONTENT_TYPE, kind)], body).into_response(); |
| | response.headers_mut().insert(header::CONTENT_LENGTH, size.into()); |
| | if kind == "application/octet-stream" |
| | && let Ok(value) = format!("attachment; filename*=UTF-8''{}", encode(&name)).parse() |