{"record":{"id":"824f67ad61463c74","repo":"AdguardTeam/AdGuardHome","slug":"searching-session-by-token-w","errorCode":null,"errorMessage":"searching session by token: %w","messagePattern":"searching session by token: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/home/authhttp.go","lineNumber":528,"sourceCode":"\t}\n\n\treturn mw.userFromRequestBasicAuth(ctx, r)\n}\n\n// userFromCookie tries to retrieve a user based on the provided cookie value.\nfunc (mw *authMiddlewareDefault) userFromCookie(\n\tctx context.Context,\n\tval string,\n) (u *aghuser.User, err error) {\n\tt, err := sessionTokenFromHex(val)\n\tif err != nil {\n\t\t// Don't wrap the error because it's informative enough as is.\n\t\treturn nil, err\n\t}\n\n\ts, err := mw.sessions.FindByToken(ctx, t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"searching session by token: %w\", err)\n\t}\n\n\tif s == nil {\n\t\treturn nil, nil\n\t}\n\n\tu, err = mw.users.ByLogin(ctx, s.UserLogin)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"searching user by login %q: %w\", s.UserLogin, err)\n\t}\n\n\treturn u, nil\n}\n\n// sessionTokenFromHex converts a hexadecimal string into a session token.\nfunc sessionTokenFromHex(val string) (token aghuser.SessionToken, err error) {\n\tsess, err := hex.DecodeString(val)\n\tif err != nil {","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/home/authhttp.go#L510-L546","documentation":"The auth middleware could not query the session store when resolving a session cookie into a user. The wrapped error comes from the sessions storage backend (e.g. JSON file or database).","triggerScenarios":"GET of any authenticated endpoint with a valid session cookie when Sessions.FindByToken returns an I/O, parse, or lock error from the session storage.","commonSituations":"Corrupted or concurrently-written sessions.json, permission problems on the data directory, disk issues.","solutions":["Check the wrapped error and AdGuard Home logs for the storage-level cause","Verify the working directory/sessions file is writable and not corrupted (restore from backup or delete sessions.json to force re-login)","Avoid running two AdGuard Home instances against the same data directory","Restart the service if a transient file lock was the cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Treat storage errors as 500; only nil,nil means anonymous\nu, err := userFromRequest(r)\nif err != nil { http.Error(w, \"internal\", 500); return }","preventionTips":["Back up and monitor the sessions data file","Avoid concurrent instances sharing one working directory","Handle 5xx by clearing cookies and re-authenticating"],"tags":["auth","session","storage","middleware"],"backgroundTag":"session-store-read-failure","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}