Skip to content

fix: bound OCR verification work to prevent DoS - #181

Merged
cmalec merged 2 commits into
mainfrom
fix/ocr-verification-bounds
Jul 28, 2026
Merged

fix: bound OCR verification work to prevent DoS#181
cmalec merged 2 commits into
mainfrom
fix/ocr-verification-bounds

Conversation

@cmalec

@cmalec cmalec commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

OCR event verification processes attacker-controlled inputs without size or count limits:

  1. Unbounded ocr_context: hex-decoded before the event hash check, so a malformed event with a huge context causes memory exhaustion even if verification would fail.
  2. Unbounded signature count: the loop performs ECDSA public-key recovery on every signature until quorum, so a large array of valid-but-non-matching signatures causes CPU exhaustion.

Changes:

  • Cap ocr_context at 1 MiB after hex decoding
  • Cap signature count at max(2 × validSigners, minRequiredSignatures, 256)
  • Split parseOCRProofData so ocr_context is decoded only after the event hash verification, avoiding large allocations on invalid reports

Reference: "Unbounded OCR proof processing in OcrEventVerifier causes client-side DoS" analysis-1
Reference: "Unbounded parsing and crypto verification in OcrEventVerifier causes application-wide DoS" analysis-2

Add limits on OCR context size (1 MiB max) and signature count (max of
2x valid signers or 256, whichever is smaller). Split parseOCRProofData
so ocr_context is decoded only after the event hash verification,
avoiding large allocations on invalid reports. These bounds prevent CPU
and memory exhaustion when verifying untrusted events.
@cmalec
cmalec requested a review from a team as a code owner July 24, 2026 22:05
@github-actions

Copy link
Copy Markdown

👋 cmalec, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

Update the test to use a valid OCR report (with correct workflow owner
and event hash) so verification passes the hash check and reaches the
context decoding step where the invalid hex is now rejected.
@cmalec
cmalec merged commit 18b4403 into main Jul 28, 2026
11 checks passed
@cmalec
cmalec deleted the fix/ocr-verification-bounds branch July 28, 2026 20:11
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.

2 participants