Skip to content

fix(protocol): size check before JSON parse in receiveEnvelope (#49)#65

Merged
rfxlamia merged 2 commits into
mainfrom
fix/issue-49-receive-envelope-size-check
Jul 23, 2026
Merged

fix(protocol): size check before JSON parse in receiveEnvelope (#49)#65
rfxlamia merged 2 commits into
mainfrom
fix/issue-49-receive-envelope-size-check

Conversation

@rfxlamia

@rfxlamia rfxlamia commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reorder receiveEnvelope() so SPEC §4.3 step 1 (64 KiB wire size check) runs before parseOuterVersion() / JSON.parse
  • Oversized wire with v: 2 now returns envelope_too_large instead of unsupported_version, matching relay inbox behavior (M2.6)
  • Add regression test mirroring relay's oversized v:2 case; relabel §4.1 wire-version test for clarity

Closes #49

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature
  • Breaking change
  • Refactor
  • Documentation
  • CI / workflow

Test plan

  • pnpm --filter @agentpair/protocol test — 390 tests passed
  • New case: oversized v:2 wire → envelope_too_large (not unsupported_version)
  • Existing case: valid-size v:2 wire → unsupported_version still passes
  • Golden fixture envelope_too_large (v:1 generative) unchanged and passing

Pre-flight checklist

  • Follows SPEC §4.3 step 1 (size before decode; decode-DoS mitigation §11.2)
  • No SPEC or golden-vector changes (M1.6 envelope_too_large stays v:1 only)
  • Protocol host receiver aligned with packages/relay/src/routes/inbox.ts

Summary by CodeRabbit

  • Bug Fixes
    • Oversized envelopes are now rejected before version validation.
    • Oversized messages consistently return an “envelope too large” error, preventing further processing or delivery.
  • Tests
    • Added coverage for oversized envelopes containing unsupported wire versions.
    • Updated test labeling for wire-version validation scenarios.

Reorder receiveEnvelope() to match SPEC §4.3 step 1: reject wire >
64 KiB before parseOuterVersion (JSON.parse). Oversized v:2 wire now
returns envelope_too_large instead of unsupported_version, aligning
the protocol host receiver with relay (M2.6).

Closes #49
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@rfxlamia, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e62ffef9-e482-4bc5-a738-8401ea1ad2a3

📥 Commits

Reviewing files that changed from the base of the PR and between df90c1b and 6d0390f.

📒 Files selected for processing (1)
  • packages/protocol/src/receive-envelope.test.ts
📝 Walkthrough

Walkthrough

receiveEnvelope now checks the wire-size limit before outer-version parsing. Tests update the step labels and cover oversized envelopes with an unknown wire version, asserting no dispatch or sequence commit occurs.

Changes

Envelope validation ordering

Layer / File(s) Summary
Size validation before version parsing
packages/protocol/src/crypto/receive-envelope.ts, packages/protocol/src/receive-envelope.test.ts
The size check precedes outer-version parsing, and tests verify envelope_too_large takes precedence without dispatch or sequence-store commit.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main behavior change in receiveEnvelope.
Linked Issues check ✅ Passed The code now checks envelope size before JSON parsing, matching issue #49 and the spec-ordered oversized v:2 behavior.
Out of Scope Changes check ✅ Passed The only changes are the size-check reorder and matching regression tests, both directly tied to the issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-49-receive-envelope-size-check

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.


describe("receiveEnvelope steps 0–6 (§4.3)", () => {
it("step 0: unknown wire version → unsupported_version, dispatch not called", async () => {
describe("receiveEnvelope steps 1–6 (§4.3)", () => {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

[nit] The describe block was renamed to steps 1–6 (§4.3) to match the §4.3 numbering, but a later case in the same block still says valid wire passing steps 0–6 continues to step 7+ (line 307). After this PR there is no “step 0” in either the implementation comments or the suite naming, so the leftover “0” is inconsistent and can confuse anyone mapping tests to SPEC steps.

Suggestion: Rename that case to valid wire passing steps 1–6 continues to step 7+ (or similar) in a follow-up or this PR if you touch the file again.

Rename leftover "steps 0–6" case label to match §4.3 numbering after
issue #49 reorder (no step 0 in impl or suite).
@rfxlamia
rfxlamia merged commit 2357fb1 into main Jul 23, 2026
2 checks passed
@rfxlamia
rfxlamia deleted the fix/issue-49-receive-envelope-size-check branch July 23, 2026 04:23
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.

receiveEnvelope: size check before JSON parse (§4.3 step-order drift)

1 participant