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
1 change: 1 addition & 0 deletions payjoin-mailroom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 28 additions & 1 deletion payjoin-mailroom/src/ohttp_relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn parse_gateway_uri_from_path(path: &str, default: &GatewayUri) -> Result<Gatew

let path = &path[1..];

if "http://" == &path[..7] || "https://" == &path[..8] {
if path.starts_with("http://") || path.starts_with("https://") {
Comment thread
Chibey-max marked this conversation as resolved.
GatewayUri::from_str(path)
} else {
Ok(Authority::from_str(path)?.into())
Expand Down Expand Up @@ -344,3 +344,30 @@ pub(crate) fn empty() -> BoxBody<Bytes, hyper::Error> {
pub(crate) fn full<T: Into<Bytes>>(chunk: T) -> BoxBody<Bytes, hyper::Error> {
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")
);
}
}