AgentsConfigHelper / rules
Cursor rule2 starsChanged 3 months agoMITView on GitHub
Session management and secure cookies (rotation, fixation, timeouts, theft detection)
We split this codeguard-0-session-management-and-cookies.mdc into the rules it gives an agent
9 rules. About 0 are common, 7 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Use generic cookie names (e.g., id) rather than framework defaults.
- Distinctive: line 21
Prefer non-persistent session cookies (no Expires/Max-Age).
- Distinctive: line 29
Create sessions only server-side.
- Distinctive: line 31
Use distinct pre‑auth and post‑auth cookie names if framework patterns require it.
- Distinctive: line 48
Always regenerate the session ID when potential hijacking is detected.
- Very specific: line 51
Do not store session tokens in localStorage/sessionStorage due to XSS risk.
- Distinctive: line 52
If client-side storage is unavoidable for non-session secrets, isolate via Web Workers and never expose in page context.
- Distinctive: line 55
Prefer built-in session frameworks.
- Distinctive: line 70
No client storage of session tokens.
≈ “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: Session management and secure cookies (rotation, fixation, timeouts, theft detection) globs: **/*.c,**/*.go,**/*.h,**/*.htm,**/*.html,**/*.java,**/*.js,**/*.jsx,**/*.mjs,**/*.php,**/*.py,**/*.pyi,**/*.pyx,**/*.rb,**/*.ts,**/*.tsx version: 1.0.1 --- rule_id: codeguard-0-session-management-and-cookies ## Session Management & Cookies Implement robust, attack-resistant session handling that prevents fixation, hijacking, and theft while maintaining usability. ### Session ID Generation and Properties - Generate session IDs with a CSPRNG; ≥64 bits of entropy (prefer 128+). Opaque, unguessable, and free of meaning. - Use generic cookie names (e.g., `id`) rather than framework defaults. Reject any incoming ID not created by the server. - Store all session data server-side; never embed PII or privileges in the token. If sensitive, encrypt server-side session store at rest. ### Cookie Security Configuration - Set `Secure`, `HttpOnly`, `SameSite=Strict` (or `Lax` if necessary for flows) on session cookies. - Scope cookies narrowly with `Path` and `Domain`. Avoid cross-subdomain exposure. - Prefer non-persistent session cookies (no Expires/Max-Age). Require full HTTPS; enable HSTS site-wide. Example header: ``` Set-Cookie: id=<opaque>; Secure; HttpOnly; SameSite=Strict; Path=/ ``` ### Session Lifecycle and Rotation - Create sessions only server-side; treat provided IDs as untrusted input. - Regenerate session ID on authentication, password changes, and any privilege elevation. Invalidate the prior ID. - Use distinct pre‑auth and post‑auth cookie names if framework patterns require it. ### Expiration and Logout - Idle timeout: 2–5 minutes for high-value, 15–30 minutes for lower risk. Absolute timeout: 4–8 hours. - Enforce timeouts server-side. Provide a visible logout button that fully invalidates the server session and clears the cookie client-side. ### Transport and Caching - Enforce HTTPS for the entire session journey. Never mix HTTP/HTTPS in one session. - Send `Cache-Control: no-store` on responses containing session identifiers or sensitive data. ### Cookie Theft Detection and Response - Fingerprint session context server-side at establishment (IP, User-Agent, Accept-Language, relevant `sec-ch-ua` where available). - Compare incoming requests to the stored fingerprint, allowing for benign drift (e.g., subnet changes, UA updates). - Risk-based responses: - High risk: require re-authentication; rotate session ID. - Medium risk: step-up verification (challenge); rotate session ID. - Low risk: log suspicious activity. - Always regenerate the session ID when potential hijacking is detected. ### Client-Side Storage - Do not store session tokens in `localStorage`/`sessionStorage` due to XSS risk. Prefer HttpOnly cookies for transport. - If client-side storage is unavoidable for non-session secrets, isolate via Web Workers and never expose in page context. ### Framework and Multi-Cookie Scenarios - Prefer built-in session frameworks; keep them updated and hardened. - Validate relationships when multiple cookies participate in session state; avoid same cookie names across paths/domains. ### Monitoring and Telemetry - Log session lifecycle events (creation, rotation, termination) using salted hashes of the session ID, not raw values. - Monitor for brute force of session IDs and anomalous concurrent usage. ### Implementation Checklist 1) CSPRNG session IDs (≥64 bits entropy), opaque and server-issued only. 2) Cookie flags: `Secure`, `HttpOnly`, `SameSite` set; tight domain/path. 3) HTTPS-only with HSTS; no mixed content. 4) Regenerate IDs on auth and privilege changes; invalidate old IDs. 5) Idle and absolute timeouts enforced server-side; full logout implemented. 6) `Cache-Control: no-store` for sensitive responses. 7) Server-side fingerprinting and risk-based responses to anomalies. 8) No client storage of session tokens; framework defaults hardened.
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-authentication-mfa.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-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.

