package main
import (
- "bytes"
"sync"
)
id int64
moduleName string
target string
- debugOutput *bytes.Buffer
+ debugOutput string
success bool
}
}
// Add a result to the history.
-func (rh *resultHistory) Add(moduleName, target string, debugOutput *bytes.Buffer, success bool) {
+func (rh *resultHistory) Add(moduleName, target, debugOutput string, success bool) {
rh.mu.Lock()
defer rh.mu.Unlock()
if r.URL.Query().Get("debug") == "true" {
w.Header().Set("Content-Type", "text/plain")
- debugOutput.WriteTo(w)
+ w.Write([]byte(debugOutput))
return
}
}
// Returns plaintext debug output for a probe.
-func DebugOutput(module *config.Module, logBuffer *bytes.Buffer, registry *prometheus.Registry) *bytes.Buffer {
+func DebugOutput(module *config.Module, logBuffer *bytes.Buffer, registry *prometheus.Registry) string {
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "Logs for the probe:\n")
logBuffer.WriteTo(buf)
}
buf.Write(c)
- return buf
+ return buf.String()
}
func init() {
results := rh.List()
- for i := len(results) - 1; i > 0; i-- {
+ for i := len(results) - 1; i >= 0; i-- {
r := results[i]
success := "Success"
if !r.success {
return
}
w.Header().Set("Content-Type", "text/plain")
- result.debugOutput.WriteTo(w)
+ w.Write([]byte(result.debugOutput))
})
http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
func TestDebugOutputSecretsHidden(t *testing.T) {
module := c.Modules["http_2xx"]
- buf := DebugOutput(&module, &bytes.Buffer{}, prometheus.NewRegistry())
+ out := DebugOutput(&module, &bytes.Buffer{}, prometheus.NewRegistry())
- out := buf.String()
if strings.Contains(out, "mysecret") {
t.Errorf("Secret exposed in debug output: %v", out)
}