Skip to content

Fix Content-Length buffer overflow and add regression tests#45371

Draft
Phlegmelm wants to merge 1 commit into
envoyproxy:mainfrom
Phlegmelm:fix/sip-proxy-content-length-overflow
Draft

Fix Content-Length buffer overflow and add regression tests#45371
Phlegmelm wants to merge 1 commit into
envoyproxy:mainfrom
Phlegmelm:fix/sip-proxy-content-length-overflow

Conversation

@Phlegmelm
Copy link
Copy Markdown

Summary

Stack buffer overflow in Decoder::reassemble() — the Content-Length
header value was copied into a fixed-size stack buffer with no length
check, allowing attacker-controlled input to overflow the buffer pre-auth.

Reported via GHSA-rh3p-qxp2-vx3f.

Root cause

contrib/sip_proxy/filters/network/source/decoder.cc passed an
attacker-controlled length directly to copyOut() without bounds checking:

char len[10]{};
remaining_data.copyOut(offset, value_len, len); // value_len unchecked

Changes

  • Restored content_length_end == -1 guard to prevent length underflow
  • Added value_len <= 0 guard to reject malformed empty/zero-span headers
  • Clamped copy to min(value_len, sizeof(len) - 1)copyOut can no
    longer write past the buffer
  • Replaced std::atoi with absl::SimpleAtoi into uint32_t — rejects
    negative, non-numeric, and out-of-range values
  • Added Bazel dep @abseil-cpp//absl/strings to decoder_lib
  • Added regression tests: DecodeOverlongContentLengthDoesNotOverflow,
    DecodeNegativeContentLengthIsRejected

Testing

Not compiled on Windows — verified by review and against the buffer API
contract. Linux build target:
//contrib/sip_proxy/filters/network/test:decoder_test

@repokitteh-read-only
Copy link
Copy Markdown

Hi @Phlegmelm, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #45371 was opened by Phlegmelm.

see: more, trace.

@Phlegmelm Phlegmelm had a problem deploying to external-contributors June 1, 2026 18:08 — with GitHub Actions Error
- Add content_length_end == -1 guard to prevent length underflow
- Add value_len <= 0 guard to reject malformed headers
- Clamp copyOut to min(value_len, sizeof(len)-1) to prevent overflow
- Replace std::atoi with absl::SimpleAtoi into uint32_t to reject
  negative, non-numeric, and out-of-range values
- Add regression tests: DecodeOverlongContentLengthDoesNotOverflow,
  DecodeNegativeContentLengthIsRejected

Signed-off-by: Lucy <Asherdardenkol@proton.me>
@Phlegmelm Phlegmelm force-pushed the fix/sip-proxy-content-length-overflow branch from c0b88c5 to eb9bd8a Compare June 1, 2026 18:10
@Phlegmelm Phlegmelm requested a deployment to external-contributors June 1, 2026 18:10 — with GitHub Actions Waiting
Copy link
Copy Markdown
Contributor

@yanavlasov yanavlasov left a comment

Choose a reason for hiding this comment

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

Thanks. Just a small suggestion to use string_view instead of copying data.

/wait

// handful of digits, so clamping cannot turn a legitimate value into a
// smaller-but-valid number (an over-long value is rejected by the parse
// below as out of range).
char len[16] = {}; // zero-initialized, so always NUL terminated after copy
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.

Creating absl::string_view into the content, instead of copying may be better. It will also avoid constructing absl::string_view later on.

@yanavlasov yanavlasov self-assigned this Jun 1, 2026
@Phlegmelm Phlegmelm marked this pull request as draft June 3, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants