diff --git a/src/routes/media.rs b/src/routes/media.rs index f1e894c..a4787c5 100644 --- a/src/routes/media.rs +++ b/src/routes/media.rs @@ -26,6 +26,39 @@ static MEDIA_REF: LazyLock = LazyLock::new(|| { .expect("static regex is valid") }); +/// An upload is attacker-controlled content served from our own origin, so the +/// browser is only ever told it is a type that cannot execute script. Anything +/// else — `text/html`, `image/svg+xml`, an unrecognised type — is stored and +/// served as an opaque download instead. +fn sanitize_mime(raw: &str) -> String { + let base = raw + .split(';') + .next() + .unwrap_or_default() + .trim() + .to_ascii_lowercase(); + + let (top, sub) = base.split_once('/').unwrap_or_default(); + let inlineable = match top { + // SVG is a document: it can carry