Skip to content

v1 sender should limit response size #483

@nothingmuch

Description

@nothingmuch

BIP 78 does not restrict the size of the response, but specifies that content length must be included.

The v1 receiver enforces a reasonable limit on the request:

if content_length > 4_000_000 * 4 / 3 {
return Err(InternalRequestError::ContentLengthTooLarge(content_length).into());
}

however, a similar limit was not included in payjoin-cli, response.bytes().to_vec() could potentially make unbounded allocations given a large enough response body:

let mut res_str = String::new();
response.read_to_string(&mut res_str).map_err(InternalValidationError::Io)?;

(note that the error mapping also seems inaccurate, not sure what happens in the case of invalid utf8 in the response)

nor is a size limit enforced in the payjoin-cli sender:

let psbt = ctx.process_response(&mut response.bytes().await?.to_vec().as_slice()).map_err(

because these are unbounded allocations a malicious receiver can cause memory exhaustion for the sender.

there may be other issues in v1, and similarly we should check that the in the v2 implementation no such unbounded allocations (e.g. r.bytes().to_vec()) are used for all parties (sender, receiver, directory and relay)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions