Skip to content

Commit

Permalink
Merge pull request from GHSA-cjr9-mr35-7xh6
Browse files Browse the repository at this point in the history
pkg/cmd: disable cmdline profile
  • Loading branch information
jzelinskie committed Apr 13, 2023
2 parents 7ecd240 + f2b1f9c commit 9bbd7d7
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 9bbd7d7

Please sign in to comment.