cursor-handbook / security
Cursor rule31 starsChanged 3 months agoMITView on GitHub
Security guardrails applied to all AI interactions
- Reads credentials
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,531 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository30 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/architecture/core-principles.mdcCursor rule
- .cursor/rules/architecture/dependency-management.mdcCursor rule
- .cursor/rules/architecture/token-efficiency.mdcCursor rule
- .cursor/rules/backend/api-design.mdcCursor rule
- .cursor/rules/backend/code-organization.mdcCursor rule
- .cursor/rules/backend/error-handling.mdcCursor rule
- .cursor/rules/backend/handler-patterns.mdcCursor rule
- .cursor/rules/backend/nodejs.mdcCursor rule
- .cursor/rules/backend/typescript.mdcCursor rule
- .cursor/rules/cloud/containerization.mdcCursor rule
- .cursor/rules/cloud/infrastructure.mdcCursor rule
- .cursor/rules/cloud/serverless.mdcCursor rule
- .cursor/rules/database/migration-rules.mdcCursor rule
- .cursor/rules/database/query-patterns.mdcCursor rule
- .cursor/rules/database/schema-design.mdcCursor rule
- .cursor/rules/devops/ci-cd.mdcCursor rule
- .cursor/rules/devops/documentation-standards.mdcCursor rule
- .cursor/rules/devops/monitoring.mdcCursor rule
- .cursor/rules/frontend/accessibility.mdcCursor rule
- .cursor/rules/frontend/component-patterns.mdcCursor rule
- .cursor/rules/frontend/performance.mdcCursor rule
- .cursor/rules/frontend/state-management.mdcCursor rule
- .cursor/rules/main-rules.mdcCursor rule
- .cursor/rules/security/secrets-rules.mdcCursor rule
- .cursor/rules/security/security-compliance.mdcCursor rule
- .cursor/rules/testing/integration-testing.mdcCursor rule
- .cursor/rules/testing/mock-patterns.mdcCursor rule
- .cursor/rules/testing/testing-standards.mdcCursor rule
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
- Very specific: line 16
ALWAYS: use environment variables: process.env.VARIABLE_NAME
- Distinctive: line 17
ALWAYS: use a secrets manager for production: AWS Secrets Manager, Vault, etc.
- Very specific: line 27
When logging user-related operations, use only: userId, sessionId, correlationId
- Distinctive: line 45
Use allowlists over denylists
- Distinctive: line 51
Never store passwords in plain text
- Distinctive: line 52
Use bcrypt/argon2 for password hashing
- Distinctive: line 54
Use short-lived tokens with refresh mechanism
- Distinctive: line 58
Before approving any code change, verify:
- Very specific: line 69
Don't use eval() or new Function() — use safe alternatives
- Very specific: line 77
Don't log req.body or res — may contain secrets or PII
- Very specific: line 78
Don't put secrets in .env.example — use placeholders like YOUR_API_KEY
- Very specific: line 79
Don't use any for user input — always type and validate
- Distinctive: line 80
Don't expose internal errors — map to generic messages for clients
- Distinctive: line 85
Rate limit bypass: Use consistent key (IP + user ID when authenticated)
≈ “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.
Files
---
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
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
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.

