Repository navigation
don't proxy sensitive headers - #3272
Conversation
7fe8157 to
98568a6
Compare
|
Force push to pin |
| // Next requires a literal matcher. Tests keep this in sync with lib/plausible. | ||
| '/([aA][pP][iI]/[eE][vV][eE][nN][tT])', |
There was a problem hiding this comment.
I have trouble understanding:
- the "tests" comment here because how does this sync? Doesn't this in fact desync?
- why
PLAUSIBLE_SCRIPT_PATHdoes not match here - the point of the uppercase. Is
/aPi/in a path the same as/ApI/?
There was a problem hiding this comment.
the "tests" comment here because how does this sync? Doesn't this in fact desync?
Sorry. That's referencing some bot tests and a bot comment.
why PLAUSIBLE_SCRIPT_PATH does not match here
It's already covered by the other matcher. PLAUSIBLE_EVENT_PATH needed its own matcher because the other matcher excludes /api paths.
the point of the uppercase. Is /aPi/ in a path the same as /ApI/?
Bots being bots. I'll see if I can use PLAUSIBLE_EVENT_PATH.
There was a problem hiding this comment.
I'll see if I can use PLAUSIBLE_EVENT_PATH.
We can't use constants in matchers, but I'll make it all lowercase and add a comment about needing to keep it in sync.
|
QA instructions
To QA H=(-H 'Cookie: __Secure-next-auth.session-token=SECRET1; multi_auth=SECRET2'
-H 'Authorization: Bearer SECRET3' -H 'X-Api-Key: SECRET4'
-H 'X-Stacker-News-Referrer: spoof' -H 'User-Agent: qa-test'
-H 'X-Forwarded-For: 555.5.555.5')
curl -si "${H[@]}" http://localhost:3000/js/script.js
curl -si "${H[@]}" -X POST -H 'Content-Type: text/plain' -d '{"n":"pageview","u":"http://localhost:3000/"}' http://localhost:3000/api/event |
withPlausibleProxynaively passes ALL headers to Plausible on rewrite (because nextjs does not allow header removals innext.config.jsrewrite rules). This PR avoids this by doing the rewrite ourselves inproxy.jsusing a whitelist of headers that we send upstream.We bind
PlausibleProvider'sinittoPLAUSIBLE_EVENT_PATHwhich helps prevent all headers getting passed should the lib ever change that path.Note
Medium Risk
Changes how analytics traffic is proxied and which headers leave the app; misconfiguration could break Plausible or still leak headers if paths drift from the matcher.
Overview
Moves Plausible analytics proxying out of
next-plausible'swithPlausibleProxyso upstream requests no longer forward every client header to plausible.io.A new
lib/plausible.jscentralizes first-party paths (/js/script.js,/api/event) and their plausible.io targets.pages/_app.jspointsPlausibleProviderat those paths and setsinit.endpointto the event path.proxy.jsrewrites those routes with a whitelist of request headers, setshostto strip the rest, and applies the same security headers as other responses; the matcher gains explicit entries for the two Plausible paths (kept in sync with the constants via comment).next.config.jsdrops thewithPlausibleProxywrapper while keepingtranspilePackages: ['next-plausible'].Reviewed by Cursor Bugbot for commit 40aec5e. Bugbot is set up for automated code reviews on this repo. Configure here.