Skip to main content
rule

002-security — Claude Code rule: security checks

002-security is a Claude Code rule that sets security requirements for AI-generated code. It applies across all project files.

MIT ★ 97 updated 2026-06-11

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/002-security.mdc
Open on GitHub

What 002-security does

The rule calls for schema validation of user input, HTML sanitization before rendering, and checks on uploaded files’ MIME type, extension, and size. SQL must use parameterized queries; user input must not reach shell commands or eval().

Credentials belong in environment variables, and JWT validation must pin the algorithm. The rule also covers cookie flags, rate limits, explicit CORS origins, request size limits, and HTTP security headers. A human must review all AI-generated code.

What it helps with

  • validate user input against a schema
  • prevent SQL injection by using parameterized queries
  • keep user input out of shell commands
  • secure API endpoints with rate limits and explicit CORS origins
  • keep credentials out of source and client-side code

Example prompts for the agent

  • Check this file against the 002-security requirements.
  • Add schema validation and HTML sanitization for this input.
  • Review this API handler for security issues covered by 002-security.

How to install 002-security

Manually: put the files in place

.cursor/rules/002-security.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about 002-security

How do I install 002-security in Claude Code?

Add the rule file at .claude/rules/002-security.md.

What does 002-security do?

It sets requirements for input validation, injection prevention, secret handling, and API security across project files.

Which platforms support 002-security?

It is listed for Claude Code, Cursor, GitHub Copilot, Cline, Codex, and Windsurf (Devin Desktop).

Source text

002-security.mdc · MIT
---
description: Security rules for AI-generated code — applied to all files
globs:
alwaysApply: true
---

# Security Rules

## Core Principles
- All AI-generated code requires human security review
- Trust nothing, verify everything
- Defense in depth: multiple security layers
- Principle of least privilege

## Input Validation (MANDATORY)
- Validate ALL user input with schema validation (Zod, Pydantic, etc.)
- Never trust client-side data
- Sanitize HTML content before rendering
- Validate file uploads: MIME type, extension, max size

## Injection Prevention
- NEVER concatenate SQL strings — use parameterized queries
- NEVER pass user input to shell commands
- NEVER use dangerouslySetInnerHTML without DOMPurify
- NEVER use eval() or Function() with user input

## Authentication & Secrets
- Never store secrets in source code or client-side code
- Use environment variables for all credentials
- Implement proper JWT validation with algorithm pinning
- Use httpOnly, secure, sameSite cookies

## API Security
- Rate limiting on all endpoints
- CORS configuration: explicit origins only
- Input size limits on all endpoints
- Proper HTTP security headers (CSP, HSTS, etc.)

© obviousworks · MIT · obviousworks/vibe-coding-ai-rules

Similar IDE rules

All IDE rules for Security →

From the same set7

Project sponsors

Companies that keep this analytics open