From 162b308c50889ef43c1580c2bca4241c7b449503 Mon Sep 17 00:00:00 2001 From: Chibey-max Date: Wed, 21 Oct 2026 18:52:22 +0100 Subject: [PATCH] Fix short gateway paths Avoid panics when parsing short paths. --- payjoin-mailroom/CHANGELOG.md | 1 + payjoin-mailroom/src/ohttp_relay/mod.rs | 29 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/payjoin-mailroom/CHANGELOG.md b/payjoin-mailroom/CHANGELOG.md index dcf76eb2b..0efc683b6 100644 --- a/payjoin-mailroom/CHANGELOG.md +++ b/payjoin-mailroom/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Reject mailbox payloads too large to return through the OHTTP gateway with 413, and V1 requests too large to relay with `original-psbt-rejected`, instead of truncating the response (#1983) +- Return a parsing error instead of panicking on short gateway paths such as `/a.io` (#1999) ## 0.1.3 diff --git a/payjoin-mailroom/src/ohttp_relay/mod.rs b/payjoin-mailroom/src/ohttp_relay/mod.rs index 30b996172..a6995eef0 100644 --- a/payjoin-mailroom/src/ohttp_relay/mod.rs +++ b/payjoin-mailroom/src/ohttp_relay/mod.rs @@ -248,7 +248,7 @@ fn parse_gateway_uri_from_path(path: &str, default: &GatewayUri) -> Result BoxBody { pub(crate) fn full>(chunk: T) -> BoxBody { Full::new(chunk.into()).map_err(|never| match never {}).boxed() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn short_gateway_path_returns_error() { + let default = GatewayUri::from_static(DEFAULT_GATEWAY); + + assert!(parse_gateway_uri_from_path("/http:/", &default).is_err()); + assert!(parse_gateway_uri_from_path("/https:/", &default).is_err()); + } + + #[test] + fn short_gateway_host_and_full_gateway_path_parse() { + let default = GatewayUri::from_static(DEFAULT_GATEWAY); + + assert_eq!( + parse_gateway_uri_from_path("/a.io", &default).unwrap(), + GatewayUri::from_static("https://a.io") + ); + assert_eq!( + parse_gateway_uri_from_path("/https://payjo.in", &default).unwrap(), + GatewayUri::from_static("https://payjo.in") + ); + } +}