Address review findings F1-F4 for config and /health
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:
2026-10-02 22:10:25 -04:00
co-authored by Claude Opus 5.5
parent 5707682018
commit 60555bf8ec
6 changed files with 194 additions and 42 deletions
+18
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"io"
"log/slog"
"maps"
"net/http"
"net/http/httptest"
"testing"
@@ -48,4 +49,21 @@ func TestHealthRejectsOtherMethods(t *testing.T) {
if rec.Code != http.StatusMethodNotAllowed {
t.Errorf("status = %d, want 405", rec.Code)
}
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
t.Errorf("Content-Type = %q, want application/json", ct)
}
var got struct {
Error map[string]any `json:"error"`
}
if err := json.NewDecoder(rec.Body).Decode(&got); err != nil {
t.Fatal(err)
}
want := map[string]any{
"code": "method_not_allowed",
"message": "method not allowed",
"retryable": false,
}
if !maps.Equal(got.Error, want) {
t.Errorf("error body = %v, want %v", got.Error, want)
}
}