Skip to content

Commit c9a47f3

Browse files
spacebear21shinghim
andcommitted
Enforce size limit in payjoin-cli
Because these are unbounded allocations a malicious receiver can cause memory exhaustion for the sender. Co-authored-by: Shing Him Ng <shinghim@protonmail.com>
1 parent 7c9e7ee commit c9a47f3

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

payjoin-cli/src/app/v1.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use payjoin::bitcoin::FeeRate;
1717
use payjoin::receive::v1::{PayjoinProposal, UncheckedProposal};
1818
use payjoin::receive::ReplyableError::{self, Implementation, V1};
1919
use payjoin::send::v1::SenderBuilder;
20-
use payjoin::{ImplementationError, Uri, UriExt};
20+
use payjoin::{ImplementationError, Uri, UriExt, MAX_CONTENT_LENGTH};
2121
use tokio::net::TcpListener;
2222
use tokio::sync::watch;
2323

@@ -88,12 +88,15 @@ impl AppTrait for App {
8888
"Sent fallback transaction hex: {:#}",
8989
payjoin::bitcoin::consensus::encode::serialize_hex(&fallback_tx)
9090
);
91-
let psbt = ctx.process_response(&mut response.bytes().await?.to_vec().as_slice()).map_err(
92-
|e| {
93-
log::debug!("Error processing response: {e:?}");
94-
anyhow!("Failed to process response {e}")
95-
},
96-
)?;
91+
let response_bytes = response.bytes().await?;
92+
if response_bytes.len() > MAX_CONTENT_LENGTH {
93+
return Err(anyhow!("Response bytes exceeded the limit of {MAX_CONTENT_LENGTH} bytes"));
94+
}
95+
96+
let psbt = ctx.process_response(&mut response_bytes.to_vec().as_slice()).map_err(|e| {
97+
log::debug!("Error processing response: {:?}", e);
98+
anyhow!("Failed to process response {}", e)
99+
})?;
97100

98101
self.process_pj_response(psbt)?;
99102
Ok(())

0 commit comments

Comments
 (0)