Skip to content

Commit 2da09c6

Browse files
szedan-rhclaude
andcommitted
fix: add Content-Type checking for Grafana login routing
Enhanced the /login handler to check Content-Type header in addition to redirectTo parameter and Referer header. Grafana sends login requests with Content-Type: application/json, while ChatUI uses form data. This fixes the 405 Method Not Allowed error for Grafana login POST requests. Note: Grafana still needs GF_SERVER_ROOT_URL configuration to work properly in iframe, which is a separate deployment configuration issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 551a395 commit 2da09c6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

dashboard/backend/router/router.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,23 @@ func Setup(cfg *config.Config) *http.ServeMux {
203203
}
204204
// Check if this is a Grafana login request by:
205205
// 1. Query parameter redirectTo with "goto" (GET requests)
206-
// 2. Referer header containing "/embedded/grafana" or "/monitoring" (POST requests)
206+
// 2. Referer header containing "/embedded/grafana" or "/monitoring"
207+
// 3. Content-Type: application/json (Grafana uses JSON for login POST)
207208
redirectTo := r.URL.Query().Get("redirectTo")
208209
referer := r.Header.Get("Referer")
210+
contentType := r.Header.Get("Content-Type")
209211

210212
isGrafanaRequest := (redirectTo != "" && strings.Contains(redirectTo, "goto")) ||
211213
strings.Contains(referer, "/embedded/grafana") ||
212-
strings.Contains(referer, "/monitoring")
214+
strings.Contains(referer, "/monitoring") ||
215+
strings.Contains(contentType, "application/json")
213216

214217
if isGrafanaRequest && grafanaStaticProxy != nil {
215-
log.Printf("Proxying Grafana login: %s %s (redirectTo=%s, referer=%s)", r.Method, r.URL.Path, redirectTo, referer)
218+
log.Printf("Proxying Grafana login: %s %s (redirectTo=%s, referer=%s, contentType=%s)", r.Method, r.URL.Path, redirectTo, referer, contentType)
216219
grafanaStaticProxy.ServeHTTP(w, r)
217220
return
218221
}
219-
log.Printf("Proxying Chat UI login: %s %s", r.Method, r.URL.Path)
222+
log.Printf("Proxying Chat UI login: %s %s (contentType=%s)", r.Method, r.URL.Path, contentType)
220223
chatUIProxy.ServeHTTP(w, r)
221224
})
222225
mux.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)