Skip to content

Commit

Permalink
pkg/cmd: disable cmdline profile
Browse files Browse the repository at this point in the history
This route can unintentionally expose secrets
provided to via the command-line to those with
access to the metrics service.

Fixes GHSA-cjr9-mr35-7xh6 CVE-2023-29193
  • Loading branch information
jzelinskie committed Apr 13, 2023
1 parent 7ecd240 commit f2b1f9c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/cmd/server/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,21 @@ func DefaultPreRunE(programName string) cobrautil.CobraRunFunc {
// metrics and pprof endpoints.
func MetricsHandler(telemetryRegistry *prometheus.Registry) http.Handler {
mux := http.NewServeMux()

mux.Handle("/metrics", promhttp.Handler())
if telemetryRegistry != nil {
mux.Handle("/telemetry", promhttp.HandlerFor(telemetryRegistry, promhttp.HandlerOpts{}))
}

mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
if telemetryRegistry != nil {
mux.Handle("/telemetry", promhttp.HandlerFor(telemetryRegistry, promhttp.HandlerOpts{}))
}
mux.HandleFunc("/debug/pprof/cmdline", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "This profile type has been disabled to avoid leaking private command-line arguments")
})

return mux
}

Expand Down

0 comments on commit f2b1f9c

Please sign in to comment.