fix: reject values that exceed Int32 for all SQL LIMIT params
This commit is contained in:
5 files changed
+29
-17
No files matched your search
@@ -6,32 +6,32 @@ import (
|
||||
)
|
||||
|
||||
// defaultCapturesListLimit is used when the limit query param is absent,
|
||||
// non-numeric, or non-positive. A raw strconv.Atoi zero value (its error
|
||||
// non-numeric, non-positive, or wider than the int32 SQL LIMIT the store
|
||||
// binds. A raw strconv.ParseInt zero value (its error
|
||||
// case) must never reach ListCaptures directly -- SQL "LIMIT 0" returns zero
|
||||
// rows, which would make an unrecognised or missing limit look identical to
|
||||
// "no captures exist" instead of "show the default page."
|
||||
const defaultCapturesListLimit = 100
|
||||
|
||||
// handleCaptures lists recent captured events, newest first, for the
|
||||
// dashboard's event inspector (t2db.2). Token-gated like every other
|
||||
// dashboard's event inspector. Token-gated like every other
|
||||
// /api/* route -- captured payloads are visible only to an authenticated
|
||||
// operator, per docs/prds/webhook-intake-security.md point 5.
|
||||
// operator.
|
||||
//
|
||||
// This is the read half of event capture. The write half is the receiver in
|
||||
// internal/infrastructure/captureintake, mounted on the bypass mux via
|
||||
// CaptureIntake; the dashboard displays captures and mounts the route; it
|
||||
// no longer stores them (archie-core-8cda.5.4).
|
||||
// CaptureIntake; the dashboard displays captures and mounts the route.
|
||||
func (s *Server) handleCaptures(w http.ResponseWriter, r *http.Request) {
|
||||
if s.Captures == nil {
|
||||
writeJSON(w, map[string]any{"captures": []any{}, "enabled": false})
|
||||
return
|
||||
}
|
||||
|
||||
limit, err := strconv.Atoi(r.URL.Query().Get("limit"))
|
||||
limit, err := strconv.ParseInt(r.URL.Query().Get("limit"), 10, 32)
|
||||
if err != nil || limit <= 0 {
|
||||
limit = defaultCapturesListLimit
|
||||
}
|
||||
captures, err := s.Captures.ListCaptures(r.Context(), limit)
|
||||
captures, err := s.Captures.ListCaptures(r.Context(), int(limit))
|
||||
if err != nil {
|
||||
s.Log.Error("list captures", "err", err)
|
||||
http.Error(w, "list captures failed", http.StatusInternalServerError)
|
||||
|
||||
@@ -105,7 +105,7 @@ func TestHandleCapturesDefaultsLimitWhenMissingOrInvalid(t *testing.T) {
|
||||
seedCapture(t, srv, "src")
|
||||
}
|
||||
|
||||
for _, limit := range []string{"", "not-a-number", "-5", "0"} {
|
||||
for _, limit := range []string{"", "not-a-number", "-5", "0", "4294967297"} {
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/captures?limit="+limit, nil)
|
||||
w := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(w, req)
|
||||
|
||||
Reference in new issue
Block a user