Fix authentication bypass on /v1/shape via path-normalization mismatch - #4765
Merged
Conversation
`authenticate/2` guarded on `conn.request_path` (the raw request target) while `plug :match` dispatches on the percent-decoded, empty-segment-stripped path. Any request whose decoded path routes to `/v1/shape` but whose raw target is not exactly "/v1/shape" — e.g. "/v1/shape/", "/v1//shape", "/v1/%73hape" — was dispatched to the shape plugs while falling through the unauthenticated catch-all clause, bypassing secure mode entirely. Gate on the route the router already resolved (`conn.private.plug_route`, set by `plug :match` before the later plugs run) so authentication covers exactly what dispatch will serve, for every encoding and slash variant and on every method, with OPTIONS still exempt and unmatched routes still reaching the 404 catch-all. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSXLrB24RAKuYBC5oQ1Svy
`put_cors_headers/2` keyed on `conn.path_info`, which Plug never decodes (the decode happens inside `match/2` and is not written back). A request such as "/v1/%73hape" therefore routes to the shape handler but missed the shape CORS clause and received the default GET/HEAD method list. Match on `conn.private.plug_route` — the same resolved-route basis now used by `authenticate/2` — so CORS headers follow the route dispatch actually selected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSXLrB24RAKuYBC5oQ1Svy
Guards the non-security direction of the plug_route-based auth gate: in insecure mode, requests whose target normalizes to "/v1/shape" (trailing slash, doubled slash, percent-encoded) must still be dispatched to the shape handler and served, not over-blocked or lost to the 404 catch-all. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSXLrB24RAKuYBC5oQ1Svy
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4765 +/- ##
==========================================
- Coverage 60.06% 60.02% -0.05%
==========================================
Files 397 397
Lines 43772 43772
Branches 12591 12589 -2
==========================================
- Hits 26293 26272 -21
- Misses 17398 17418 +20
- Partials 81 82 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ Deploy Preview for electric-next ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
balegas
approved these changes
Aug 20, 2026
Contributor
|
This PR has been released! 🚀 The following packages include changes from this PR:
Thanks for contributing to Electric! |
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.
Summary
Fixes an authentication bypass on
/v1/shapein secure mode (private advisory GHSA-m4f6-p2j8-rq76).authenticate/2guarded onconn.request_path— the raw request target — whileplug :matchdispatches on the percent-decoded, empty-segment-stripped path. Any request whose decoded path routes to/v1/shapebut whose raw target is not exactly"/v1/shape"was dispatched toServeShapePlug/DeleteShapePlugwhile falling through the unauthenticated catch-all clause, bypassing secure mode entirely — no credential required:Affects GET, POST, DELETE and HEAD; OPTIONS is exempt by design. Only secure-mode deployments (
secret != nil) are affected.Fix
authenticate/2now matches on the route the router already resolved (conn.private.plug_route, set byplug :matchbefore the later plugs run) instead of the rawrequest_path. This authenticates exactly what dispatch will serve, for every encoding and slash variant and on every method, with OPTIONS still exempt and unmatched routes still reaching the 404 catch-all.put_cors_headers/2shared the same latent weakness — it keyed on the never-decodedpath_info— and is switched to the sameplug_routebasis so CORS headers follow the resolved route.Credit
Reported by Yahya Jirari, Beeldi (GHSA-m4f6-p2j8-rq76).
🤖 Generated with Claude Code