From f3e944b13070d574fe7d9012e47eda34f2b23ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 22 Oct 2026 21:38:40 +0200 Subject: [PATCH] paste: take the password and burn confirmation from a request body only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Form` reads the query string on GET and HEAD. On the paste and rendered views that let `?confirm_burn=1` skip the interstitial, so anything that merely follows a URL — an ``, a prefetch, a link unfurler — burnt the paste. On those views and on `/raw` and `/dl` it let `?password=` unlock an encrypted paste, putting the password into browser history, bookmarks, the `Referer` and every proxy log on the way. The interstitial and the password prompt both post, so the views only read a posted form, and the `Password` extractor ignores the query; the `wastebin-password` header remains the way to send a password with a GET. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + .../wastebin_server/src/handlers/extract.rs | 7 ++ .../src/handlers/html/paste.rs | 98 ++++++++++++++++++- .../src/handlers/html/rendered.rs | 90 ++++++++++++++++- crates/wastebin_server/src/handlers/raw.rs | 41 ++++++++ 5 files changed, 232 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d352978..87014984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixed +- Ignore `password` and `confirm_burn` in the query string, so a link can no + longer confirm a burn on the reader's behalf or carry a paste's password. - 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/handlers/extract.rs b/crates/wastebin_server/src/handlers/extract.rs index cddf982e..e3ecc15f 100644 --- a/crates/wastebin_server/src/handlers/extract.rs +++ b/crates/wastebin_server/src/handlers/extract.rs @@ -271,6 +271,13 @@ where return Ok(password); } + // `Form` reads the query string on GET and HEAD, which would put the password in the URL + // and from there into browser history and every proxy log on the way. Only accept it from + // a request body; the header above is the way to send one with a GET. + if matches!(*req.method(), http::Method::GET | http::Method::HEAD) { + return Ok(None); + } + Ok(Form::::from_request(req, state) .await .ok() diff --git a/crates/wastebin_server/src/handlers/html/paste.rs b/crates/wastebin_server/src/handlers/html/paste.rs index d7ac25b8..eeb64b8b 100644 --- a/crates/wastebin_server/src/handlers/html/paste.rs +++ b/crates/wastebin_server/src/handlers/html/paste.rs @@ -73,6 +73,7 @@ pub async fn get( uids: Option, theme: Option, lang: Lang, + method: http::Method, form: Result, E>, ) -> Result { if let Some(token) = handoff.owner.as_deref() @@ -90,7 +91,14 @@ pub async fn get( } async { - let form = form.ok().map(|Form(form)| form); + // `Form` reads the query string on GET and HEAD, so `?confirm_burn=1` burnt the paste for + // anything that merely follows a link (an ``, a prefetch, a link unfurler), and + // `?password=` put the password into browser history, the `Referer` and proxy logs. The + // interstitial and the password prompt both post, so only a request body counts. + let form = form + .ok() + .filter(|_| method == http::Method::POST) + .map(|Form(form)| form); let password = form .as_ref() .and_then(|form| form.password.as_ref()) @@ -189,8 +197,9 @@ pub async fn get( #[cfg(test)] mod tests { + use crate::handlers::insert::form::Entry; use crate::test_helpers::{Client, StoreCookies}; - use reqwest::StatusCode; + use reqwest::{StatusCode, header}; #[tokio::test] async fn unknown_paste() -> Result<(), Box> { @@ -205,7 +214,7 @@ mod tests { #[tokio::test] async fn password_prompt_keeps_extension() -> Result<(), Box> { let client = Client::new(StoreCookies(false)).await; - let data = crate::handlers::insert::form::Entry { + let data = Entry { text: String::from("fn main() {}"), extension: Some(String::from("rs")), password: String::from("hunter2"), @@ -231,7 +240,7 @@ mod tests { async fn encrypted_paste_is_not_stored() -> Result<(), Box> { let client = Client::new(StoreCookies(false)).await; let password = "hunter2"; - let data = crate::handlers::insert::form::Entry { + let data = Entry { text: String::from("secret-body-xyz"), password: password.to_string(), ..Default::default() @@ -253,7 +262,7 @@ mod tests { let res = client .post(&location) .form(&[("password", password)]) - .header(reqwest::header::ACCEPT, "text/html; charset=utf-8") + .header(header::ACCEPT, "text/html; charset=utf-8") .send() .await?; assert_eq!(res.status(), StatusCode::OK); @@ -264,4 +273,83 @@ mod tests { Ok(()) } + + /// `Form` reads the query string on GET, so a link carrying `?confirm_burn=1` skipped the + /// interstitial and burnt the paste for anything that merely follows a URL: an ``, a + /// prefetch, a link unfurler. + #[tokio::test] + async fn burn_is_not_confirmed_from_the_query_string() -> Result<(), Box> + { + 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/", ""); + + for _ in 0..2 { + let res = client + .get(&location) + .query(&[("confirm_burn", "1")]) + .header(header::ACCEPT, "text/html; charset=utf-8") + .send() + .await?; + assert_eq!(res.status(), StatusCode::OK); + let body = res.text().await?; + assert!(!body.contains("secret-body-xyz"), "body: {body}"); + assert!(body.contains(">reveal<"), "body: {body}"); + } + + Ok(()) + } + + /// `Form` reads the query string on GET, so `?password=` unlocked the paste, putting the + /// password into browser history, bookmarks, the `Referer` and every proxy log on the way. + /// The prompt posts, so only a request body may carry one. + #[tokio::test] + async fn password_is_not_taken_from_the_query_string() -> Result<(), Box> + { + let client = Client::new(StoreCookies(false)).await; + let data = Entry { + text: String::from("secret-body-xyz"), + password: String::from("hunter2"), + ..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()?; + + let body = client + .get(location) + .query(&[("password", "hunter2")]) + .header(header::ACCEPT, "text/html; charset=utf-8") + .send() + .await? + .text() + .await?; + assert!(!body.contains("secret-body-xyz"), "body: {body}"); + + // The prompt's own POST is unaffected. + let body = client + .post(location) + .form(&[("password", "hunter2")]) + .header(header::ACCEPT, "text/html; charset=utf-8") + .send() + .await? + .text() + .await?; + assert!(body.contains("secret-body-xyz"), "body: {body}"); + + Ok(()) + } } diff --git a/crates/wastebin_server/src/handlers/html/rendered.rs b/crates/wastebin_server/src/handlers/html/rendered.rs index d8c4f893..698cdce5 100644 --- a/crates/wastebin_server/src/handlers/html/rendered.rs +++ b/crates/wastebin_server/src/handlers/html/rendered.rs @@ -45,10 +45,15 @@ pub async fn get( uids: Option, theme: Option, lang: Lang, + method: http::Method, form: Result, E>, ) -> Result { async { - let form = form.ok().map(|Form(form)| form); + // Only a posted form counts; see `paste::get`. + let form = form + .ok() + .filter(|_| method == http::Method::POST) + .map(|Form(form)| form); let password = form .as_ref() .and_then(|form| form.password.as_ref()) @@ -327,4 +332,87 @@ mod tests { Ok(()) } + + /// `Form` reads the query string on GET, so a link carrying `?confirm_burn=1` skipped the + /// interstitial and burnt the paste for anything that merely follows a URL: an ``, a + /// prefetch, a link unfurler. + #[tokio::test] + async fn burn_is_not_confirmed_from_the_query_string() -> Result<(), Box> + { + let client = Client::new(StoreCookies(false)).await; + let data = Entry { + text: String::from("secret-body-xyz"), + extension: Some(String::from("md")), + 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 rendered = format!("/md{location}"); + + for _ in 0..2 { + let res = client + .get(&rendered) + .query(&[("confirm_burn", "1")]) + .header(header::ACCEPT, "text/html; charset=utf-8") + .send() + .await?; + assert_eq!(res.status(), StatusCode::OK); + let body = res.text().await?; + assert!(!body.contains("secret-body-xyz"), "body: {body}"); + assert!(body.contains(">reveal<"), "body: {body}"); + } + + Ok(()) + } + + /// `Form` reads the query string on GET, so `?password=` unlocked the paste, putting the + /// password into browser history, bookmarks, the `Referer` and every proxy log on the way. + /// The prompt posts, so only a request body may carry one. + #[tokio::test] + async fn password_is_not_taken_from_the_query_string() -> Result<(), Box> + { + let client = Client::new(StoreCookies(false)).await; + let data = Entry { + text: String::from("secret-body-xyz"), + extension: Some(String::from("md")), + password: String::from("hunter2"), + ..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()?; + let rendered = format!("/md{location}"); + + let body = client + .get(&rendered) + .query(&[("password", "hunter2")]) + .header(header::ACCEPT, "text/html; charset=utf-8") + .send() + .await? + .text() + .await?; + assert!(!body.contains("secret-body-xyz"), "body: {body}"); + + // The prompt's own POST is unaffected. + let body = client + .post(&rendered) + .form(&[("password", "hunter2")]) + .header(header::ACCEPT, "text/html; charset=utf-8") + .send() + .await? + .text() + .await?; + assert!(body.contains("secret-body-xyz"), "body: {body}"); + + Ok(()) + } } diff --git a/crates/wastebin_server/src/handlers/raw.rs b/crates/wastebin_server/src/handlers/raw.rs index bc00fb9a..770089a4 100644 --- a/crates/wastebin_server/src/handlers/raw.rs +++ b/crates/wastebin_server/src/handlers/raw.rs @@ -97,4 +97,45 @@ mod tests { Ok(()) } + + /// `Form` reads the query string on GET, so `?password=` unlocked the raw view and the + /// download, putting the password into browser history and proxy logs. + #[tokio::test] + async fn password_is_not_taken_from_the_query_string() -> Result<(), Box> + { + let client = Client::new(StoreCookies(false)).await; + let password = "hunter2"; + let data = Entry { + text: String::from("secret-body-xyz"), + password: password.to_string(), + ..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()?.to_owned(); + + for route in ["raw", "dl"] { + let body = client + .get(&format!("/{route}{location}")) + .query(&[("password", password)]) + .send() + .await? + .text() + .await?; + assert!(!body.contains("secret-body-xyz"), "/{route}: {body}"); + + // The documented way to send one with a GET still works. + let body = client + .get(&format!("/{route}{location}")) + .header(PASSWORD_HEADER_NAME, password) + .send() + .await? + .text() + .await?; + assert_eq!(body, "secret-body-xyz", "/{route}"); + } + + Ok(()) + } }