diff --git a/pkg/hold/admin/admin.go b/pkg/hold/admin/admin.go index 9eb7156..d810321 100644 --- a/pkg/hold/admin/admin.go +++ b/pkg/hold/admin/admin.go @@ -150,16 +150,18 @@ func NewAdminUI(ctx context.Context, holdPDS *pds.HoldPDS, quotaMgr *quota.Manag // Session management -func (ui *AdminUI) createSession(did, handle string) string { +func (ui *AdminUI) createSession(did, handle string) (string, error) { b := make([]byte, 32) - rand.Read(b) + if _, err := rand.Read(b); err != nil { + return "", fmt.Errorf("failed to create session token: %w", err) + } token := base64.URLEncoding.EncodeToString(b) ui.sessionsMu.Lock() ui.sessions[token] = &AdminSession{DID: did, Handle: handle} ui.sessionsMu.Unlock() - return token + return token, nil } func (ui *AdminUI) getSession(token string) *AdminSession { @@ -340,7 +342,10 @@ func (ui *AdminUI) handleClientMetadata(w http.ResponseWriter, r *http.Request) w.Header().Set("Content-Type", "application/json") w.Header().Set("Cache-Control", "public, max-age=3600") - json.NewEncoder(w).Encode(metadata) + if err := json.NewEncoder(w).Encode(metadata); err != nil { + slog.Error("failed to encode json to http response", "error", err, "path", r.URL.Path) + w.WriteHeader(http.StatusInternalServerError) + } } // Close cleans up resources (no-op now, but keeps interface consistent) diff --git a/pkg/hold/admin/handlers.go b/pkg/hold/admin/handlers.go index e6ad2b2..6b01559 100644 --- a/pkg/hold/admin/handlers.go +++ b/pkg/hold/admin/handlers.go @@ -123,7 +123,10 @@ func (ui *AdminUI) handleStatsAPI(w http.ResponseWriter, r *http.Request) { // Otherwise return JSON w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(stats) + if err := json.NewEncoder(w).Encode(stats); err != nil { + slog.Error("failed to encode json to http response", "error", err, "path", r.URL.Path) + w.WriteHeader(http.StatusInternalServerError) + } } // UserUsage represents storage usage for a user @@ -192,5 +195,8 @@ func (ui *AdminUI) handleTopUsersAPI(w http.ResponseWriter, r *http.Request) { // Otherwise return JSON w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(users) + if err := json.NewEncoder(w).Encode(users); err != nil { + slog.Error("failed to encode json to http response", "error", err, "path", r.URL.Path) + w.WriteHeader(http.StatusInternalServerError) + } } diff --git a/pkg/hold/admin/handlers_auth.go b/pkg/hold/admin/handlers_auth.go index 1b7beba..014991b 100644 --- a/pkg/hold/admin/handlers_auth.go +++ b/pkg/hold/admin/handlers_auth.go @@ -117,7 +117,12 @@ func (ui *AdminUI) handleCallback(w http.ResponseWriter, r *http.Request) { } // Create session and set cookie - token := ui.createSession(did, handle) + token, err := ui.createSession(did, handle) + if err != nil { + slog.Error("failed to create session token", "error", err, "path", r.URL.Path) + w.WriteHeader(http.StatusInternalServerError) + return + } ui.setSessionCookie(w, r, token) slog.Info("Admin login successful", "did", did, "handle", handle) diff --git a/pkg/hold/admin/handlers_crew.go b/pkg/hold/admin/handlers_crew.go index 9cdd7e3..b661c04 100644 --- a/pkg/hold/admin/handlers_crew.go +++ b/pkg/hold/admin/handlers_crew.go @@ -319,7 +319,11 @@ func (ui *AdminUI) handleCrewUpdate(w http.ResponseWriter, r *http.Request) { // Re-apply tier to new record if tier != "" { - ui.pds.UpdateCrewMemberTier(ctx, current.Member, tier) + if err := ui.pds.UpdateCrewMemberTier(ctx, current.Member, tier); err != nil { + slog.Error("failed to update crew member tier", "error", err, "path", r.URL.Path) + w.WriteHeader(http.StatusInternalServerError) + return + } } }