Skip to content

Check for overflow when encrypting under ABE - #696

Open
ETCaton wants to merge 2 commits into
cloudflare:mainfrom
ETCaton:push-pyzznowxtnss
Open

ETCaton wants to merge 2 commits into
cloudflare:mainfrom
ETCaton:push-pyzznowxtnss

Conversation

@ETCaton

@ETCaton ETCaton commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Because of the use of uint16, >65535 byte values put into the header will wrap around silently and cause decryption to later fail with a confusing "too short" message.

This fixes encryption so that it rejects loudly and this can't silently occur (either accidentally or by malicious policy)

See #695


Open in Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@bwesterb
bwesterb requested a review from cjpatton September 7, 2026 12:41

@cjpatton cjpatton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the patch! This ends up being a pretty big change since we need to update the internal serialization APIs. Ultimately I think the right thing to do is to replace the customer serialization logic with cryptobyte. Would you be interested in pivoting your PR to do this instead?

@ETCaton

ETCaton commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Sure!

I've not written much Go outside of personal projects years ago, so let me read the docs and rethink it. I'll push when I have something that seems to work

@cjpatton

Copy link
Copy Markdown
Contributor

Sure!

I've not written much Go outside of personal projects years ago, so let me read the docs and rethink it. I'll push when I have something that seems to work

Sounds good. Some considerations:

  1. Lots of packages in this repo could use cryptobyte, but for this PR, just focus on ABE.
  2. For inspiration, have a look at crypto/tls in the Go standard library.

@ETCaton

ETCaton commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sure if I'm missing something, but it seems like cryptobyte only works big-endian and so it wouldn't work here for the little-endian values. I'll see if I can use it to wrap some pieces without touching little/big endian

devin-ai-integration[bot]

This comment was marked as resolved.

@cjpatton

Copy link
Copy Markdown
Contributor

I'm not sure if I'm missing something, but it seems like cryptobyte only works big-endian and so it wouldn't work here for the little-endian values. I'll see if I can use it to wrap some pieces without touching little/big endian

Ugh, you're right. That sucks :)

I'll review the PR as is then.

Because of the use of uint16, >65535 byte values put into the header will
wrap around silently and cause decryption to later fail with a confusing
"too short" message.

This fixes encryption so that it rejects loudly and this can't silently
occur (either accidentally or by malicious policy)
Go has a helpful /x/crypto/cryptobyte which includes bounds checking.
Unfortunately, it was designed with protocols which mandate big-endian
in mind, and these values are little-endian

To avoid breaking all the ciphertexts out in the wild we compromise on
cryptobyte for bounds checking then doing some little-endian bookkeeping
ourselves, which still provides a relatively centralized place instead
of a large amount of diffs
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