Skip to content

Fix admin setup endpoint request body parsing#58

Merged
JoshuaAFerguson merged 4 commits into
mainfrom
claude/fix-setup-request-parsing-01NFyvsJQuGRyybrYuH55eyt
Nov 17, 2025
Merged

Fix admin setup endpoint request body parsing#58
JoshuaAFerguson merged 4 commits into
mainfrom
claude/fix-setup-request-parsing-01NFyvsJQuGRyybrYuH55eyt

Conversation

@JoshuaAFerguson

Copy link
Copy Markdown
Member

No description provided.

The SanitizeJSONMiddleware was consuming the request body without
restoring it, causing subsequent handlers to receive empty bodies.
This broke the setup admin endpoint which requires access to the
request body for validation.

Changes:
- Modified SanitizeJSONMiddleware to read body with io.ReadAll
- Restore body using io.NopCloser before calling Next()
- Use json.Unmarshal instead of c.ShouldBindJSON to avoid consumption
- Removed debug logging from setup handler (no longer needed)
- Removed unused imports (bytes, io) from setup handler

This fix ensures the request body is available to all handlers in
the middleware chain, resolving the "EOF" error when submitting the
setup form.
The AuthHandler.RegisterRoutes was creating an extra /auth group when
it was already being called with /api/v1/auth from main.go, causing
login and other auth endpoints to be registered at /api/v1/auth/auth/*
instead of /api/v1/auth/*.

This resulted in 404 errors when trying to access:
- POST /api/v1/auth/login
- POST /api/v1/auth/refresh
- POST /api/v1/auth/logout
- SAML endpoints

Changes:
- Removed the router.Group("/auth") wrapper in RegisterRoutes
- Routes now register directly on the provided router parameter
- Added comment clarifying that router is already /api/v1/auth

This ensures auth endpoints are accessible at the correct paths.
The CORS middleware was not allowing WebSocket-specific headers,
causing WebSocket upgrade requests to fail with CORS errors.

Changes:
- Added Upgrade, Connection headers for WebSocket protocol switch
- Added Sec-WebSocket-Key for handshake validation
- Added Sec-WebSocket-Version for protocol version negotiation
- Added Sec-WebSocket-Extensions for extension negotiation
- Added Sec-WebSocket-Protocol for subprotocol selection

This fix allows WebSocket connections to properly upgrade from HTTP,
resolving the "WebSocket Connection Error" on the frontend.
Fixed two critical issues preventing WebSocket connections:

1. WebSocket Origin Check (websocket.go):
   - Changed from ALLOWED_ORIGINS to CORS_ALLOWED_ORIGINS env var
   - Now uses same environment variable and logic as CORS middleware
   - Defaults to localhost:3000 and localhost:8000 when not configured
   - Ensures consistent origin validation across HTTP and WebSocket

2. Authentication Middleware (middleware.go):
   - Added special handling for WebSocket upgrade requests
   - Detects WebSocket upgrade via Upgrade and Connection headers
   - Returns HTTP status codes without JSON body for WebSocket requests
   - Prevents breaking WebSocket handshake with JSON responses
   - Auth failures now properly handled by WebSocket upgrader

Why These Fixes Were Needed:
- WebSocket origin check was using different env var, causing rejection
- Auth middleware was writing JSON responses during WebSocket upgrade
- JSON responses break the WebSocket handshake protocol
- Connection would fail before upgrade could complete

This resolves the "WebSocket Connection Error" preventing real-time
updates in the frontend.
@JoshuaAFerguson JoshuaAFerguson merged commit f0ae97a into main Nov 17, 2025
7 of 23 checks passed
@JoshuaAFerguson JoshuaAFerguson deleted the claude/fix-setup-request-parsing-01NFyvsJQuGRyybrYuH55eyt branch November 17, 2025 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants