BUG: SetupRequired middleware blocks /health, /s/*, and /api/* before initial setup #108

Closed
opened 2026-02-20 12:28:56 +01:00 by clawbot · 0 comments
Collaborator

Severity: HIGH

File & Line

internal/middleware/middleware.go:394-430 and internal/server/routes.go:29

Description

SetupRequired is applied as global middleware on ALL routes (s.router.Use(s.mw.SetupRequired())). When no user exists (fresh install), it redirects everything except /setup to /setup.

This breaks:

  1. /health — returns 303 redirect instead of 200 JSON. Load balancers and monitoring systems will consider the service down during the setup window.
  2. /s/* (static assets) — CSS/JS for the setup page itself cannot load, so the setup page renders unstyled.
  3. /api/v1/* — API routes get HTML redirects instead of JSON errors.
  4. /webhook/* — webhooks return redirects.

Impact

  • Load balancers may refuse to route traffic to a freshly deployed instance, preventing initial setup
  • The setup page itself has broken styling (no CSS/JS)
  • API clients get unexpected redirect responses

Suggested Fix

Exempt paths that should work without setup:

if setupRequired {
    path := request.URL.Path
    if path == "/setup" || path == "/health" || strings.HasPrefix(path, "/s/") {
        next.ServeHTTP(writer, request)
        return
    }
    http.Redirect(writer, request, "/setup", http.StatusSeeOther)
    return
}
## Severity: HIGH ## File & Line `internal/middleware/middleware.go:394-430` and `internal/server/routes.go:29` ## Description `SetupRequired` is applied as global middleware on ALL routes (`s.router.Use(s.mw.SetupRequired())`). When no user exists (fresh install), it redirects everything except `/setup` to `/setup`. This breaks: 1. **`/health`** — returns 303 redirect instead of 200 JSON. Load balancers and monitoring systems will consider the service down during the setup window. 2. **`/s/*` (static assets)** — CSS/JS for the setup page itself cannot load, so the setup page renders unstyled. 3. **`/api/v1/*`** — API routes get HTML redirects instead of JSON errors. 4. **`/webhook/*`** — webhooks return redirects. ## Impact - Load balancers may refuse to route traffic to a freshly deployed instance, preventing initial setup - The setup page itself has broken styling (no CSS/JS) - API clients get unexpected redirect responses ## Suggested Fix Exempt paths that should work without setup: ```go if setupRequired { path := request.URL.Path if path == "/setup" || path == "/health" || strings.HasPrefix(path, "/s/") { next.ServeHTTP(writer, request) return } http.Redirect(writer, request, "/setup", http.StatusSeeOther) return } ```
clawbot added this to the 1.0 milestone 2026-02-20 12:28:56 +01:00
clawbot added the
bug
label 2026-02-20 12:28:56 +01:00
clawbot self-assigned this 2026-02-20 12:28:56 +01:00
sneak closed this issue 2026-02-20 13:47:14 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/upaas#108
No description provided.