Repository navigation
Gotchas
Max Partenfelder edited this page Oct 30, 2026
·
1 revision
The rules agents and humans get wrong most often, one line each with the page that explains it.
- Provider routes are never behind the Guard; register them with
auth.RegisterRoutes/ginadapter.RegisterRouteson the root. Home - Put the password and GitHub providers into
GuardOptions.Refreshers, or deleted users and removed team members keep access untilMaximumAge. Sessions -
apikeymiddleware goes before the Guard, never in front of ajwt.Verifier(both readAuthorization: Bearer). API-Keys - net/http has no built-in check middleware; wrap the check yourself (
authorizein the examples) or useginadapter.Require. Authorization -
internal/fakeproviderandinternal/backendtestare not importable outside this module; write your own fakes for consumer tests. - Use the wide-event-logger v1 middleware (
ginadapter.NewMiddlewareofgithub.com/govengers/wide-event-logger): it redacts everyrequest.queryvalue, OAuthcodeandstateincluded, unless you list the parameter inQueryAllowlist; never allowlistcodeorstate.ObserveandRequirefind no event of the deprecatedmxcd/go-wide-event-loggerand record nothing. Gin
-
OnLoginmust not mutate its argument: returnidentity.Clone()with changes. Authorization - The password provider's
OnLoginmust keepUserID, or the login fails with 500. Password -
UserIDisuuid.Nilfor OIDC, GitHub and API keys until yourOnLogin(orResolver) sets it;HasUserIDnever matchesuuid.Nil. Authorization - Inactive identities (
Active: false), and identities impersonated by an inactive one, pass onlyIsAuthenticated; aResolvermust setActive: true. API-Keys - Impersonate only through
session.Impersonator:SaveIdentityandSwapIdentityrefuse an identity or impersonator of another provider or subject than the session holds, and a stored impersonation without the Impersonator's end time ends at the next request. Sessions - Roles from
OnLoginand OIDC roles are fixed for the session's lifetime; only the password (user deleted, password or second factor changed) and GitHub (teams) refreshers change a running session. Sessions - The GitHub refresher re-derives
auth.RoleAdminfromAdminTeamson every refresh, so anOnLoginthat stripsadminis undone; gate on a role of your own instead. GitHub - Browser sessions carry no
Permissionsunless a hook grants them;HasPermissionalone locks interactive users out. Authorization
- Logout (all providers) and GitHub refresh-teams refuse
Sec-Fetch-Site: cross-sitewith 403: put logout links on the app's own site. OIDC -
return_tois accepted only as a same-origin path (/..., not//or/\, at most 2048 bytes); anything else becomes/. Security -
LoginURL,ErrorURLandPostLogoutURLare validated at startup and refuse fragments. OIDC - The cookie is named
__Host-<CookieName>while it is Secure, host-only and on/; look for__Host-auth_session, notauth_session. Sessions - Plain
httpoff loopback loops every login unlessInsecureCookie(SESSION_INSECURE_COOKIE) is set; local development only. Sessions - Front-channel logout needs
SameSite: None;oidc.Newandgithub.Newrefuse aStrictstore (the callback would arrive without the cookie). Sessions - No component follows redirects of IdP, token, JWKS, Keycloak or GitHub endpoints (
redirect refused); configure the final URLs. OIDC - Issuer, discovered endpoints, Keycloak and GitHub URLs must be
https;httponly on loopback hosts. OIDC
- No rate limiting: rate-limit the password login,
POST {prefix}/register(an anonymous Argon2id, like login) and TOTP routes at the edge. Password - No retries, no idle timeout, no key rotation list; changing
EncryptionKeylogs everyone out. Sessions -
MemoryBackendis for one replica at non-production scale; useredisbackendin production. Sessions - A stale
SaveIdentityfrom your code can race a Guard refresh; useSession.SwapIdentity. Sessions - Google needs an admission (
AllowedEmailDomains,OnLoginorAllowAnyAccount), elseoidc.Newrefuses; an allowed Workspace domain also requireshd, so a consumer Google account with a company address is 403. OIDC - Full list: Security.
Mirror of docs/wiki at v1.4.0 (5734859). Edit the repository, not this wiki.