AgentsConfigHelper / rules
Cursor rule2 starsChanged 3 months agoMITView on GitHub
Authentication and MFA best practices (passwords, MFA, OAuth/OIDC, SAML, recovery, tokens)
We split this codeguard-0-authentication-mfa.mdc into the rules it gives an agent
12 rules. About 0 are common, 12 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Use non-public, random, and unique internal user identifiers.
- Distinctive: line 15
Always return generic error messages (e.g., "Invalid username or password").
- Distinctive: line 20
Check new passwords against breach corpora (e.g., k‑anonymity APIs).
- Distinctive: line 47
Use standard protocols only.
- Distinctive: line 49
Prefer Authorization Code with PKCE for public/native apps.
- Distinctive: line 57
Keep response lifetimes short.
- Distinctive: line 60
Prefer opaque server‑managed tokens for simplicity and revocation.
- Distinctive: line 63
Consider binding tokens to a client context (e.g., fingerprint hash in cookie) to reduce replay.
- Distinctive: line 69
Use HTTPS reset links to pinned, trusted domains.
- Distinctive: line 70
After reset: require re‑authentication, rotate sessions, and do not auto‑login.
- Distinctive: line 71
Never lock accounts due to reset attempts.
- Distinctive: line 75
Use distinct session contexts and stricter timeouts for admin operations.
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
--- description: Authentication and MFA best practices (passwords, MFA, OAuth/OIDC, SAML, recovery, tokens) globs: **/*.c,**/*.go,**/*.h,**/*.java,**/*.js,**/*.jsx,**/*.kt,**/*.kts,**/*.m,**/*.mjs,**/*.php,**/*.py,**/*.pyi,**/*.pyx,**/*.rb,**/*.swift,**/*.ts,**/*.tsx version: 1.0.1 --- rule_id: codeguard-0-authentication-mfa ## Authentication & MFA Build a resilient, user-friendly authentication system that resists credential attacks, protects secrets, and supports strong, phishing-resistant MFA and secure recovery. ### Account Identifiers and UX - Use non-public, random, and unique internal user identifiers. Allow login via verified email or username. - Always return generic error messages (e.g., "Invalid username or password"). Keep timing consistent to prevent account enumeration. - Support password managers: `<input type="password">`, allow paste, no JS blocks. ### Password Policy - Accept passphrases and full Unicode; minimum 8 characters; avoid composition rules. Set only a reasonable maximum length (64+). - Check new passwords against breach corpora (e.g., k‑anonymity APIs); reject breached/common passwords. ### Password Storage (Hashing) - Hash, do not encrypt. Use slow, memory‑hard algorithms with unique per‑user salts and constant‑time comparison. - Preferred order and parameters (tune to your hardware; target <1s on server): - Argon2id: m=19–46 MiB, t=2–1, p=1 (or equivalent security trade‑offs) - scrypt: N=2^17, r=8, p=1 (or equivalent) - bcrypt (legacy only): cost ≥10, be aware of 72‑byte input limit - PBKDF2 (FIPS): PBKDF2‑HMAC‑SHA‑256 ≥600k, or SHA‑1 ≥1.3M - Optional pepper: store outside DB (KMS/HSM); if used, apply via HMAC or pre‑hashing. Plan for user resets if pepper rotates. - Unicode and null bytes must be supported end‑to‑end by the library. ### Authentication Flow Hardening - Enforce TLS for all auth endpoints and token transport; enable HSTS. - Implement rate limits per IP, account, and globally; add proof‑of‑work or CAPTCHA only as last resort. - Lockouts/throttling: progressive backoff; avoid permanent lockout via resets/alerts. - Uniform responses and code paths to reduce oracle/timing signals. ### Multi‑Factor Authentication (MFA) - Adopt phishing‑resistant factors by default for sensitive accounts: passkeys/WebAuthn (FIDO2) or hardware U2F. - Acceptable: TOTP (app‑based), smart cards with PIN. Avoid for sensitive use: SMS/voice, email codes; never rely on security questions. - Require MFA for: login, password/email changes, disabling MFA, privilege elevation, high‑value transactions, new devices/locations. - Risk‑based MFA signals: new device, geo‑velocity, IP reputation, unusual time, breached credentials. - MFA recovery: provide single‑use backup codes, encourage multiple factors, and require strong identity verification for resets. - Handle failed MFA: offer alternative enrolled methods, notify users of failures, and log context (no secrets). ### Federation and Protocols (OAuth 2.0 / OIDC / SAML) - Use standard protocols only; do not build your own. - OAuth 2.0/OIDC: - Prefer Authorization Code with PKCE for public/native apps; avoid Implicit and ROPC. - Validate state and nonce; use exact redirect URI matching; prevent open redirects. - Constrain tokens to audience/scope; use DPoP or mTLS for sender‑constraining when possible. - Rotate refresh tokens; revoke on logout or risk signals. - SAML: - TLS 1.2+; sign responses/assertions; encrypt sensitive assertions. - Validate issuers, InResponseTo, timestamps (NotBefore/NotOnOrAfter), Recipient; verify against trusted keys. - Prevent XML signature wrapping with strict schema validation and hardened XPath selection. - Keep response lifetimes short; prefer SP‑initiated flows; validate RelayState; implement replay detection. ### Tokens (JWT and Opaque) - Prefer opaque server‑managed tokens for simplicity and revocation. If using JWTs: - Explicitly pin algorithms; reject "none"; validate iss/aud/exp/iat/nbf; use short lifetimes and rotation. - Store secrets/keys securely (KMS/HSM). Use strong HMAC secrets or asymmetric keys; never hardcode. - Consider binding tokens to a client context (e.g., fingerprint hash in cookie) to reduce replay. - Implement denylist/allowlist for revocation on logout and critical events. ### Recovery and Reset - Return the same response for existing and non‑existing accounts (no enumeration). Normalize timing. - Generate 32+ byte, CSPRNG tokens; single‑use; store as hashes; short expiry. - Use HTTPS reset links to pinned, trusted domains; add referrer policy (no‑referrer) on UI. - After reset: require re‑authentication, rotate sessions, and do not auto‑login. - Never lock accounts due to reset attempts; rate‑limit and monitor instead. ### Administrative and Internal Accounts - Separate admin login from public forms; enforce stronger MFA, device posture checks, IP allowlists, and step‑up auth. - Use distinct session contexts and stricter timeouts for admin operations. ### Monitoring and Signals - Log auth events (failures/successes, MFA enroll/verify, resets, lockouts) with stable fields and correlation IDs; never log secrets or raw tokens. - Detect credential stuffing: high failure rates, many IPs/agents, impossible travel. Notify users of new device logins. ### Implementation Checklist - Passwords: Argon2id (preferred) with per‑user salt, constant‑time verify; breached password checks on change/set. - MFA: WebAuthn/passkeys or hardware tokens for high‑risk; TOTP as fallback; secure recovery with backup codes. - Federation: Authorization Code + PKCE; strict redirect URI validation; audience/scope enforced; token rotation. - Tokens: short‑lived, sender‑constrained where possible; revocation implemented; secrets in KMS/HSM. - Recovery: single‑use, hashed, time‑boxed tokens; consistent responses; re‑auth required after reset; sessions rotated. - Abuse: rate limits, throttling, and anomaly detection on auth endpoints; uniform error handling. - Admin: isolated flows with stricter policies and device checks. ### Test Plan - Unit/integration tests for login, MFA enroll/verify, resets, and lockouts with uniform errors. - Protocol tests: PKCE, state/nonce, redirect URI validation, token audience/scope. - Dynamic tests for credential stuffing resistance and token replay; validate revocation after logout and role change.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/codeguard-0-additional-cryptography.mdcCursor rule
- .cursor/rules/codeguard-0-api-web-services.mdcCursor rule
- .cursor/rules/codeguard-0-authorization-access-control.mdcCursor rule
- .cursor/rules/codeguard-0-client-side-web-security.mdcCursor rule
- .cursor/rules/codeguard-0-cloud-orchestration-kubernetes.mdcCursor rule
- .cursor/rules/codeguard-0-data-storage.mdcCursor rule
- .cursor/rules/codeguard-0-devops-ci-cd-containers.mdcCursor rule
- .cursor/rules/codeguard-0-file-handling-and-uploads.mdcCursor rule
- .cursor/rules/codeguard-0-framework-and-languages.mdcCursor rule
- .cursor/rules/codeguard-0-iac-security.mdcCursor rule
- .cursor/rules/codeguard-0-input-validation-injection.mdcCursor rule
- .cursor/rules/codeguard-0-logging.mdcCursor rule
- .cursor/rules/codeguard-0-mobile-apps.mdcCursor rule
- .cursor/rules/codeguard-0-privacy-data-protection.mdcCursor rule
- .cursor/rules/codeguard-0-safe-c-functions.mdcCursor rule
- .cursor/rules/codeguard-0-session-management-and-cookies.mdcCursor rule
- .cursor/rules/codeguard-0-supply-chain-security.mdcCursor rule
- .cursor/rules/codeguard-0-xml-and-serialization.mdcCursor rule
- .cursor/rules/codeguard-1-crypto-algorithms.mdcCursor rule
- .cursor/rules/codeguard-1-digital-certificates.mdcCursor rule
- .cursor/rules/codeguard-1-hardcoded-credentials.mdcCursor rule
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

