433-backend-security

A set of backend and API security rules based on common OWASP guidance. It covers checking incoming data, controlling access, protecting secrets, preventing SQL injection, and limiting error details.

In plain words
What is it for?
It is for reviewing or building backend services and APIs with validated requests, secure authentication, protected secrets, safe database access, and generic client errors.
Why use it?
It helps prevent unsafe input, unauthorized actions, leaked credentials, database attacks, and overly revealing error messages.

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/hamzaamjad/cursor-rules/433-backend-security
Clone the repo
git clone --depth 1 https://github.com/hamzaamjad/cursor-rules
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,104 The whole file, excluding the scripts and references it only reads on demand.
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.00000 $0.01104
Opus 5 $0.00000 $0.00552
Sonnet 5 $0.00000 $0.00221
Haiku 4.5 $0.00000 $0.00110

Measured 2d ago against content hash 6b626acb63ca, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

433-backend-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 2d ago.

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.

rules/400-patterns/433-backend-security.mdc · 65 lines

How it starts

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

backend-security.mdc

  • Purpose: To enforce fundamental security best practices for backend and API development, aligning with OWASP recommendations.
  • Requirements:
    1. Input Validation: All external/untrusted data (request bodies, params, headers) MUST be validated and sanitized using a schema validation library (e.g., zod, pydantic, express-validator). Validate type, format, length, and range.
    2. Authentication & Authorization:
      • Use secure, framework-recommended session management (e.g., HTTPS-only, SameSite cookies).
      • Implement proper authorization checks for all sensitive endpoints/operations.
      • Rotate secrets (API keys, JWT secrets) periodically (default: quarterly, document exceptions). Store secrets securely (env vars loaded from vault/KMS in prod/stage, .env for local dev ONLY), never commit to VCS.
    3. SQL & Data Access:
      • Use parameterized queries or ORM methods that prevent SQL injection by default.
      • Direct use of raw SQL execution functions (e.g., ORM .raw()) requires explicit justification and review for injection vulnerabilities.
    4. Error Handling:
      • Return generic error messages/codes (e.g., HTTP 4xx/5xx) to clients.
      • NEVER expose stack traces, sensitive configuration details, or PII in error responses. Log detailed errors internally.
    5. Logging:
      • Include correlation IDs (requestId, traceId) in logs. Include authenticated userId where applicable.
      • Scrub or mask sensitive data (passwords, PII, secrets) before logging payloads.
    6. Rate Limiting: Implement rate limiting on public endpoints, especially authentication routes (e.g., per IP, per API key), with exponential backoff on failures.
    7. Dependency Management: Regularly scan dependencies for vulnerabilities (e.g., weekly npm audit --prod / pip-audit). Patch Critical/High severity vulnerabilities promptly (define SLA, e.g., within 7 days).
    8. Secrets Management: Use appropriate mechanisms for environment (e.g., Vault, AWS Secrets Manager, GCP Secret Manager for prod/stage; .env file loaded via dotenv for local development ONLY).
    9. (Placeholder) Incorporate specific checks from @security-checklist.md once available.
  • Validation:
    • Check (Static Analysis/Linting): Configure linters (e.g., ESLint security plugins, Bandit for Python) to detect common vulnerabilities like lack of input validation, use of raw SQL, insecure cookie settings.
    • Check (Code Review): Explicitly review areas using raw SQL, handling sensitive data, authentication/authorization logic. Verify secret management practices. Verify presence of schema validation on input boundaries. Check error responses for information leakage.
    • Check (Testing): Security tests should attempt to bypass validation, trigger errors, exploit potential injection points. Dependency scan results must be checked in CI.
    • Check: Is @security-checklist.md integrated or its content addressed? (Needs Clarification)
  • Examples:
    • Input Validation (Pydantic):
      from pydantic import BaseModel, Field, EmailStr
      
      class UserSignup(BaseModel):
          email: EmailStr
          password: str = Field(min_length=8)
          full_name: str = Field(max_length=100)
      
    • Error Handling (Generic):
      // Bad: Leaks details
      // app.use((err, req, res, next) => { res.status(500).send(err.stack); });
      // Good: Logs detail, returns generic error
      app.use((err, req, res, next) => {
        console.error(`[${req.id}] Error processing request: ${err.message}`, err.stack);
        res.status(500).json({ error: 'Internal Server Error' });
      });
      
  • Changes: Updated to include recent security vulnerabilities and mitigation strategies for backend systems, including enhanced logging practices and dependency management.
  • Readiness: Needs Clarification (regarding content/location of @security-checklist.md). Assuming it contains more specific checks, it needs to be obtained and integrated.
  • Source References: .cursor/rules/backend-security.mdc; OWASP Top 10; pydantic docs; zod docs.

Read the full file on GitHub · 65 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. 2d ago First seen · 65 lines · 0 tokens per session scan A 6b626acb63ca

Subscribe to this mod's changes

433-backend-security is a cursor rule published in the GitHub repository hamzaamjad/cursor-rules (2 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,104 tokens. 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.