AgentsConfigHelper / rules
Cursor rule2 starsChanged 3 months agoMITView on GitHub
Input validation and injection defense (SQL/LDAP/OS), parameterization, prototype pollution
We split this codeguard-0-input-validation-injection.mdc into the rules it gives an agent
14 rules. About 0 are common, 10 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Ensure untrusted input is validated and never interpreted as code.
- Distinctive: line 15
Treat all untrusted input as data, never as code.
- Distinctive: line 26
Use prepared statements and parameterized queries for 100% of data access.
- Distinctive: line 27
Use bind variables for any dynamic SQL construction within stored procedures and never concatenate user input into SQL.
- Distinctive: line 28
Prefer least‑privilege DB users and views.
- Distinctive: line 41
Always apply context‑appropriate escaping:
- Distinctive: line 45
Use least‑privilege LDAP connections with bind authentication.
- Very specific: line 48
Prefer built‑in APIs instead of shelling out (e.g., library calls over exec).
- Distinctive: line 49
If unavoidable, use structured execution that separates command and arguments (e.g., ProcessBuilder).
- Very specific: line 51
Use -- to delimit arguments where supported to prevent option injection.
- Distinctive: line 62
Use the platform’s parameterization features (JDBC PreparedStatement, .NET SqlCommand, Ruby ActiveRecord bind params, PHP PDO, SQLx bind, …
- Very specific: line 67
When objects are required, create with Object.create(null) or { __proto__: null } to avoid inherited prototypes.
- Very specific: line 69
Avoid unsafe deep merge utilities.
- Distinctive: line 78
No shell invocation for untrusted input.
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 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: Input validation and injection defense (SQL/LDAP/OS), parameterization, prototype pollution
globs: **/*.bash,**/*.c,**/*.ddl,**/*.dml,**/*.go,**/*.h,**/*.htm,**/*.html,**/*.java,**/*.js,**/*.jsx,**/*.mjs,**/*.php,**/*.ps1,**/*.py,**/*.pyi,**/*.pyx,**/*.rb,**/*.sh,**/*.sql,**/*.ts,**/*.tsx
version: 1.0.1
---
rule_id: codeguard-0-input-validation-injection
## Input Validation & Injection Defense
Ensure untrusted input is validated and never interpreted as code. Prevent injection across SQL, LDAP, OS commands, templating, and JavaScript runtime object graphs.
### Core Strategy
- Validate early at trust boundaries with positive (allow‑list) validation and canonicalization.
- Treat all untrusted input as data, never as code. Use safe APIs that separate code from data.
- Parameterize queries/commands; escape only as last resort and context‑specific.
### Validation Playbook
- Syntactic validation: enforce format, type, ranges, and lengths for each field.
- Semantic validation: enforce business rules (e.g., start ≤ end date, enum allow‑lists).
- Normalization: canonicalize encodings before validation; validate complete strings (regex anchors ^$); beware ReDoS.
- Free‑form text: define character class allow‑lists; normalize Unicode; set length bounds.
- Files: validate by content type (magic), size caps, and safe extensions; server‑generate filenames; scan; store outside web root.
### SQL Injection Prevention
- Use prepared statements and parameterized queries for 100% of data access.
- Use bind variables for any dynamic SQL construction within stored procedures and never concatenate user input into SQL.
- Prefer least‑privilege DB users and views; never grant admin to app accounts.
- Escaping is fragile and discouraged; parameterization is the primary defense.
Example (Java PreparedStatement):
```java
String custname = request.getParameter("customerName");
String query = "SELECT account_balance FROM user_data WHERE user_name = ? ";
PreparedStatement pstmt = connection.prepareStatement( query );
pstmt.setString( 1, custname);
ResultSet results = pstmt.executeQuery( );
```
### LDAP Injection Prevention
- Always apply context‑appropriate escaping:
- DN escaping for `\ # + < > , ; " =` and leading/trailing spaces
- Filter escaping for `* ( ) \ NUL`
- Validate inputs with allow‑lists before constructing queries; use libraries that provide DN/filter encoders.
- Use least‑privilege LDAP connections with bind authentication; avoid anonymous binds for application queries.
### OS Command Injection Defense
- Prefer built‑in APIs instead of shelling out (e.g., library calls over `exec`).
- If unavoidable, use structured execution that separates command and arguments (e.g., ProcessBuilder). Do not invoke shells.
- Strictly allow‑list commands and validate arguments with allow‑list regex; exclude metacharacters (& | ; $ > < ` \ ! ' " ( ) and whitespace as needed).
- Use `--` to delimit arguments where supported to prevent option injection.
Example (Java ProcessBuilder):
```java
ProcessBuilder pb = new ProcessBuilder("TrustedCmd", "Arg1", "Arg2");
Map<String,String> env = pb.environment();
pb.directory(new File("TrustedDir"));
Process p = pb.start();
```
### Query Parameterization Guidance
- Use the platform’s parameterization features (JDBC PreparedStatement, .NET SqlCommand, Ruby ActiveRecord bind params, PHP PDO, SQLx bind, etc.).
- For stored procedures, ensure parameters are bound; never build dynamic SQL via string concatenation inside procedures.
### Prototype Pollution (JavaScript)
- Developers should use `new Set()` or `new Map()` instead of using object literals
- When objects are required, create with `Object.create(null)` or `{ __proto__: null }` to avoid inherited prototypes.
- Freeze or seal objects that should be immutable; consider Node `--disable-proto=delete` as defense‑in‑depth.
- Avoid unsafe deep merge utilities; validate keys against allow‑lists and block `__proto__`, `constructor`, `prototype`.
### Caching and Transport
- Apply `Cache-Control: no-store` on responses containing sensitive data; enforce HTTPS across data flows.
### Implementation Checklist
- Central validators: types, ranges, lengths, enums; canonicalization before checks.
- 100% parameterization coverage for SQL; dynamic identifiers via allow‑lists only.
- LDAP DN/filter escaping in use; inputs validated prior to query.
- No shell invocation for untrusted input; if unavoidable, structured exec + allow‑list + regex validation.
- JS object graph hardened: safe constructors, blocked prototype paths, safe merge utilities.
- File uploads validated by content, size, and extension; stored outside web root and scanned.
### Test Plan
- Static checks for string concatenation in queries/commands and dangerous DOM/merge sinks.
- Fuzzing for SQL/LDAP/OS injection vectors; unit tests for validator edge cases.
- Negative tests exercising blocked prototype keys and deep merge behavior.
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 3,978 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 repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/codeguard-0-additional-cryptography.mdcCursor rule
- .cursor/rules/codeguard-0-api-web-services.mdcCursor rule
- .cursor/rules/codeguard-0-authentication-mfa.mdcCursor rule
- .cursor/rules/codeguard-0-authorization-access-control.mdcCursor rule
- .cursor/rules/codeguard-0-client-side-web-security.mdcCursor rule
- .cursor/rules/codeguard-0-cloud-orchestration-kubernetes.mdcCursor rule
- .cursor/rules/codeguard-0-data-storage.mdcCursor rule
- .cursor/rules/codeguard-0-devops-ci-cd-containers.mdcCursor rule
- .cursor/rules/codeguard-0-file-handling-and-uploads.mdcCursor rule
- .cursor/rules/codeguard-0-framework-and-languages.mdcCursor rule
- .cursor/rules/codeguard-0-iac-security.mdcCursor rule
- .cursor/rules/codeguard-0-logging.mdcCursor rule
- .cursor/rules/codeguard-0-mobile-apps.mdcCursor rule
- .cursor/rules/codeguard-0-privacy-data-protection.mdcCursor rule
- .cursor/rules/codeguard-0-safe-c-functions.mdcCursor rule
- .cursor/rules/codeguard-0-session-management-and-cookies.mdcCursor rule
- .cursor/rules/codeguard-0-supply-chain-security.mdcCursor rule
- .cursor/rules/codeguard-0-xml-and-serialization.mdcCursor rule
- .cursor/rules/codeguard-1-crypto-algorithms.mdcCursor rule
- .cursor/rules/codeguard-1-digital-certificates.mdcCursor rule
- .cursor/rules/codeguard-1-hardcoded-credentials.mdcCursor rule
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.

