Skip to content

Commit aad9223

Browse files
committed
Set v1 buffer size to 7168
This PR sets and rename v1_max_buffer_size. The buffer size for v1 payload is set to 7168 which is same for v2. The variable name is updated to better reflect what it is. The rationale behind the change is that it prevents v2 client fetching v1 request from leaking information about the nature of the request
1 parent 27cc8a1 commit aad9223

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

payjoin-mailroom/src/directory.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const CHACHA20_POLY1305_NONCE_LEN: usize = 32; // chacha20poly1305 n_k
1818
const POLY1305_TAG_SIZE: usize = 16;
1919
pub const BHTTP_REQ_BYTES: usize =
2020
ENCAPSULATED_MESSAGE_BYTES - (CHACHA20_POLY1305_NONCE_LEN + POLY1305_TAG_SIZE);
21-
const V1_MAX_BUFFER_SIZE: usize = 65536;
21+
pub(crate) const MAX_PAYLOAD_SIZE: usize = 7168;
2222

2323
const V1_REJECT_RES_JSON: &str =
2424
r#"{{"errorCode": "original-psbt-rejected ", "message": "Body is not a string"}}"#;
@@ -276,7 +276,7 @@ impl<D: Db> Service<D> {
276276
.await
277277
.map_err(|e| HandlerError::InternalServerError(e.into()))?
278278
.to_bytes();
279-
if req.len() > V1_MAX_BUFFER_SIZE {
279+
if req.len() > MAX_PAYLOAD_SIZE {
280280
return Err(HandlerError::PayloadTooLarge);
281281
}
282282
match self.db.post_v2_payload(&id, req.into()).await {
@@ -322,7 +322,7 @@ impl<D: Db> Service<D> {
322322
.await
323323
.map_err(|e| HandlerError::InternalServerError(e.into()))?
324324
.to_bytes();
325-
if req.len() > V1_MAX_BUFFER_SIZE {
325+
if req.len() > MAX_PAYLOAD_SIZE {
326326
return Err(HandlerError::PayloadTooLarge);
327327
}
328328

@@ -356,6 +356,9 @@ impl<D: Db> Service<D> {
356356
Ok(bytes) => bytes.to_bytes(),
357357
Err(_) => return Ok(bad_request_body_res),
358358
};
359+
if body_bytes.len() > MAX_PAYLOAD_SIZE {
360+
return Err(HandlerError::PayloadTooLarge);
361+
}
359362
let body_str = match String::from_utf8(body_bytes.to_vec()) {
360363
Ok(body_str) => body_str,
361364
Err(_) => return Ok(bad_request_body_res),

0 commit comments

Comments
 (0)