fix(server): prevent /debug/* exposure via DefaultServeMux fallthrough#3240
Closed
matiasinsaurralde wants to merge 1 commit into
Closed
fix(server): prevent /debug/* exposure via DefaultServeMux fallthrough#3240matiasinsaurralde wants to merge 1 commit into
matiasinsaurralde wants to merge 1 commit into
Conversation
Kratos' HTTP server routes unmatched requests to http.DefaultServeMux, where net/http/pprof, expvar and golang.org/x/net/trace auto-register handlers from their init() functions. As a result /debug/pprof/*, /debug/vars and /debug/requests were reachable on the public control-plane and CAS HTTP servers regardless of the enable_profiler flag. Add a DenyDefaultMuxFallthrough helper that overrides the Kratos NotFoundHandler and MethodNotAllowedHandler to return 404/405 instead of delegating to the global mux, and apply it to the public-facing HTTP and metrics servers in both the control plane and CAS. The dedicated :6060 profiler server is left unchanged so profiling remains available when enable_profiler is set. Signed-off-by: Matías Insaurralde <matias@chainloop.dev>
Member
|
Superseded by #3241 which also removes the default import and configures a specific profiler at 6060 |
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
Kratos HTTP servers route unmatched requests to
http.DefaultServeMuxthrough their NotFoundHandler andMethodNotAllowedHandler. Standard-library packages such asnet/http/pprof,expvarandgolang.org/x/net/traceauto-register handlers on that global mux from theirinit()functions, so any unmatched route on a public server could leak/debug/pprof/*,/debug/varsand/debug/requests.This adds a shared
DenyDefaultMuxFallthroughhelper that returns plain 404/405 handlers, severing the fallthrough on every network path, and applies it to the Control Plane and Artifact CAS HTTP and metrics servers. Registered routes continue to be matched by the router and are unaffected.