agentleFS
sordi-aisordi-ai/skill-everything/.cursor/rules/security-review.mdc

skill-everything / rules

Cursor rule20 starsChanged 7 months agoMITView on GitHub

Apply when performing a security review, checking for vulnerabilities, or implementing authentication and authorization logic.

The file

Show its rules and text

We split this security-review.mdc into the rules it gives an agent

20 rules. About 0 are common, 15 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈15

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    AuthN/AuthZ separation: Always treat authentication (who are you?) and authorization (what can you do?) as distinct checks.

    line 17
  2. Distinctive:

    Resource ownership check: Always verify resource ownership in addition to role-based access on mutation endpoints — a valid role does not …

    line 18
  3. Distinctive:

    IDOR prevention: Never expose sequential or predictable resource IDs in URLs without a server-side ownership assertion.

    line 19
  4. Distinctive:

    Privilege escalation guard: Never allow a user to elevate their own role or grant permissions they do not already hold.

    line 20
  5. Distinctive:

    Token scope enforcement: Always validate that the token's declared scope covers the requested operation before executing it.

    line 21
  6. Distinctive:

    Session fixation prevention: Always regenerate the session identifier immediately after a successful login to prevent session fixation …

    line 25
  7. Distinctive:

    Idle and absolute timeouts: Ensure sessions carry both an idle timeout (e.g., 15 min) and an absolute expiry (e.g., 8 h).

    line 26
  8. Very specific:

    Secure cookie attributes: Always set HttpOnly, Secure, and SameSite=Strict (or Lax) on session cookies.

    line 27
  9. Distinctive:

    Logout invalidation: Always invalidate the server-side session record on logout.

    line 28
  10. Distinctive:

    Parameterized queries everywhere: Never construct database queries by string concatenation with user-supplied values.

    line 32
  11. Distinctive:

    Output encoding context: Always encode output in the context where it will be rendered (HTML entity encoding for HTML, JSON encoding for …

    line 33
  12. Distinctive:

    SSRF mitigation: Before making any server-side HTTP request to a URL derived from user input, validate the resolved IP against an allowlist.

    line 34
  13. Distinctive:

    File path traversal: Never concatenate user input into file system paths.

    line 35
  14. Very specific:

    CORS allowlist: Avoid wildcard Access-Control-Allow-Origin: * on endpoints that return authenticated data.

    line 39
  15. Very specific:

    CSP header: Ensure every HTML response includes a Content-Security-Policy header that restricts script-src to known origins.

    line 40
  16. Distinctive:

    Rate limiting on auth endpoints: Always apply rate limiting and exponential back-off to login, password-reset, and OTP endpoints.

    line 41
  17. Distinctive:

    Sensitive data in logs: Never log passwords, tokens, full credit-card numbers, or other PII.

    line 42
  18. Distinctive:

    Secret rotation readiness: Always design secret consumption so that rotating a credential requires only an environment variable update with …

    line 46
  19. Very specific:

    Dependency CVE scan: Before merging any PR that adds or upgrades a dependency, run a CVE scan (e.g., pip-audit, npm audit, trivy).

    line 47
  20. Distinctive:

    Audit logging on sensitive actions: Always emit a structured audit log entry (actor, action, resource ID, timestamp, outcome) for every …

    line 48

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
security-review.mdc
---
description: Apply when performing a security review, checking for vulnerabilities, or implementing authentication and authorization logic.
alwaysApply: false
---

# Sub-Skill: Security Review Depth
<!-- target: tokens_target above. Run `python tools/render_readme_table.py` to update README. -->

**Purpose:** Deep security rules for authentication, authorization, injection, session management, and API hardening. Complements code-quality rules 20–23 with IDOR, SSRF, and access-control depth.

---

## Rules

### Authentication vs. Authorization

1. **AuthN/AuthZ separation.** Always treat authentication (who are you?) and authorization (what can you do?) as distinct checks; never collapse them into a single boolean `is_logged_in` guard.
2. **Resource ownership check.** Always verify resource ownership in addition to role-based access on mutation endpoints — a valid role does not imply ownership of the target record. Reference: ERR-2026-019
3. **IDOR prevention.** Never expose sequential or predictable resource IDs in URLs without a server-side ownership assertion; use opaque UUIDs and always re-fetch the record to confirm the caller owns it.
4. **Privilege escalation guard.** Never allow a user to elevate their own role or grant permissions they do not already hold; enforce privilege changes through a separate admin-only path.
5. **Token scope enforcement.** Always validate that the token's declared scope covers the requested operation before executing it; reject tokens with insufficient scope with 403, not 401.

### Session Management

6. **Session fixation prevention.** Always regenerate the session identifier immediately after a successful login to prevent session fixation attacks.
7. **Idle and absolute timeouts.** Ensure sessions carry both an idle timeout (e.g., 15 min) and an absolute expiry (e.g., 8 h); never issue non-expiring session tokens.
8. **Secure cookie attributes.** Always set `HttpOnly`, `Secure`, and `SameSite=Strict` (or `Lax`) on session cookies; never omit any of these three attributes.
9. **Logout invalidation.** Always invalidate the server-side session record on logout; never rely solely on deleting the client-side cookie.

### Injection and Input Handling

10. **Parameterized queries everywhere.** Never construct database queries by string concatenation with user-supplied values; always use parameterized statements or an ORM that enforces binding.
11. **Output encoding context.** Always encode output in the context where it will be rendered (HTML entity encoding for HTML, JSON encoding for JSON responses, URL encoding for query strings); never apply a single generic escape.
12. **SSRF mitigation.** Before making any server-side HTTP request to a URL derived from user input, validate the resolved IP against an allowlist; block private RFC-1918 ranges and loopback addresses.
13. **File path traversal.** Never concatenate user input into file system paths; always resolve the canonical path and assert it falls within the expected base directory before opening.

### API and Transport Hardening

14. **CORS allowlist.** Avoid wildcard `Access-Control-Allow-Origin: *` on endpoints that return authenticated data; always enumerate trusted origins explicitly.
15. **CSP header.** Ensure every HTML response includes a `Content-Security-Policy` header that restricts `script-src` to known origins; never use `unsafe-inline` without a nonce or hash.
16. **Rate limiting on auth endpoints.** Always apply rate limiting and exponential back-off to login, password-reset, and OTP endpoints; never expose them without request throttling.
17. **Sensitive data in logs.** Never log passwords, tokens, full credit-card numbers, or other PII; mask or omit them before writing to any log sink.

### Secrets and Dependencies

18. **Secret rotation readiness.** Always design secret consumption so that rotating a credential requires only an environment variable update with no code change; never hard-code secrets or embed them in config files committed to version control.
19. **Dependency CVE scan.** Before merging any PR that adds or upgrades a dependency, run a CVE scan (e.g., `pip-audit`, `npm audit`, `trivy`); block merge if high-severity findings are unresolved.
20. **Audit logging on sensitive actions.** Always emit a structured audit log entry (actor, action, resource ID, timestamp, outcome) for every privileged or destructive operation; never skip audit logging for admin endpoints.

---

## See also

- `skills/code-quality/SKILL.md` — rules 20–23 cover sanitization, parameterized queries, and secret hygiene at a general level; this skill deepens those with IDOR, SSRF, and session specifics.
- `skills/error-log/SKILL.md` — ERR-2026-019 motivated rule 2 (resource ownership check).

---

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.