[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6D25M5H8GQN2P4MAZ3RCTKW":3,"skill-same:01M6D25M5H8GQN2P4MAZ3RCTKW":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":49,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6D25M5H8GQN2P4MAZ3RCTKW","security-auth",null,"Reviewing authentication and authorisation: password storage, sessions and cookies, JWT pitfalls, OAuth and OpenID Connect flows, MFA and passkeys, account enumeration, brute force and rate limits, password reset and verification tokens, API keys, and authorisation checked on every route and every object, including between tenants. Read before reviewing sign-in, sessions, permissions or tokens.","enowdev\u002Fenowxcli","enowdev","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F179420349?v=4","01M6D1MVX2KC0X3Z9NESE7P22K","Enow Dev.","01M6D1MW1FMZGBDKWAJY4GQX81",67,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fsecurity-auth\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"security auth","auth","security","mfa","tokens","sign","route","read","password","password reset","api","passkeys","OAuth","cookies","verification","permissions","authentication","connect","sessions","storage","2026-11-10 10:12:30",false,"---\nname: security-auth\ndescription: \"Reviewing authentication and authorisation: password storage, sessions and cookies, JWT pitfalls, OAuth and OpenID Connect flows, MFA and passkeys, account enumeration, brute force and rate limits, password reset and verification tokens, API keys, and authorisation checked on every route and every object, including between tenants. Read before reviewing sign-in, sessions, permissions or tokens.\"\n---\n\n# Reviewing authentication and authorisation\n\nThe naive auth review sees bcrypt and stops. It misses the JWT verified\nwithout a pinned algorithm, the session that survives a password reset, the\nreset link that works twice, the tenant id read from a header, and the admin\nroute that trusts a role the client wrote. This is what to check in sign-in,\nsessions, tokens and permissions, where it hides in code, and how bad each\ngap is. The rules to build by are in `backend-auth`; method and report format\nin `security`.\n\n## 1. Map the auth surface\n\n- **Where identity is established**: sign-in and sign-up, OAuth and SSO\n  callbacks, magic links, API key and service token middleware, \"remember\n  me\", impersonation.\n- **Where it is checked**: the middleware, its order, the public list, the\n  policy layer. A hosted provider (Auth0, Clerk, Cognito, Supabase Auth,\n  Firebase Auth, Keycloak) takes over password storage and MFA; sessions,\n  token checks and authorisation stay in the app.\n- **Which library**: Auth.js, Better Auth, Passport, Django auth and allauth,\n  Laravel Sanctum or Fortify, Devise, Spring Security. Hand-written auth is\n  read line by line; Lucia is deprecated.\n\n```sh\nrg -n -i 'bcrypt|argon2|scrypt|pbkdf2|password_hash|hashpw|hashlib\\.(md5|sha1|sha256)|createHash\\(|md5\\(|sha1\\(' .\nrg -n -i 'jwt\\.(sign|verify|decode)|jsonwebtoken|jwtVerify|decodeJwt|ParseWithClaims|ParseUnverified|algorithms' .\nrg -n -i 'httpOnly|sameSite|SESSION_COOKIE|cookie_secure|session\\.regenerate|regenerate_id|cycle_key|reset_session' .\nrg -l -i 'reset|forgot|magic.?link|verify.?email|otp|totp|recovery.?code|api.?key' .\n```\n\n## 2. Passwords\n\n- **Storage** (CWE-916, 256, 257): argon2id (OWASP minimum 19 MiB memory,\n  2 iterations, 1 lane), scrypt (N 2^17, r 8, p 1), bcrypt at cost 12 or\n  more, PBKDF2-HMAC-SHA256 at 600,000 iterations where FIPS demands it. A\n  fast hash (MD5, SHA-1, SHA-256, salted or not), reversible encryption or\n  plain text is high: it matters exactly when the database leaks.\n- bcrypt reads only the first 72 bytes; a pre-hash must be encoded (base64),\n  since raw digest bytes can contain zeros that end the input early.\n- Verified by the library in constant time; `==` on hashes is a finding.\n  Hashes rehashed at sign-in when parameters are old (`password_needs_rehash`,\n  argon2's `check_needs_rehash`).\n- **Policy** (CWE-521): at least 8 characters (NIST SP 800-63B revision 4\n  asks for 15 when the password is the only factor), at least 64 allowed,\n  every character allowed, no composition rules, no forced rotation, and\n  breached passwords refused (the Pwned Passwords range API receives only\n  the first five characters of the SHA-1 hash).\n- Changing the password asks for the current one (CWE-620) and ends other\n  sessions. A password in a URL, a log or an email is a finding.\n\n## 3. Sessions and cookies\n\n- Session ids of 128 bits or more from a CSPRNG (frameworks do this), never a\n  user id, timestamp or hash of them.\n- **Fixation** (CWE-384): a new id at sign-in and on privilege change:\n  `req.session.regenerate()`, Django `login()`, Laravel\n  `session()->regenerate()`, Rails `reset_session`, PHP\n  `session_regenerate_id(true)`; Spring Security does it by default.\n- **Expiry** (CWE-613): idle and absolute limits enforced on the server\n  (OWASP suggests 2 to 5 minutes idle for high-value applications, 15 to 30\n  for low-risk ones); sign-out, password change and reset end the session\n  on the server. A signed cookie or JWT still valid after sign-out is\n  medium; \"sign out everywhere\" exists.\n- **Cookies** (CWE-1004, 614, 1275): `HttpOnly`, `Secure`, `SameSite=Lax`\n  (`Strict` for admin), `Path=\u002F`, no `Domain` unless needed (a parent-domain\n  cookie reaches every subdomain); the `__Host-` prefix stops a sibling\n  subdomain overwriting it.\n- Signed is not encrypted: Flask's default session and other signed cookies\n  are readable by the user. No secrets or personal data inside.\n- Weak session secrets (`keyboard cat` from the express-session docs,\n  `changeme`, `django-insecure-` in production, a committed\n  `secret_key_base`) let anyone mint sessions: critical when exploitable.\n\n```sh\nrg -n -i 'httpOnly:\\s*false|secure:\\s*false|sameSite:\\s*[\"\\x27]?none|SESSION_COOKIE_(SECURE|HTTPONLY)\\s*=\\s*False|keyboard cat' .\n```\n\n## 4. JWT\n\n- **Decoded, not verified** (CWE-347): jsonwebtoken `decode`, jose\n  `decodeJwt`, golang-jwt `ParseUnverified`, PyJWT with\n  `verify_signature` off, `jwt-decode` on a server. Claims from an\n  unverified token are the client's word: critical when they decide access.\n- **Algorithm not pinned**: a verifier that follows the header accepts\n  `none`, or checks an HMAC keyed with the RSA public key (algorithm\n  confusion). Pin it: `algorithms: [\"RS256\"]`, PyJWT's required `algorithms`,\n  golang-jwt `WithValidMethods`.\n- **Keys from the token**: `jku`, `x5u` or `jwk` headers trusted; `kid` put\n  in a file path or query.\n- **Claims**: `exp` required, `iss` and `aud` checked (a token issued to\n  another service or client accepted is a confused deputy), a minute of\n  clock skew at most.\n- **Lifetimes**: access tokens 5 to 15 minutes; refresh tokens kept on the\n  server, rotated on use, reuse revoking the family. A 30-day access token\n  with no revocation is a finding; so are roles in a long-lived token that\n  outlive a demotion.\n- HMAC secrets of 32 random bytes or more: a short or dictionary secret is\n  guessed offline from any one token (`your-256-bit-secret` is the jwt.io\n  example). The payload is readable: no secrets or needless personal data.\n- In a browser, not in `localStorage` (any XSS reads it): the session cookie\n  or a backend-for-frontend.\n\n```sh\nrg -n 'jwt\\.decode\\(|decodeJwt\\(|ParseUnverified|verify_signature[\"\\x27]?\\s*:\\s*False|ignoreExpiration|(alg|algorithms?)\\W{0,6}\\[?\\s*[\"\\x27]none[\"\\x27]|\\bjku\\b|\\bx5u\\b' .\n```\n\n## 5. OAuth, OpenID Connect and SAML\n\n- Authorization code with PKCE (S256) for every client, as RFC 9700 (the\n  OAuth 2.0 security best practice, 2025) recommends; the implicit flow and\n  the password grant are findings.\n- `state` per request, bound to the session and checked on the callback;\n  without it an attacker can sign a victim into the attacker's account or\n  link the attacker's identity to the victim's (high). `nonce` checked in\n  the ID token.\n- Redirect URIs matched exactly at the provider; the app's own `returnTo`\n  validated (`security-web` section 7).\n- ID tokens checked by the library: signature against the provider's JWKS,\n  `iss`, `aud` equal to the client id, `exp`, `nonce`.\n- Users keyed by `iss` plus `sub`, never by email alone. Linking by email\n  only when the provider asserts `email_verified` and owns the domain;\n  keying Microsoft Entra multi-tenant sign-ins on the mutable `email` claim\n  (nOAuth) gives accounts away.\n- A provider's access token proves identity to your API only when issued for\n  it (the audience); client secrets never in a mobile app or SPA; refresh\n  tokens encrypted at rest; scopes minimal.\n- SAML: a maintained library at a current version (ruby-saml and others had\n  signature bypasses in 2024 and 2025), signed assertions required,\n  audience, recipient and `NotOnOrAfter` checked, assertion ids cached\n  against replay.\n\n## 6. MFA and passkeys\n\n- TOTP (RFC 6238): 30-second steps, one step of drift, attempts limited per\n  account, a used code refused within its window, the shared secret\n  encrypted at rest (it cannot be hashed).\n- SMS and email codes are weaker (SIM swap, mailbox takeover): a fallback,\n  not the factor for admins.\n- WebAuthn and passkeys through a library (`@simplewebauthn\u002Fserver`,\n  `webauthn` for Python, `go-webauthn`, `webauthn-rs`): a random, single-use,\n  short-lived challenge; origin and RP ID checked; user verification\n  required when the passkey is the only factor.\n- Recovery codes: 8 to 10, random, hashed, single use, replaced as a set.\n- **Bypasses**: the second step reachable without the first (a flag the\n  client holds); API tokens or OAuth sign-in skipping MFA; a reset that turns\n  MFA off; \"remember this device\" tokens that never expire; MFA enrolled or\n  removed without re-authentication.\n- Step-up (a recent sign-in or a fresh factor) for email and password\n  changes, new API keys, payouts, new MFA devices, account deletion.\n\n## 7. Enumeration and brute force\n\n- **Enumeration** (CWE-204): the same status, message and timing for known\n  and unknown accounts on sign-in, reset, sign-up and resend-verification;\n  an unknown user still costs one dummy hash. Low alone; medium when\n  membership is itself sensitive (a clinic's patient portal).\n- **Brute force** (CWE-307): limits per account and per IP (and per \u002F24 or\n  \u002F64) with growing delays on sign-in, code checks, reset, sign-up and\n  anything that sends email or SMS. A six-digit code needs a cap per code\n  (about 5 tries) and a short life (5 to 10 minutes).\n- Lockout that is temporary and cannot be used to lock owners out for good;\n  a CAPTCHA or delay after repeated failures; the owner notified.\n- Credential stuffing beats per-IP limits: breached-password checks, MFA and\n  bot signals matter more.\n- Limits keyed on spoofable headers, or counted per request while GraphQL\n  batches many attempts into one (`security-web` section 13).\n\n## 8. Reset, verification and magic links\n\n- 32 random bytes from a CSPRNG, stored as a SHA-256 hash, single use,\n  bound to one purpose, expiring (reset 15 to 60 minutes, magic link 10 to\n  15, email verification a day), and void once used, reissued, or the\n  password changes (CWE-640).\n- Sent only to the address on the account, never to one in the request (a\n  second field, an array); the link built from the configured base URL,\n  never the `Host` header, which would send the token to another domain.\n- Kept out of logs, analytics and the `Referer` sent to third-party scripts\n  (`Referrer-Policy: no-referrer` on the page that holds it).\n- After a reset: other sessions end, MFA stays, the owner is told. An email\n  change is confirmed from the new address and announced to the old;\n  `emailVerified` is never settable by the client.\n\n```sh\nrg -n -i 'Math\\.random|uuid\\.?v1|Date\\.now\\(\\)|random\\.(randint|choice)|mt_rand|uniqid' .\nrg -n 'req\\.(headers\\.host|hostname)|request\\.get_host\\(\\)|request\\.host\\b|\\$_SERVER\\[.HTTP_HOST' .\n```\n\n## 9. API keys and service credentials\n\n- 32 random bytes with a prefix naming product and environment\n  (`sk_live_`), shown once, stored hashed (SHA-256 suffices for random keys),\n  looked up by hash, scoped, revocable, expiring where possible, with a\n  last-used time.\n- In a header, never the query string (URLs end up in logs). A user's key\n  carries that user's permissions and dies with their membership.\n- Service to service: workload identity, mTLS or short-lived signed tokens\n  with an audience, not one static key shared by every service.\n\n## 10. Authorisation\n\n- **Deny by default**: auth applied to the whole router with an explicit\n  public list. Check the order (a route registered before the middleware),\n  catch-alls, and methods (the `GET` guarded, the `POST` to the same path\n  not).\n- **One layer**: policies or gates (Laravel policies, Pundit, Django and DRF\n  `permission_classes`, Spring `@PreAuthorize`, Casbin, Oso, Cerbos,\n  OpenFGA or SpiceDB for relationships). Scattered `role == \"admin\"` checks\n  are where one is missing.\n- **Every object**: reads, updates, deletes, downloads, exports, search\n  results, nested routes, bulk actions, socket subscriptions, GraphQL fields\n  and `node` lookups (`security-web` section 1).\n- **Tenants**: the tenant from the session's membership, never the body, a\n  header or the subdomain alone; every query, cache key, search index, file\n  key and job scoped by it.\n- **Row-level security** in PostgreSQL: `ENABLE ROW LEVEL SECURITY` and\n  `FORCE ROW LEVEL SECURITY` (without `FORCE` the table owner skips it;\n  superusers and `BYPASSRLS` roles always do, so the app never connects as\n  one); the tenant set with `SET LOCAL` inside a transaction, or a pooled\n  connection carries it into the next request.\n- **Supabase and Firebase**: the public key plus a table without RLS, or\n  rules like `allow read, write: if true` or test mode still in force,\n  exposes everything; the `service_role` or secret key never ships to a\n  client.\n- Roles from the server's records, not a claim the client sent, effective at\n  once when changed; admin routes apart, with MFA and an audit trail;\n  impersonation logged and visible.\n- Tests prove that another user or tenant gets `404` or `403` for each\n  resource. Their absence is a note; the gap they would catch is the finding.\n\n```sh\nrg -n -i 'isAdmin|role\\s*===?\\s*[\"\\x27]|hasRole\\(|@PreAuthorize|permission_classes|authorize\\(|Gate::|->can\\(' .\nrg -n -i 'row level security|create policy|set_config\\(|set local|service_role|if true;' .\n```\n\n## 11. Rating auth findings\n\n| Finding | Usual rating |\n|---|---|\n| Unverified or `none` tokens accepted; an auth bypass on a public route; a mintable session secret | Critical |\n| Cross-tenant reads or writes; a public key with RLS off on private tables | Critical or high |\n| IDOR on private data; a reset token reusable or never expiring; an MFA bypass; account-linking CSRF | High |\n| Sessions surviving a reset or sign-out; codes with no attempt limit | Medium or high |\n| No sign-in rate limit; session fixation; tokens in `localStorage` | Medium |\n| Enumeration; no `__Host-` prefix; a weak policy where MFA is enforced | Low |\n\n## Check it\n\n- Walk each flow in the code: sign-up, sign-in, sign-out, reset, email\n  change, MFA enrol and removal, invitation, role change, account deletion.\n  For each: what proves identity, what is issued, what ends, what is logged.\n- For each role, the routes it reaches match what the product intends; for\n  each tenant-scoped table, every query path filters by tenant.\n- Run the project's auth tests and note which forbidden paths have none.\n\n## Avoid\n\nStopping at the hash function; trusting a decoded but unverified token; an\nalgorithm taken from the token header; a session that survives a reset; a\nreset link built from the `Host` header; users matched by email across\nproviders; a tenant id from the request; `if isAdmin` copied into handlers;\na public key over tables without RLS; calling enumeration critical.\n","# Reviewing authentication and authorisation\n\nThe naive auth review sees bcrypt and stops. It misses the JWT verified\nwithout a pinned algorithm, the session that survives a password reset, the\nreset link that works twice, the tenant id read from a header, and the admin\nroute that trusts a role the client wrote. This is what to check in sign-in,\nsessions, tokens and permissions, where it hides in code, and how bad each\ngap is. The rules to build by are in `backend-auth`; method and report format\nin `security`.\n\n## 1. Map the auth surface\n\n- **Where identity is established**: sign-in and sign-up, OAuth and SSO\n  callbacks, magic links, API key and service token middleware, \"remember\n  me\", impersonation.\n- **Where it is checked**: the middleware, its order, the public list, the\n  policy layer. A hosted provider (Auth0, Clerk, Cognito, Supabase Auth,\n  Firebase Auth, Keycloak) takes over password storage and MFA; sessions,\n  token checks and authorisation stay in the app.\n- **Which library**: Auth.js, Better Auth, Passport, Django auth and allauth,\n  Laravel Sanctum or Fortify, Devise, Spring Security. Hand-written auth is\n  read line by line; Lucia is deprecated.\n\n```sh\nrg -n -i 'bcrypt|argon2|scrypt|pbkdf2|password_hash|hashpw|hashlib\\.(md5|sha1|sha256)|createHash\\(|md5\\(|sha1\\(' .\nrg -n -i 'jwt\\.(sign|verify|decode)|jsonwebtoken|jwtVerify|decodeJwt|ParseWithClaims|ParseUnverified|algorithms' .\nrg -n -i 'httpOnly|sameSite|SESSION_COOKIE|cookie_secure|session\\.regenerate|regenerate_id|cycle_key|reset_session' .\nrg -l -i 'reset|forgot|magic.?link|verify.?email|otp|totp|recovery.?code|api.?key' .\n```\n\n## 2. Passwords\n\n- **Storage** (CWE-916, 256, 257): argon2id (OWASP minimum 19 MiB memory,\n  2 iterations, 1 lane), scrypt (N 2^17, r 8, p 1), bcrypt at cost 12 or\n  more, PBKDF2-HMAC-SHA256 at 600,000 iterations where FIPS demands it. A\n  fast hash (MD5, SHA-1, SHA-256, salted or not), reversible encryption or\n  plain text is high: it matters exactly when the database leaks.\n- bcrypt reads only the first 72 bytes; a pre-hash must be encoded (base64),\n  since raw digest bytes can contain zeros that end the input early.\n- Verified by the library in constant time; `==` on hashes is a finding.\n  Hashes rehashed at sign-in when parameters are old (`password_needs_rehash`,\n  argon2's `check_needs_rehash`).\n- **Policy** (CWE-521): at least 8 characters (NIST SP 800-63B revision 4\n  asks for 15 when the password is the only factor), at least 64 allowed,\n  every character allowed, no composition rules, no forced rotation, and\n  breached passwords refused (the Pwned Passwords range API receives only\n  the first five characters of the SHA-1 hash).\n- Changing the password asks for the current one (CWE-620) and ends other\n  sessions. A password in a URL, a log or an email is a finding.\n\n## 3. Sessions and cookies\n\n- Session ids of 128 bits or more from a CSPRNG (frameworks do this), never a\n  user id, timestamp or hash of them.\n- **Fixation** (CWE-384): a new id at sign-in and on privilege change:\n  `req.session.regenerate()`, Django `login()`, Laravel\n  `session()->regenerate()`, Rails `reset_session`, PHP\n  `session_regenerate_id(true)`; Spring Security does it by default.\n- **Expiry** (CWE-613): idle and absolute limits enforced on the server\n  (OWASP suggests 2 to 5 minutes idle for high-value applications, 15 to 30\n  for low-risk ones); sign-out, password change and reset end the session\n  on the server. A signed cookie or JWT still valid after sign-out is\n  medium; \"sign out everywhere\" exists.\n- **Cookies** (CWE-1004, 614, 1275): `HttpOnly`, `Secure`, `SameSite=Lax`\n  (`Strict` for admin), `Path=\u002F`, no `Domain` unless needed (a parent-domain\n  cookie reaches every subdomain); the `__Host-` prefix stops a sibling\n  subdomain overwriting it.\n- Signed is not encrypted: Flask's default session and other signed cookies\n  are readable by the user. No secrets or personal data inside.\n- Weak session secrets (`keyboard cat` from the express-session docs,\n  `changeme`, `django-insecure-` in production, a committed\n  `secret_key_base`) let anyone mint sessions: critical when exploitable.\n\n```sh\nrg -n -i 'httpOnly:\\s*false|secure:\\s*false|sameSite:\\s*[\"\\x27]?none|SESSION_COOKIE_(SECURE|HTTPONLY)\\s*=\\s*False|keyboard cat' .\n```\n\n## 4. JWT\n\n- **Decoded, not verified** (CWE-347): jsonwebtoken `decode`, jose\n  `decodeJwt`, golang-jwt `ParseUnverified`, PyJWT with\n  `verify_signature` off, `jwt-decode` on a server. Claims from an\n  unverified token are the client's word: critical when they decide access.\n- **Algorithm not pinned**: a verifier that follows the header accepts\n  `none`, or checks an HMAC keyed with the RSA public key (algorithm\n  confusion). Pin it: `algorithms: [\"RS256\"]`, PyJWT's required `algorithms`,\n  golang-jwt `WithValidMethods`.\n- **Keys from the token**: `jku`, `x5u` or `jwk` headers trusted; `kid` put\n  in a file path or query.\n- **Claims**: `exp` required, `iss` and `aud` checked (a token issued to\n  another service or client accepted is a confused deputy), a minute of\n  clock skew at most.\n- **Lifetimes**: access tokens 5 to 15 minutes; refresh tokens kept on the\n  server, rotated on use, reuse revoking the family. A 30-day access token\n  with no revocation is a finding; so are roles in a long-lived token that\n  outlive a demotion.\n- HMAC secrets of 32 random bytes or more: a short or dictionary secret is\n  guessed offline from any one token (`your-256-bit-secret` is the jwt.io\n  example). The payload is readable: no secrets or needless personal data.\n- In a browser, not in `localStorage` (any XSS reads it): the session cookie\n  or a backend-for-frontend.\n\n```sh\nrg -n 'jwt\\.decode\\(|decodeJwt\\(|ParseUnverified|verify_signature[\"\\x27]?\\s*:\\s*False|ignoreExpiration|(alg|algorithms?)\\W{0,6}\\[?\\s*[\"\\x27]none[\"\\x27]|\\bjku\\b|\\bx5u\\b' .\n```\n\n## 5. OAuth, OpenID Connect and SAML\n\n- Authorization code with PKCE (S256) for every client, as RFC 9700 (the\n  OAuth 2.0 security best practice, 2025) recommends; the implicit flow and\n  the password grant are findings.\n- `state` per request, bound to the session and checked on the callback;\n  without it an attacker can sign a victim into the attacker's account or\n  link the attacker's identity to the victim's (high). `nonce` checked in\n  the ID token.\n- Redirect URIs matched exactly at the provider; the app's own `returnTo`\n  validated (`security-web` section 7).\n- ID tokens checked by the library: signature against the provider's JWKS,\n  `iss`, `aud` equal to the client id, `exp`, `nonce`.\n- Users keyed by `iss` plus `sub`, never by email alone. Linking by email\n  only when the provider asserts `email_verified` and owns the domain;\n  keying Microsoft Entra multi-tenant sign-ins on the mutable `email` claim\n  (nOAuth) gives accounts away.\n- A provider's access token proves identity to your API only when issued for\n  it (the audience); client secrets never in a mobile app or SPA; refresh\n  tokens encrypted at rest; scopes minimal.\n- SAML: a maintained library at a current version (ruby-saml and others had\n  signature bypasses in 2024 and 2025), signed assertions required,\n  audience, recipient and `NotOnOrAfter` checked, assertion ids cached\n  against replay.\n\n## 6. MFA and passkeys\n\n- TOTP (RFC 6238): 30-second steps, one step of drift, attempts limited per\n  account, a used code refused within its window, the shared secret\n  encrypted at rest (it cannot be hashed).\n- SMS and email codes are weaker (SIM swap, mailbox takeover): a fallback,\n  not the factor for admins.\n- WebAuthn and passkeys through a library (`@simplewebauthn\u002Fserver`,\n  `webauthn` for Python, `go-webauthn`, `webauthn-rs`): a random, single-use,\n  short-lived challenge; origin and RP ID checked; user verification\n  required when the passkey is the only factor.\n- Recovery codes: 8 to 10, random, hashed, single use, replaced as a set.\n- **Bypasses**: the second step reachable without the first (a flag the\n  client holds); API tokens or OAuth sign-in skipping MFA; a reset that turns\n  MFA off; \"remember this device\" tokens that never expire; MFA enrolled or\n  removed without re-authentication.\n- Step-up (a recent sign-in or a fresh factor) for email and password\n  changes, new API keys, payouts, new MFA devices, account deletion.\n\n## 7. Enumeration and brute force\n\n- **Enumeration** (CWE-204): the same status, message and timing for known\n  and unknown accounts on sign-in, reset, sign-up and resend-verification;\n  an unknown user still costs one dummy hash. Low alone; medium when\n  membership is itself sensitive (a clinic's patient portal).\n- **Brute force** (CWE-307): limits per account and per IP (and per \u002F24 or\n  \u002F64) with growing delays on sign-in, code checks, reset, sign-up and\n  anything that sends email or SMS. A six-digit code needs a cap per code\n  (about 5 tries) and a short life (5 to 10 minutes).\n- Lockout that is temporary and cannot be used to lock owners out for good;\n  a CAPTCHA or delay after repeated failures; the owner notified.\n- Credential stuffing beats per-IP limits: breached-password checks, MFA and\n  bot signals matter more.\n- Limits keyed on spoofable headers, or counted per request while GraphQL\n  batches many attempts into one (`security-web` section 13).\n\n## 8. Reset, verification and magic links\n\n- 32 random bytes from a CSPRNG, stored as a SHA-256 hash, single use,\n  bound to one purpose, expiring (reset 15 to 60 minutes, magic link 10 to\n  15, email verification a day), and void once used, reissued, or the\n  password changes (CWE-640).\n- Sent only to the address on the account, never to one in the request (a\n  second field, an array); the link built from the configured base URL,\n  never the `Host` header, which would send the token to another domain.\n- Kept out of logs, analytics and the `Referer` sent to third-party scripts\n  (`Referrer-Policy: no-referrer` on the page that holds it).\n- After a reset: other sessions end, MFA stays, the owner is told. An email\n  change is confirmed from the new address and announced to the old;\n  `emailVerified` is never settable by the client.\n\n```sh\nrg -n -i 'Math\\.random|uuid\\.?v1|Date\\.now\\(\\)|random\\.(randint|choice)|mt_rand|uniqid' .\nrg -n 'req\\.(headers\\.host|hostname)|request\\.get_host\\(\\)|request\\.host\\b|\\$_SERVER\\[.HTTP_HOST' .\n```\n\n## 9. API keys and service credentials\n\n- 32 random bytes with a prefix naming product and environment\n  (`sk_live_`), shown once, stored hashed (SHA-256 suffices for random keys),\n  looked up by hash, scoped, revocable, expiring where possible, with a\n  last-used time.\n- In a header, never the query string (URLs end up in logs). A user's key\n  carries that user's permissions and dies with their membership.\n- Service to service: workload identity, mTLS or short-lived signed tokens\n  with an audience, not one static key shared by every service.\n\n## 10. Authorisation\n\n- **Deny by default**: auth applied to the whole router with an explicit\n  public list. Check the order (a route registered before the middleware),\n  catch-alls, and methods (the `GET` guarded, the `POST` to the same path\n  not).\n- **One layer**: policies or gates (Laravel policies, Pundit, Django and DRF\n  `permission_classes`, Spring `@PreAuthorize`, Casbin, Oso, Cerbos,\n  OpenFGA or SpiceDB for relationships). Scattered `role == \"admin\"` checks\n  are where one is missing.\n- **Every object**: reads, updates, deletes, downloads, exports, search\n  results, nested routes, bulk actions, socket subscriptions, GraphQL fields\n  and `node` lookups (`security-web` section 1).\n- **Tenants**: the tenant from the session's membership, never the body, a\n  header or the subdomain alone; every query, cache key, search index, file\n  key and job scoped by it.\n- **Row-level security** in PostgreSQL: `ENABLE ROW LEVEL SECURITY` and\n  `FORCE ROW LEVEL SECURITY` (without `FORCE` the table owner skips it;\n  superusers and `BYPASSRLS` roles always do, so the app never connects as\n  one); the tenant set with `SET LOCAL` inside a transaction, or a pooled\n  connection carries it into the next request.\n- **Supabase and Firebase**: the public key plus a table without RLS, or\n  rules like `allow read, write: if true` or test mode still in force,\n  exposes everything; the `service_role` or secret key never ships to a\n  client.\n- Roles from the server's records, not a claim the client sent, effective at\n  once when changed; admin routes apart, with MFA and an audit trail;\n  impersonation logged and visible.\n- Tests prove that another user or tenant gets `404` or `403` for each\n  resource. Their absence is a note; the gap they would catch is the finding.\n\n```sh\nrg -n -i 'isAdmin|role\\s*===?\\s*[\"\\x27]|hasRole\\(|@PreAuthorize|permission_classes|authorize\\(|Gate::|->can\\(' .\nrg -n -i 'row level security|create policy|set_config\\(|set local|service_role|if true;' .\n```\n\n## 11. Rating auth findings\n\n| Finding | Usual rating |\n|---|---|\n| Unverified or `none` tokens accepted; an auth bypass on a public route; a mintable session secret | Critical |\n| Cross-tenant reads or writes; a public key with RLS off on private tables | Critical or high |\n| IDOR on private data; a reset token reusable or never expiring; an MFA bypass; account-linking CSRF | High |\n| Sessions surviving a reset or sign-out; codes with no attempt limit | Medium or high |\n| No sign-in rate limit; session fixation; tokens in `localStorage` | Medium |\n| Enumeration; no `__Host-` prefix; a weak policy where MFA is enforced | Low |\n\n## Check it\n\n- Walk each flow in the code: sign-up, sign-in, sign-out, reset, email\n  change, MFA enrol and removal, invitation, role change, account deletion.\n  For each: what proves identity, what is issued, what ends, what is logged.\n- For each role, the routes it reaches match what the product intends; for\n  each tenant-scoped table, every query path filters by tenant.\n- Run the project's auth tests and note which forbidden paths have none.\n\n## Avoid\n\nStopping at the hash function; trusting a decoded but unverified token; an\nalgorithm taken from the token header; a session that survives a reset; a\nreset link built from the `Host` header; users matched by email across\nproviders; a tenant id from the request; `if isAdmin` copied into handlers;\na public key over tables without RLS; calling enumeration critical.\n",{"name":5,"description":7},"main","38293fe1b096e6bf3646c7344c38786ed688f464","crates\u002Fenowx-core\u002Fskills\u002Fsecurity-auth",21,"https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli","https:\u002F\u002Fenowx.ai","https:\u002F\u002Fgithub.com\u002Fenowdev","Pretending to be a Developer","2026-10-06 02:05:35",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add enowdev\u002Fenowxcli --skill security-auth",{"tool":59,"command":60},"bunx","bunx skills add enowdev\u002Fenowxcli --skill security-auth",{"tool":62,"command":63},"pnpm","pnpm dlx skills add enowdev\u002Fenowxcli --skill security-auth","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fsecurity-auth\u002FSKILL.md",true,[],[68,79,96,109,129,148],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":39},"01M6D2HQYSQD9N7MTNDT4A7CBM","demo-skill","Project-scope demo skill for tests.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fworkspace\u002F.agents\u002Fskills\u002Fdemo-skill\u002FSKILL.md",[],[75,76,77,78,26],"demo skill","demo","tests","project",{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":39},"01M6D2HM0GCPM0TM2HPG9HHR2R","writing","Writing words people read: the specific thing instead of claims, words to drop, sentences, interface copy (buttons, labels, errors, empty states, confirmations), page copy, notifications and emails, alt text and link text, numbers and dates, words that translate well, documentation and voice. Read before writing a page's copy, an interface's text or a document.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fwriting\u002FSKILL.md",[],[81,86,87,88,89,90,26,91,92,93,94,95],"text","emails","empty","drop","document","page","voice","notifications","documentation","translate",{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":39},"01M6D2HG07YS49NM196Q0R3AZ8","ui","Designing or restyling an interface: direction, layout, type, colour, icons, components, states, responsive behaviour. Read before building a page, a screen or a set of components.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui\u002FSKILL.md",[],[98,103,104,105,106,91,107,26,108],"icons","components","SET","responsive","layout","before building",{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":39},"01M6D2HB59HZHWG1RYZDV4SJ91","ui-themes","Light and dark themes, and colour that holds in both: tokens with a value per theme, and what each kind of content needs to stay visible (icons, SVG drawings and line art, logos, photos, screenshots, charts, code, maps, borders, shadows, focus, form controls), switching without a flash, and checking both. Read before building a second theme or a theme toggle, and before any drawing, logo or chart on a page that has two themes.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-themes\u002FSKILL.md",[],[98,116,117,118,23,119,120,121,122,26,108,123,91,124,125,126,103,127,128],"ui themes","switching","photos","drawing","focus","maps","Art","flash","code","Charts","content","screenshots","logo",{"skillNo":130,"name":131,"nameZh":6,"description":132,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":133,"categories":134,"keywords":135,"publishedAt":39},"01M6D2H5R5KRAE524C8QX0T7Q0","ui-structure","Structure before styling: the blueprint written before any interface code (the screen's job, the regions its kind of page needs, their order and why, the layout skeleton in numbers, the components and their states), the anatomy and order of a homepage, a dashboard, a list, a detail page, settings, a form, sign-in, pricing, docs, an article and a checkout, and how to turn the blueprint into code (tokens, layout primitives, components, sections, page). Read first, before building or rebuilding any page or screen.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-structure\u002FSKILL.md",[],[136,98,137,104,138,139,124,140,141,142,107,23,143,144,145,26,108,91,146,147],"structure","ui structure","pricing","dashboard","Blueprint","article","anatomy","styling","primitives","list","why","how",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":39},"01M6D2H0ZZBJG77MBGPZHA6MWD","ui-stack-vue","Building interfaces in Vue 3 and Nuxt: project layout, script setup with typed defineProps, defineEmits and defineModel, attribute fallthrough, slots and scoped slots, template refs, ref, reactive and computed, watch versus watchEffect, composables and VueUse, provide and inject, Pinia, keyed v-for, transitions, Nuxt 4 (app directory, pages, layouts, useFetch and useAsyncData keys, $fetch in handlers, server routes, runtime config, useSeoMeta, NuxtImg, middleware), VeeValidate forms, Reka UI and Nuxt UI, testing, vue-tsc, and the traps. Read when the project uses Vue or Nuxt.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-stack-vue\u002FSKILL.md",[],[98,155,156,157,158,159,160,161,107,78,162,163,26,164,165,166,167,168,169,170],"vue","stack","ui stack vue","forms","pages","watch","runtime","transitions","fetch","pinia","nuxt","template","server","config","directory","testing"]