security

Security rules for validating input, protecting accounts and data, encoding output safely, hashing passwords, and securing sessions.

In plain words
What is it for?
Use them when designing or reviewing server-side validation, authentication, password handling, rate limits, cookies, database access, or output encoding.
Why use it?
They reduce common risks such as malformed input, injection, weak password storage, credential attacks, and unsafe authentication sessions.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nedcodes-ok/cursor-doctor/security
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursor-doctor
Per session 957 This file is loaded in full into every session.
When invoked 957 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00957 $0.00957
Opus 5 $0.00478 $0.00478
Sonnet 5 $0.00191 $0.00191
Haiku 4.5 $0.00096 $0.00096

Measured yesterday against content hash ff9ffb6717b3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

security scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

pro-kit/templates/practices/security.mdc · 45 lines

How it starts

The opening of the file, as written. The whole thing — 45 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Security Rules

Input Validation

  • Validate ALL user input on the server — type, length, format, range. Client-side validation is UX, not security
  • Allowlists over denylists: define what IS allowed, not what isn't. Denylists always miss something
  • Context-aware output encoding: HTML entities for HTML context, parameterized queries for SQL, shell escaping for commands. The same input needs different escaping in different outputs
  • Zod, Joi, Pydantic, or similar for structured validation — don't write regex for every field. Schema validation catches entire classes of malformed input at once
  • Reject unexpected fields, don't just ignore them. If your API accepts { name, email } and receives { name, email, isAdmin: true }, the extra field should cause an error or be stripped explicitly

Authentication

  • bcrypt (cost 12+) or Argon2id for password hashing — never MD5, SHA-256, or single-pass algorithms. If an attacker gets the database, bcrypt makes brute-force take years instead of hours
  • Rate limit auth endpoints: 5-10 attempts per IP per minute. After lockout, require CAPTCHA or temporary block — without this, credential stuffing is trivial
  • Session cookies: httpOnly (no JS access), secure (HTTPS only), sameSite: strict or lax (prevents CSRF). Missing any of these is a real vulnerability, not a nice-to-have
  • Implement actual logout: invalidate the session/token server-side. Just deleting the client cookie means a captured token still works
  • JWTs are not sessions: they can't be revoked until they expire. For applications that need instant revocation (admin ban, password change), use server-side sessions or a token blocklist

Authorization

  • Check permissions on every request server-side — hiding a button in the UI is not access control. Every API endpoint must verify the caller has permission
  • Object-level authorization: verifying a user is authenticated is not enough. Verify they own or have access to the specific resource: WHERE user_id = auth.uid() AND id = :requestedId
  • IDOR (Insecure Direct Object Reference) is the most common authorization bug: user changes /api/orders/123 to /api/orders/124 and sees someone else's order. Always verify ownership
  • Fail closed: if the permission check errors or is ambiguous, deny access. if (!hasPermission) deny not if (hasPermission) allow else maybe allow
  • Principle of least privilege: give each component/user/service the minimum access it needs. Database users for the app shouldn't have DROP TABLE permissions

Read the full file on GitHub · 45 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 45 lines · 957 tokens per session scan A ff9ffb6717b3

Subscribe to this mod's changes

security is a cursor rule published in the GitHub repository nedcodes-ok/cursor-doctor (9 stars, last pushed 5mo ago), licensed MIT. It adds 957 tokens to every session, about $0.0048 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.