fix(server): set Cache-Control: private on paid responses in gin/echo/fiber adapters - #83
Open
MoneyBund wants to merge 7 commits into
Open
fix(server): set Cache-Control: private on paid responses in gin/echo/fiber adapters#83MoneyBund wants to merge 7 commits into
MoneyBund wants to merge 7 commits into
Conversation
Contributor
|
LGTM - can you just add a changelog? |
Author
Done |
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.
Set
Cache-Control: privateon paid responses in the Gin, Echo, and Fiber adaptersType: Security fix · Severity: High · Area:
pkg/server/{gin,echo,fiber}Summary
The
net/httpmiddleware marks every successfully-paid response asCache-Control: privateso that a shared cache can never hand one payer'sPayment-Receipt(and the paid body) to a different client. The threeframework adapters re-implement the success path inline and set the
Payment-Receiptheader without the accompanying cache directive. This PRbrings all three adapters back in line with the core middleware and locks the
behavior in with a regression test per adapter.
Why this matters
serveVerifiedin pkg/server/middleware.go isexplicit about the invariant:
The Gin, Echo, and Fiber
ChargeMiddlewarehandlers each set onlyPayment-Receipt. When such a server sits behind a CDN or reverse proxy, a200 OKon aGETroute with aPayment-Receiptheader and no cachedirectives is eligible for heuristic caching (RFC 9111 §4.2.2). A shared
cache may then replay the paid body and another user's receipt to an unrelated,
unpaid client — precisely the leak the core middleware was written to prevent.
Three of the four officially supported stacks were affected; only the raw
net/httppath (andComposeMiddleware, which routes throughserveVerified)was protected.
The fix
Add
Cache-Control: privatealongside thePayment-Receiptheader in eachadapter's verified branch, using each framework's native header API:
c.Writer.Header().Set("Cache-Control", "private")c.Response().Header().Set("Cache-Control", "private")c.Set("Cache-Control", "private")