feat: pass route path to authorize callback via HandlerInfo#135
Merged
JimMoen merged 2 commits intoemqx:masterfrom Mar 25, 2026
Merged
feat: pass route path to authorize callback via HandlerInfo#135JimMoen merged 2 commits intoemqx:masterfrom
JimMoen merged 2 commits intoemqx:masterfrom
Conversation
Add Path parameter to do_authorize/3 so that the authorize callback
receives the route template (e.g., "/clients/:clientid") in
HandlerInfo map. This allows authorization logic to know the exact
matched route without re-implementing path matching.
HandlerInfo now contains: method, module, function, path.
No #handler{} record change — zero hot-upgrade risk.
Add t_route_path_in_auth test case that requests /route_path_in_auth/42 and asserts the authorize callback receives the route template "/route_path_in_auth/:id" (not the actual request path).
savonarola
approved these changes
Mar 25, 2026
JimMoen
added a commit
to JimMoen/emqx
that referenced
this pull request
Mar 25, 2026
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
Pass the route template path (e.g.
"/clients/:clientid") to the authorize callback via theHandlerInfomap, enabling authorization logic to use the same path that was used for handler dispatch — rather than parsingcowboy_req:path(Req)independently.Motivation
In emqx/emqx#16942 (API Key scope-based authorization), the authorize callback needs to know which route was matched in order to check permissions. Previously, the only option was to re-parse the raw request path from
cowboy_req:path(Req)and match it against route patterns — effectively building a parallel path resolution system. This is fragile and security-sensitive (see review comment).By passing the route
Pathfrom the dispatch state directly, we eliminate the dual-resolution concern entirely.Changes
src/minirest_handler.erl— 1 file, 4 lines changed:do_authorize/2→do_authorize/3: accepts thePathparameter fromhandle/2's dispatch stateHandlerInfomap: addspath => Pathfield (route template string, e.g."/clients/:clientid")#handler{}is untouched to preserve hot-upgrade compatibilityBackward Compatibility
authorizecallback with arity 2 (M:F(Request, HandlerInfo)) receives the extrapathkey inHandlerInfo— existing callbacks that pattern-match onHandlerInfowithoutpathare unaffectedM:F(Request)) is unchanged