diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d352978..b57100d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixed +- Refuse a burn-after-reading paste on `/raw` and `/dl` instead of destroying + it on a plain GET that any link preview, prefetch or embedded image can send. - Reject off-origin and scheme-relative `Referer` values when redirecting back after a theme change, closing an open-redirect bypass via `//`-prefixed paths. - Unlink Unix domain socket after shutdown. diff --git a/crates/wastebin_server/src/errors.rs b/crates/wastebin_server/src/errors.rs index e4ed6421..effc9330 100644 --- a/crates/wastebin_server/src/errors.rs +++ b/crates/wastebin_server/src/errors.rs @@ -26,6 +26,9 @@ pub(crate) enum Error { Id(#[from] id::Error), #[error("payload too large")] MalformedForm, + /// A burn-after-reading paste was asked for on a route that cannot confirm the destruction. + #[error("burn-after-reading paste needs confirmation")] + BurnNotConfirmed, } #[derive(Serialize)] @@ -46,6 +49,7 @@ impl From for StatusCode { Error::Database(db::Error::NoPassword) | Error::Id(_) | Error::UrlParsing(_) => { StatusCode::BAD_REQUEST } + Error::BurnNotConfirmed => StatusCode::FORBIDDEN, Error::MalformedForm => StatusCode::UNPROCESSABLE_ENTITY, Error::Join(_) | Error::QrCode(_) diff --git a/crates/wastebin_server/src/handlers/download.rs b/crates/wastebin_server/src/handlers/download.rs index 1f4b1720..0f7852c1 100644 --- a/crates/wastebin_server/src/handlers/download.rs +++ b/crates/wastebin_server/src/handlers/download.rs @@ -27,6 +27,11 @@ pub async fn get( let key: Key = id.parse()?; let password = password.map(|Password(password)| password); + // A download is a GET with no way to confirm the destruction; see `raw::get`. + if db.get_metadata(key.id).await?.must_be_deleted { + return Err(crate::Error::BurnNotConfirmed); + } + match db.get(key.id, password).await { Ok(Entry::Regular(data) | Entry::Burned(data)) => { Ok(get_download(&key, data).into_response()) diff --git a/crates/wastebin_server/src/handlers/html/burn.rs b/crates/wastebin_server/src/handlers/html/burn.rs index 0ee458b0..1eeac867 100644 --- a/crates/wastebin_server/src/handlers/html/burn.rs +++ b/crates/wastebin_server/src/handlers/html/burn.rs @@ -272,4 +272,47 @@ mod tests { Ok(()) } + + /// `/raw` and `/dl` destroyed a burn paste on a plain GET, so anything that merely follows a + /// URL consumed it: a link unfurler, a prefetch, or an `` on any page — including a + /// rendered Markdown paste, whose CSP permits images, holding `![](/raw/OTHER_ID)`. + #[tokio::test] + async fn a_get_on_raw_or_download_does_not_burn() -> Result<(), Box> { + for route in ["raw", "dl"] { + let client = Client::new(StoreCookies(false)).await; + let data = Entry { + text: String::from("secret-body-xyz"), + burn_after_reading: Some(String::from("on")), + ..Default::default() + }; + + let res = client.post_form().form(&data).send().await?; + assert_eq!(res.status(), StatusCode::SEE_OTHER); + + let location = res + .headers() + .get("location") + .unwrap() + .to_str()? + .replace("burn/", ""); + + let res = client.get(&format!("/{route}{location}")).send().await?; + assert_eq!(res.status(), StatusCode::FORBIDDEN, "/{route}"); + assert!( + !res.text().await?.contains("secret-body-xyz"), + "/{route} revealed the content" + ); + + // The paste is still there to be confirmed on its own page. + let res = client + .get(&location) + .header(header::ACCEPT, "text/html; charset=utf-8") + .send() + .await?; + assert_eq!(res.status(), StatusCode::OK, "/{route} burned the paste"); + assert!(res.text().await?.contains(">reveal<")); + } + + Ok(()) + } } diff --git a/crates/wastebin_server/src/handlers/raw.rs b/crates/wastebin_server/src/handlers/raw.rs index bc00fb9a..c4d184cf 100644 --- a/crates/wastebin_server/src/handlers/raw.rs +++ b/crates/wastebin_server/src/handlers/raw.rs @@ -23,6 +23,13 @@ pub async fn get( let password = password.map(|Password(password)| password); let key: Key = id.parse()?; + // This route is a GET that returns bytes, so there is nowhere to confirm the destruction + // and nothing stopping anything that merely follows a URL from triggering it. The content + // stays reachable through the paste page, which does ask first. + if db.get_metadata(key.id).await?.must_be_deleted { + return Err(crate::Error::BurnNotConfirmed); + } + match db.get(key.id, password).await { Ok(Entry::Regular(data) | Entry::Burned(data)) => Ok(data.text.into_response()), Ok(Entry::Encrypted(data)) => Ok(data.text.into_response().no_store()),