auth: CallerMiddleware header priority order is undocumented #10

Closed
opened 2026-05-14 08:44:21 +00:00 by mathias · 1 comment
Owner

CallerMiddleware checks X-Auth-Request-User first, then falls back to X-Forwarded-User. If a future auth proxy sets both headers (e.g. oauth2-proxy in some configs does), behaviour is undefined and untested.

File: internal/auth/caller.go:10-18

Suggestions:

  • Add a comment documenting which header takes precedence and why
  • Add a unit test covering the both-present scenario
  • Consider logging a warning when both are present and differ
`CallerMiddleware` checks `X-Auth-Request-User` first, then falls back to `X-Forwarded-User`. If a future auth proxy sets both headers (e.g. oauth2-proxy in some configs does), behaviour is undefined and untested. **File:** `internal/auth/caller.go:10-18` **Suggestions:** - Add a comment documenting which header takes precedence and why - Add a unit test covering the both-present scenario - Consider logging a warning when both are present and differ
Author
Owner

Done in gitea-mcp v0.5.0.

CallerMiddleware (internal/auth/caller.go) now:

  • Documents the precedence in a doc comment: X-Auth-Request-User (the verified OIDC identity oauth2-proxy sets) is authoritative; X-Forwarded-User is only a fallback when the former is absent.
  • Takes a *slog.Logger and logs a warning when both headers are present and disagree — X-Auth-Request-User still wins, but the proxy misconfiguration is now visible instead of silently resolved.

Table-driven TestCallerHeaderPrecedence (both/single/none) + TestCallerConflictingHeadersLogsWarning. task check green.

Done in gitea-mcp v0.5.0. `CallerMiddleware` (`internal/auth/caller.go`) now: - **Documents the precedence** in a doc comment: `X-Auth-Request-User` (the verified OIDC identity oauth2-proxy sets) is authoritative; `X-Forwarded-User` is only a fallback when the former is absent. - Takes a `*slog.Logger` and **logs a warning when both headers are present and disagree** — X-Auth-Request-User still wins, but the proxy misconfiguration is now visible instead of silently resolved. Table-driven `TestCallerHeaderPrecedence` (both/single/none) + `TestCallerConflictingHeadersLogsWarning`. `task check` green.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mathias/gitea-mcp#10