Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions crates/wastebin_server/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -46,6 +49,7 @@ impl From<Error> 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(_)
Expand Down
5 changes: 5 additions & 0 deletions crates/wastebin_server/src/handlers/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
43 changes: 43 additions & 0 deletions crates/wastebin_server/src/handlers/html/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<img>` 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<dyn std::error::Error>> {
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(())
}
}
7 changes: 7 additions & 0 deletions crates/wastebin_server/src/handlers/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Loading