Repository navigation
fix(security): cap the pre-auth body buffer in ServiceSignature - #894
Merged
Merged
Conversation
readAndRestoreBody buffered the whole request body with io.ReadAll before the signature was verified, on the public /orgs/:org/entitlements routes. HasSignature only checks the header is present, so any anonymous caller could force an arbitrarily large allocation (memory exhaustion). Wrap the read in http.MaxBytesReader (4 MiB, generous for entitlements JSON). An oversized body fails the read and collapses into the same generic 401 as every other signature rejection. Refs #892 (finding 3)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #894 +/- ##
==========================================
- Coverage 90.71% 90.71% -0.01%
==========================================
Files 1370 1370
Lines 140857 140857
==========================================
- Hits 127778 127775 -3
- Misses 13070 13073 +3
Partials 9 9
🚀 New features to boost your workflow:
|
Merged
fclairamb
added a commit
that referenced
this pull request
Nov 16, 2026
🤖 I have created a release *beep* *boop* --- ## [0.51.0](v0.50.2...v0.51.0) (2026-11-16) ### Features * Pingdom check importer, insights period selector, job retry log levels ([#904](#904)) ([7914164](7914164)) ### Bug Fixes * **security:** bound status page historyDays, mask config tokens in replay, JS websocket redirect policy, docs JWT placeholders ([#903](#903)) ([6b432e0](6b432e0)) * **security:** cap the pre-auth body buffer in ServiceSignature ([#894](#894)) ([c4da4c5](c4da4c5)), closes [#892](#892) * **security:** cross-check SAML NameID namespace (GO-2026-6909) ([#896](#896)) ([df0d7b6](df0d7b6)) * **security:** treat known dev JWT secrets as placeholders ([#895](#895)) ([1cad98a](1cad98a)), closes [#892](#892) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes finding 3 of the security review #892 (unbounded pre-auth body buffering).
ServiceSignatureruns before authentication on the public/api/v1/orgs/:org/entitlementsgroup.readAndRestoreBodydid an uncappedio.ReadAll(req.Body)wheneverX-SP-Signaturewas present (HasSignatureonly checks the header is non-empty). Any anonymous caller could send that header plus an arbitrarily large body and make the server buffer it fully in memory before the signature check rejected the request — a memory-exhaustion vector on directly-exposed instances. There is no global body cap (limits are per-handler) andReadHeaderTimeoutdoes not bound the body.Fix
http.MaxBytesReaderwith a newmaxServiceSignedBodyBytesconstant (4 MiB — generous for entitlements JSON writes).No wire-contract change:
servicesigcanonical string, headers and verification order are untouched.Tests
New
internal/middleware/servicesig_test.go(internal package, reaches the unexported service marker and the cap constant):go test ./internal/middleware/ ./internal/servicesig/green,golangci-lint run ./internal/middleware/...0 issues,go build ./...OK.Refs #892