netbirdio/netbird · error
Unauthorized
Error message
Unauthorized
What it means
Fires in forwardWithHeaderAuth when validateSessionToken succeeds structurally but returns result.Valid == false — the token is well-formed and verifiable, but the session it identifies is not authorized for this host/domain (revoked session, expired session record, or policy rejection). The client receives 401 Unauthorized and captured data records the token's user for access logging.
Solutions
- Re-authenticate to establish a new, valid session
- Check whether the session was revoked or expired server-side
- Verify the user's group/policy membership grants access to this domain
- Compare middleware logs (captured user/email) with expected access policy to find the rejection reason
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at proxy/internal/auth/middleware.go:478 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16).
Data as JSON: /api/errors/2739a96ab0841d47.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/internal/auth/middleware.go:478
return false
}
result, err := mw.validateSessionToken(r.Context(), host, token, config.SessionPublicKey, auth.MethodHeader)
if err != nil {
setHeaderCapturedData(r.Context(), "", "", nil, nil)
status := http.StatusBadRequest
msg := "invalid session token"
if errors.Is(err, errValidationUnavailable) {
status = http.StatusBadGateway
msg = "authentication service unavailable"
}
http.Error(w, msg, status)
return true
}
if !result.Valid {
setHeaderCapturedData(r.Context(), result.UserID, result.UserEmail, result.Groups, result.GroupNames)
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return true
}
setSessionCookie(w, token, config.SessionExpiration)
if cd := proxy.CapturedDataFromContext(r.Context()); cd != nil {
cd.SetUserID(result.UserID)
cd.SetUserEmail(result.UserEmail)
cd.SetUserGroups(result.Groups)
cd.SetUserGroupNames(result.GroupNames)
cd.SetAuthMethod(auth.MethodHeader.String())
}
next.ServeHTTP(w, r)
return true
}
func (mw *Middleware) handleHeaderAuthError(w http.ResponseWriter, r *http.Request, err error) bool {
if errors.Is(err, ErrHeaderAuthFailed) {View on GitHub (pinned to 93e97f4bf1)