Repository navigation
admin: normalize request path in remote admin access-control check (defense-in-depth) - #7910
Conversation
Co-authored-by: atlarix-agent <[email protected]>
|
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 <[email protected]>
Co-authored-by: iabdullah215 <[email protected]>
|
@iabdullah215 done and thanks for the review |
steadytao
left a comment
There was a problem hiding this comment.
See the comment from my previous review, wrong button 🥲
path.Clean(allowedPath) silently broadens misconfigured values like // or /.. into /, which grants unintended access to all endpoints. Reject non-canonical paths during provisioning in replaceRemoteAdminServer so misconfigurations fail fast with a clear error. The path.Clean in adminPathAllowed remains as defense-in-depth but is now a safe no-op on validated inputs. Co-authored-by: atlarix-agent <[email protected]>
path.Clean(allowedPath) silently broadens misconfigured values like // or /.. into /, which grants unintended access to all endpoints. Reject non-canonical paths during provisioning in replaceRemoteAdminServer so misconfigurations fail fast with a clear error. The path.Clean in adminPathAllowed remains as defense-in-depth but is now a safe no-op on validated inputs. Co-authored-by: atlarix-agent <[email protected]>
strings.TrimRight strips all trailing slashes, so a configured path like /foo// passed validation (both slashes trimmed to /foo matching path.Clean output) but was silently broadened to /foo at runtime. Use strings.TrimSuffix instead, which removes exactly one trailing slash — the only form the exemption was meant to allow (users write /pki/ca/prod/ meaning the /pki/ca/prod scope). Also update the // test case: with TrimSuffix, // is just / + one trailing slash, which is valid under the exemption. Add a new test for /foo// (double trailing slashes → wantErr: true). Co-authored-by: atlarix-agent <[email protected]>
steadytao
left a comment
There was a problem hiding this comment.
LGTM. Updated trailing slash handling myself as the AI seems a bit incapable.
|
This now has a few subtle compatibility and authorisation-boundary considerations, particularly around |
I feel like there was nuance around using canonical path versus not in admin API. I have to double check. |
|
@mohammed90 @steadytao is there any more things youd like me to fix ? |
|
Hi @AmariahAK bumping this in case it got buried. It's a small defense-in-depth change to |
mholt
left a comment
There was a problem hiding this comment.
This is Matt's Codex agent, GPT-5.6 Sol, replying on his behalf.
I completed the requested second review of the path-matching semantics. Cleaning the decoded request path closes the traversal/boundary gap, while provisioning rejects configured paths whose cleaning could broaden their authority. The existing distinction between /foo and /foo/ is preserved, including exact-match behavior, and empty/root scopes retain their prior allow-all meaning. The focused tests cover the important traversal, duplicate-slash, segment-boundary, and trailing-slash cases. CI is green on this head.
(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.