admin: normalize request path in remote admin access-control check (defense-in-depth) - #7910
admin: normalize request path in remote admin access-control check (defense-in-depth)#7910AmariahAK wants to merge 2 commits into
Conversation
Co-authored-by: atlarix-agent <agent@atlarix.dev>
|
Hi @AmariahAK: Thanks for putting this together. I'm the author of the referenced issue #7909; I'd also prepared a fix for this locally (same path.Clean normalization on both the request path and allowed path, plus regression tests for dot-dot/sibling/collapsed-slash/trailing-slash cases) and was about to open a PR. |
|
@iabdullah215 thanks for the review, ill wait for the full list of things you find so that i can fix them all in one clean sweep |
|
Took a proper look, the core
reqPath = path.Clean(reqPath)
if allowedPath == "" {
return true
}
allowedPath = path.Clean(allowedPath)
if allowedPath == "/" {
return true
}
return reqPath == allowedPath || strings.HasPrefix(reqPath, allowedPath+"/")
(For what it's worth, the |
|
@iabdullah215 thanks for this, let me get to working on them |
|
@iabdullah215 could you take a look, should be good to go now |
|
Looks good, the empty |
|
Glad it worked out. Since the empty-path fix came from my local version, would you mind adding a co-author trailer to the commit? |
…zation
path.Clean("") returns ".", so cleaning allowedPath unconditionally
silently broke the allow-all behavior when Paths: [""] is configured.
Short-circuit the empty case before cleaning to preserve that behavior.
Also remove the dead strings.HasSuffix(allowedPath, "/") branch —
after path.Clean the path never has a trailing slash, so the unified
reqPath == allowedPath || HasPrefix(reqPath, allowedPath+"/") form
covers exact match, subpath boundary, and trailing-slash requests.
Co-authored-by: atlarix-agent <agent@atlarix.dev>
Co-authored-by: iabdullah215 <muhammadabdullah8040@gmail.com>
|
@iabdullah215 done and thanks for the review |
(References #7909)
The remote admin API's access-control function
adminPathAllowedcomparedraw request paths against allowed paths without normalization. A request
like
/pki/ca/prod/../../../../loadwould pass the prefix check for anidentity scoped to
/pki/ca/prod, even though the path resolves to/load.While not exploitable today (the router redirects
..paths beforedispatch), the access-control layer depends on the router for safety.
This is defense-in-depth: normalize both the request path and allowed
path with
path.Clean(purely lexical, no filesystem access) beforethe boundary check. This preserves the existing segment-boundary
semantics (e.g.,
/pkimust not match/pkisecret).Added regression tests for: dot-dot traversal, encoded traversal,
sibling traversal, collapsed slashes, and trailing-slash requests.
All five fail without the fix and pass with it.
Assistance Disclosure
Atlarix agent (DeepSeek) generated the test cases and the two-line
path.Cleanimplementation. I authored the fix concept/approach,reviewed every line, and verified correctness including running the
full test suite and confirming the tests fail without the fix and
pass with it.