Address review findings F1-F4 for config and /health
Independent review Not signed off — 0 high, 3 medium (#2)
Independent review Not signed off — 0 high, 3 medium (#2)
- F1: read the secret from MEALQUEST_SECRET_KEY_FILE, the documented name. - F2: reject public URLs carrying userinfo, never echo the raw URL in config errors, and log only the public origin (scheme + host). - F3: validate the MEALQUEST_HTTP_ADDR port (numeric, 0-65535) during Load. - F4: return 405 with the API error JSON shape for unsupported methods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/config"
|
||||
)
|
||||
|
||||
func TestLogListeningOmitsURLCredentials(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Load rejects such URLs; this proves the log stays safe even if one
|
||||
// reached the Config some other way.
|
||||
u, err := url.Parse("https://alice:hunter2@meals.example.com/app?token=t0ken")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
logListening(slog.New(slog.NewJSONHandler(&buf, nil)), config.Config{HTTPAddr: ":8080", PublicURL: u})
|
||||
|
||||
out := buf.String()
|
||||
for _, leak := range []string{"alice", "hunter2", "t0ken"} {
|
||||
if strings.Contains(out, leak) {
|
||||
t.Errorf("startup log leaks %q: %s", leak, out)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(out, `"public_origin":"https://meals.example.com"`) {
|
||||
t.Errorf("startup log missing public origin: %s", out)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user