agentleFS
girijashankarjgirijashankarj/cursor-handbook/.cursor/rules/security/guardrails.mdc

cursor-handbook / security

Cursor rule31 starsChanged 3 months agoMITView on GitHub

Security guardrails applied to all AI interactions

  • Reads credentials

The file

Show its rules and text

We split this guardrails.mdc into the rules it gives an agent

14 rules. About 0 are common, 8 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    ALWAYS: use environment variables: process.env.VARIABLE_NAME

    line 16
  2. Distinctive:

    ALWAYS: use a secrets manager for production: AWS Secrets Manager, Vault, etc.

    line 17
  3. Very specific:

    When logging user-related operations, use only: userId, sessionId, correlationId

    line 27
  4. Distinctive:

    Use allowlists over denylists

    line 45
  5. Distinctive:

    Never store passwords in plain text

    line 51
  6. Distinctive:

    Use bcrypt/argon2 for password hashing

    line 52
  7. Distinctive:

    Use short-lived tokens with refresh mechanism

    line 54
  8. Distinctive:

    Before approving any code change, verify:

    line 58
  9. Very specific:

    Don't use eval() or new Function() — use safe alternatives

    line 69
  10. Very specific:

    Don't log req.body or res — may contain secrets or PII

    line 77
  11. Very specific:

    Don't put secrets in .env.example — use placeholders like YOUR_API_KEY

    line 78
  12. Very specific:

    Don't use any for user input — always type and validate

    line 79
  13. Distinctive:

    Don't expose internal errors — map to generic messages for clients

    line 80
  14. Distinctive:

    Rate limit bypass: Use consistent key (IP + user ID when authenticated)

    line 85

≈ “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
guardrails.mdc
---
description: "Security guardrails applied to all AI interactions"
alwaysApply: true
---

# Security Guardrails

## Absolute Rules (NEVER Violate)

### 1. Secrets Management
- **NEVER** hardcode any of the following in source code:
  - API keys, tokens, or credentials
  - Database connection strings with passwords
  - Private keys or certificates
  - Webhook URLs with secrets
- **ALWAYS** use environment variables: `process.env.VARIABLE_NAME`
- **ALWAYS** use a secrets manager for production: AWS Secrets Manager, Vault, etc.
- Reference secrets via: `{{CONFIG.techStack.cloud}}` secrets manager

### 2. PII Protection
- **NEVER** log personally identifiable information:
  - Full names, email addresses, phone numbers
  - Social Security Numbers, tax IDs
  - Credit card numbers, bank account numbers
  - IP addresses (in most contexts)
  - Physical addresses, dates of birth
- When logging user-related operations, use only: `userId`, `sessionId`, `correlationId`
- Mask data in logs: `email: "j***@example.com"`, `phone: "***-***-1234"`

### 3. Infrastructure Obfuscation
- **NEVER** include real infrastructure names in:
  - Code comments
  - Documentation
  - Error messages shown to users
  - Git commit messages
- Use generic placeholders:
  - `[AWS_ACCOUNT_ID]` instead of actual account numbers
  - `[QUEUE_NAME]` instead of actual SQS/queue names
  - `[API_ENDPOINT]` instead of actual URLs
  - `[BUCKET_NAME]` instead of actual S3 bucket names
  - `[DB_HOST]` instead of actual database hostnames

### 4. Input Validation
- Validate ALL user input at the API boundary
- Use allowlists over denylists
- Sanitize data before database queries (parameterized queries only)
- Validate file uploads: type, size, content
- Rate limit all public endpoints

### 5. Authentication & Authorization
- Never store passwords in plain text
- Use bcrypt/argon2 for password hashing
- Implement proper session management
- Use short-lived tokens with refresh mechanism
- Apply principle of least privilege for all operations

## Code Review Security Checklist
Before approving any code change, verify:
- [ ] No hardcoded secrets or credentials
- [ ] No PII in logs or error messages
- [ ] Input validation on all external inputs
- [ ] Parameterized database queries (no string concatenation)
- [ ] Proper error handling (no stack traces to users)
- [ ] Authentication checks on protected routes
- [ ] Authorization checks for resource access
- [ ] No sensitive data in URL parameters

## Anti-patterns
- Don't use `eval()` or `new Function()` — use safe alternatives

```ts
// BAD
const fn = new Function('x', 'return x * 2');

// GOOD: Use explicit logic or a schema validator
```
- Don't log `req.body` or `res` — may contain secrets or PII
- Don't put secrets in `.env.example` — use placeholders like `YOUR_API_KEY`
- Don't use `any` for user input — always type and validate
- Don't expose internal errors — map to generic messages for clients

## Edge Cases
- **File uploads**: Validate MIME type, size, and scan for malware
- **JSON payloads**: Limit depth and size; reject malformed early
- **Rate limit bypass**: Use consistent key (IP + user ID when authenticated)

## Related
- See `@secrets-rules` for env var patterns
- See `@BUGBOT` for PR review rules

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.