Skip to content

Reject mailbox payloads the gateway can't return - #1983

Merged
benalleng merged 1 commit into
payjoin:masterfrom
caarloshenriq:mailroom-mailbox-size-limit
Oct 28, 2026
Merged

benalleng merged 1 commit into
payjoin:masterfrom
caarloshenriq:mailroom-mailbox-size-limit

Conversation

@caarloshenriq

Copy link
Copy Markdown
Contributor

Fixes #1982

post_mailbox accepted payloads up to 64 KiB, but every gateway response is padded to BHTTP_REQ_BYTES (8144 bytes) and anything longer was silently cut by resize(), so the client got a response it couldn't parse. V1 fallback requests had the same problem, since the receiver fetches them through the gateway.

Changes:

  • Add MAX_MAILBOX_PAYLOAD_BYTES, the largest payload whose 200 response fits in the gateway envelope (8137 bytes). Honest v2 payloads are 7168 bytes, so real clients aren't affected.
  • post_mailbox answers 413 above it.
  • V1 requests whose {psbt}\n{query} wouldn't fit are rejected with original-psbt-rejected.
  • The gateway returns an error instead of truncating if a response ever exceeds the limit.

Tests:

  • largest_mailbox_payload_round_trips_through_gateway: POST + GET of a max-size payload through a real OHTTP round trip.
  • mailbox_payload_too_large_to_return_is_rejected: one byte over gets 413.
  • post_v1_too_large_to_relay_returns_reject
  • oversized_bhttp_response_is_an_error: pins the constant to the bhttp framing.

The three rejection tests fail on master.

Reviewer: @benalleng

Disclosure: co-authored by Claude

Pull Request Checklist

Please confirm the following before requesting review:

@coveralls

coveralls commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 40742266986

Coverage increased (+0.08%) to 87.547%

Details

  • Coverage increased (+0.08%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (110 of 112 lines covered, 98.21%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
payjoin-mailroom/src/directory.rs 112 110 98.21%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 17947
Covered Lines: 15712
Line Coverage: 87.55%
Coverage Strength: 320.6 hits per line

💛 - Coveralls

@caarloshenriq
caarloshenriq force-pushed the mailroom-mailbox-size-limit branch from d0d2a1f to 88274a2 Compare October 20, 2026 20:09
benalleng
benalleng previously approved these changes Oct 28, 2026

@benalleng benalleng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 88274a2

Just a few small nits

Comment thread payjoin-mailroom/src/directory.rs Outdated
Comment thread payjoin-mailroom/src/directory.rs Outdated
post_mailbox accepted bodies up to 64 KiB, but every gateway response
is padded to BHTTP_REQ_BYTES (8144), and handle_ohttp_gateway cut
longer bhttp responses off with resize(). A client reading such a
mailbox got a response that decrypted fine but could not be parsed.
The same applied to V1 fallback requests, which the receiver fetches
through the gateway.

Cap mailbox payloads at MAX_MAILBOX_PAYLOAD_BYTES, the largest payload
whose 200 response still fits, answering 413 above it. Reject V1
requests that would not fit with original-psbt-rejected. Return an
error from the gateway instead of truncating if a response ever
exceeds the limit.
@caarloshenriq

Copy link
Copy Markdown
Contributor Author

@benalleng I’ve addressed all the nits

@benalleng benalleng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 2d8ced8

@benalleng
benalleng merged commit 3af8815 into payjoin:master Oct 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Directory accepts mailbox payloads it can't return: gateway truncates responses over ~8 KiB

3 participants