.cursorrules

Hardened Secure Cursor Rules for Personal Use

Views0
PublishedJan 15, 2026

Loading actions...

5 minBeginnerpromptSingle file

Skill content

Main instructions and any bundled files for this skill.

markdown

๐Ÿ” Global Security Constraints

  • โŒ Never hardcode secrets, tokens, passwords, API keys, or credentials.
    โœ… Always reference them from process.env, Vault, or encrypted config stores.

  • โŒ Disallow insecure code execution: eval, Function, exec, spawn("sh"), vm.runInContext().

  • โŒ Do not concatenate strings for SQL.
    โœ… Use query builders or parameterized methods only.

  • โŒ Do not log sensitive data: passwords, tokens, auth headers, PII.

  • โœ… Hash passwords with bcrypt, argon2, or scrypt โ€” never MD5 or SHA1.

  • โœ… Use HTTPS for all HTTP requests (unless explicitly localhost for dev).

  • โœ… All user inputs must be sanitized and validated with schema tools (e.g. Zod, Joi).

  • โŒ Never weaken or remove secure headers (CSP, CORS, HSTS, X-Frame-Options).

  • Security:

    • Never hardcode secrets
    • use os.Getenv() or config stores
    • ensure any user-controllable paths are not subject to path traversal
    • Define hard limits on any user-controllable data sources (e.,g. buffers, web requests)

๐Ÿ›ก๏ธ Supply Chain Security

  • Prefer using the standard library for common functionality instead of installing dependencies

๐Ÿ›ก๏ธ Code Quality

  • Constants Use constants and/or descriptive variable names instead of magic numbers
  • Error Handling: Always check errors, use descriptive error messages, and define errors at the top of relevant files rather than declaring them in-line

๐Ÿ›ก๏ธ Secure Defaults

  • Assume the following unless explicitly overridden:
    • CORS: deny, no credentials
    • Cookies: HttpOnly, Secure, SameSite=Strict
    • HTTP headers: HSTS, X-Content-Type-Options, Referrer-Policy, etc.
    • Deny file access to .env, .ssh/, secrets.*, /etc, ~/ unless explicitly allowed.
  • In web contexts:
    • Encode dynamic content
    • Block inline event handlers unless sanitized
  • In Docker/bash:
    • No curl | bash, no plaintext secrets
    • Use COPY with checksums; use secret mounts/env for credentials
  • Use modern and recommended patterns in the programming language
  • Prefer standard library implementations over third-party packages

๐Ÿงผ Hygiene Enforcement

  • .cursorignore must exclude:
    • .env, *.pem, *.key, secrets.*, credentials.json, private/, .ssh/
  • Include a rule-check marker:

    // RULE-CHECK: Secure rules active

  • Generated code must include:

    // [SECURITY INTENT]: What this protects.
    Especially for: validation, auth, crypto, DB, or network access.


๐Ÿง  Reasoning Requirements

  • For sensitive operations, Cursor must add:

    // [SECURITY REASONING]: This approach is safe because...

  • If unsure about destructive or high-privilege actions, ask for confirmation before proceeding.

๐Ÿงฉ Context-Specific Controls

๐Ÿ”™ Backend

  • Sanitize and validate all input from req.body, req.params, cookies, headers.
  • No dynamic imports or require(varName) logic.

๐ŸŒ Frontend

  • Escape/encode untrusted content.
  • Disallow dangerouslySetInnerHTML unless sanitized with DOMPurify or equivalent.

โš™๏ธ DevOps

  • No embedded secrets in Dockerfiles, bash scripts, or Compose files.
  • Prefer secrets: mounts or ENV injection.

๐Ÿ›‘ Enforcement Policy

  • If a request requires violating any rule:

    โ€œโš ๏ธ This violates hardened security constraints. Action blocked.โ€

  • If unsure:

    โ€œโš ๏ธ Unclear if this action is secure. Please clarify intent or constraints.โ€


๐Ÿ“œ Auditing Tags (optional, for tracing)

  • Tag all secure code output with:

    // [AI GENERATED SECURE CODE]


Prompt Playground

3 Variables

Fill Variables

Preview

---
description: "Hardened Secure Cursor Rules for Personal Use"
version: "1.0"
alwaysApply: true
tags: ["security", "strict", "backend", "frontend", "DevOps", "AI coding"]
---

## ๐Ÿ” Global Security Constraints

- โŒ Never hardcode secrets, tokens, passwords, API keys, or credentials.  
  โœ… Always reference them from `process.env`, Vault, or encrypted config stores.
- โŒ Disallow insecure code execution: `eval`, `Function`, `exec`, `spawn("sh")`, `vm.runInContext()`.
- โŒ Do not concatenate strings for SQL.  
  โœ… Use query builders or parameterized methods only.
- โŒ Do not log sensitive data: passwords, tokens, auth headers, PII.
- โœ… Hash passwords with `bcrypt`, `argon2`, or `scrypt` โ€” **never** MD5 or SHA1.
- โœ… Use HTTPS for all HTTP requests (unless explicitly `localhost` for dev).
- โœ… All user inputs must be sanitized and validated with schema tools (e.g. Zod, Joi).
- โŒ Never weaken or remove secure headers (CSP, CORS, HSTS, X-Frame-Options).

- **Security**: 
  - Never hardcode secrets
  - use `os.Getenv()` or config stores
  - ensure any user-controllable paths are not subject to path traversal
  - Define hard limits on any user-controllable data sources (e.,g. buffers, web requests)

---

## ๐Ÿ›ก๏ธ Supply Chain Security

- Prefer using the standard library for common functionality instead of installing dependencies

---

## ๐Ÿ›ก๏ธ Code Quality
- **Constants** Use constants and/or descriptive variable names instead of magic numbers
- **Error Handling**: Always check errors, use descriptive error messages, and define errors at the top of relevant files rather than declaring them in-line

---

## ๐Ÿ›ก๏ธ Secure Defaults

- Assume the following unless explicitly overridden:
  - CORS: `deny`, no credentials
  - Cookies: `HttpOnly`, `Secure`, `SameSite=Strict`
  - HTTP headers: HSTS, X-Content-Type-Options, Referrer-Policy, etc.
  - Deny file access to `.env`, `.ssh/`, `secrets.*`, `/etc`, `~/` unless explicitly allowed.
- In web contexts:
  - Encode dynamic content
  - Block inline event handlers unless sanitized
- In Docker/bash:
  - No `curl | bash`, no plaintext secrets
  - Use `COPY` with checksums; use secret mounts/env for credentials
- Use modern and recommended patterns in the programming language
- Prefer standard library implementations over third-party packages

---

## ๐Ÿงผ Hygiene Enforcement

- `.cursorignore` must exclude:
  - `.env`, `*.pem`, `*.key`, `secrets.*`, `credentials.json`, `private/`, `.ssh/`
- Include a rule-check marker:
  > `// RULE-CHECK: Secure rules active`
- Generated code must include:
  > `// [SECURITY INTENT]: What this protects.`  
  Especially for: validation, auth, crypto, DB, or network access.

---

## ๐Ÿง  Reasoning Requirements

- For sensitive operations, Cursor must add:
  > `// [SECURITY REASONING]: This approach is safe because...`
- If unsure about destructive or high-privilege actions, ask for confirmation before proceeding.

---

## ๐Ÿงฉ Context-Specific Controls

### ๐Ÿ”™ Backend
- Sanitize and validate all input from `req.body`, `req.params`, cookies, headers.
- No dynamic imports or `require(varName)` logic.

### ๐ŸŒ Frontend
- Escape/encode untrusted content.
- Disallow `dangerouslySetInnerHTML` unless sanitized with DOMPurify or equivalent.

### โš™๏ธ DevOps
- No embedded secrets in Dockerfiles, bash scripts, or Compose files.
- Prefer `secrets:` mounts or ENV injection.

---

## ๐Ÿ›‘ Enforcement Policy

- If a request requires violating any rule:
  > โ€œโš ๏ธ This violates hardened security constraints. Action blocked.โ€

- If unsure:
  > โ€œโš ๏ธ Unclear if this action is secure. Please clarify intent or constraints.โ€

---

## ๐Ÿ“œ Auditing Tags (optional, for tracing)

- Tag all secure code output with:
  > `// [AI GENERATED SECURE CODE]`

---

Share: