{"record":{"id":"d3b51632d46af8ca","repo":"netbirdio/netbird","slug":"invalid-session-token","errorCode":null,"errorMessage":"invalid session token","messagePattern":"invalid session token","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"proxy/internal/auth/middleware.go","lineNumber":472,"sourceCode":"func (mw *Middleware) tryHeaderScheme(w http.ResponseWriter, r *http.Request, host string, config DomainConfig, hdr Header, next http.Handler) bool {\n\ttoken, _, err := hdr.Authenticate(r)\n\tif err != nil {\n\t\treturn mw.handleHeaderAuthError(w, r, err)\n\t}\n\tif token == \"\" {\n\t\treturn false\n\t}\n\n\tresult, err := mw.validateSessionToken(r.Context(), host, token, config.SessionPublicKey, auth.MethodHeader)\n\tif err != nil {\n\t\tsetHeaderCapturedData(r.Context(), \"\", \"\", nil, nil)\n\t\tstatus := http.StatusBadRequest\n\t\tmsg := \"invalid session token\"\n\t\tif errors.Is(err, errValidationUnavailable) {\n\t\t\tstatus = http.StatusBadGateway\n\t\t\tmsg = \"authentication service unavailable\"\n\t\t}\n\t\thttp.Error(w, msg, status)\n\t\treturn true\n\t}\n\n\tif !result.Valid {\n\t\tsetHeaderCapturedData(r.Context(), result.UserID, result.UserEmail, result.Groups, result.GroupNames)\n\t\thttp.Error(w, \"Unauthorized\", http.StatusUnauthorized)\n\t\treturn true\n\t}\n\n\tsetSessionCookie(w, token, config.SessionExpiration)\n\tif cd := proxy.CapturedDataFromContext(r.Context()); cd != nil {\n\t\tcd.SetUserID(result.UserID)\n\t\tcd.SetUserEmail(result.UserEmail)\n\t\tcd.SetUserGroups(result.Groups)\n\t\tcd.SetUserGroupNames(result.GroupNames)\n\t\tcd.SetAuthMethod(auth.MethodHeader.String())\n\t}\n","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/proxy/internal/auth/middleware.go#L454-L490","documentation":"Generic guard message in forwardWithHeaderAuth: validateSessionToken returned an error for a session token supplied via a header scheme, and the error is NOT errValidationUnavailable, so it is treated as a client-side bad token (HTTP 400). The token is malformed, expired, has a bad signature, or does not match the domain's SessionPublicKey.","triggerScenarios":"Thrown at proxy/internal/auth/middleware.go:472 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-authenticate to obtain a fresh session token; the current one is expired or malformed","Verify the token was issued for this domain's session public key","Check the Authorization header format matches the scheme's expectation","Inspect middleware logs for the wrapped validation error to distinguish signature vs. expiry vs. parse failures"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","contentChangedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}