input-validation
Skill47 starsChanged 4 months agoMITView on GitHub
Use when writing or reviewing code that processes user input — validates and sanitizes to prevent SQL injection, XSS, CSRF, and other injection attacks. NOT when the code path doesn't touch user-supplied data.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- Archive228/loopkittheir own version, first seen Jun 29, 2026
- JeremyMorgan/code-review-skillstheir own version, first seen Jun 3, 2026
- suhailkakar/the-skillstheir own version, first seen May 7, 2026
- YepAPI/skillstheir own version, first seen Apr 12, 2026
- hereshecodes/secureskillstheir own version, first seen Mar 4, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- Archive228/loopkit★ 756same name
- suhailkakar/the-skills★ 26same name
- JeremyMorgan/code-review-skills★ 15same name
- YepAPI/skills★ 8same name
- hereshecodes/secureskills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository111 other files it gives its agents.
- AGENTS.mdAGENTS.md
- COPILOT-INSTRUCTIONS.mdCopilot instructions
- .github/copilot-instructions.mdCopilot instructions
- ai-visibilitySkill
- content-strategySkill
- seoSkill
- actions-debuggingSkill
- agentic-engineeringSkill
- autopilot-patternsSkill
- background-agentSkill
- context-primeSkill
- copilot-memorySkill
- cross-session-memorySkill
- ecosystem-intakeSkill
- fleet-parallelSkill
- github-code-searchSkill
- github-codespaces-efficiencySkill
- github-issue-triageSkill
- github-pr-workflowSkill
- ide-switchingSkill
- knowledge-curatorSkill
- mcp-builderSkill
- mcp-ecosystemSkill
- multi-model-strategySkill
- plan-mode-masterySkill
- scope-guardSkill
- session-managementSkill
- stack-detectorSkill
- sub-agent-sandboxingSkill
- task-intake-routerSkill
- team-plannerSkill
- token-cost-optimizerSkill
- api-and-interface-designSkill
- code-reviewSkill
- context-engineeringSkill
- cpp-debuggingSkill
- deprecation-and-migrationSkill
- diagnoseSkill
- fix-build-errorsSkill
- fix-github-issueSkill
- implementSkill
- improve-codebase-architectureSkill
- nestjs-prismaSkill
- nextjs-prismaSkill
- performance-optimizationSkill
- pr-multi-perspective-reviewSkill
- prototypeSkill
- react-vitestSkill
- receiving-code-reviewSkill
- refactor-cleanSkill
- reviewSkill
- skill-creatorSkill
- source-driven-developmentSkill
- spec-driven-developmentSkill
- systematic-debuggingSkill
- tdd-workflowSkill
- zoom-outSkill
- add-to-changelogSkill
- api-documentationSkill
- architecture-decisionsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. 0 are common, 7 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
7
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 44
Treat permission and access boundaries as the first control and application-level input validation as the second, independent control.
- Distinctive: line 49
Use least-privilege roles and restricted credentials (for example, read-only database roles where appropriate)
- Distinctive: line 51
Prefer allowlists over denylists when validating identifiers, operations, or query shapes
- Distinctive: line 213
Keep credentials and roles least-privileged even when validation is strong
- Distinctive: line 214
Always validate type, length, format, and range
- Distinctive: line 215
Use parameterized queries for all database access, no exceptions
- Distinctive: line 217
Never trust client-side validation alone — always validate server-side
- Very specific: line 218
Use explore agent to trace how user input flows through the application
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Input Validation
When to Use
- Building or reviewing API endpoints that accept user input
- Working with database queries, HTML rendering, or form handling
- Auditing an existing application for injection vulnerabilities
- Adding validation middleware to a web framework
- Handling file uploads, URL parameters, or header values
Prerequisites
- Understanding of the application's input surfaces (APIs, forms, file uploads)
- Access to the codebase's request handlers and data layer
- A validation library available (zod, joi, express-validator, etc.)
Workflow
1. Map Input Surfaces
Identify everywhere user input enters the application:
# Find route handlers / API endpoints
grep -rn "app\.\(get\|post\|put\|delete\|patch\)\|router\." src/ --include="*.ts"
# Find request body/query/param access
grep -rn "req\.body\|req\.query\|req\.params\|request\.json" src/ --include="*.ts"
# Find file upload handlers
grep -rn "multer\|upload\|formidable\|busboy" src/ --include="*.ts"1-A. Layer boundary controls before validation
Treat permission and access boundaries as the first control and application-level input validation as the second, independent control. Neither is sufficient alone: restricted credentials reduce blast radius when validation fails, and validation still matters even when the backing system is locked down.
- Use least-privilege roles and restricted credentials (for example, read-only database roles where appropriate)
- Restrict execution to a single statement where feasible
- Prefer allowlists over denylists when validating identifiers, operations, or query shapes
- Apply statement timeouts and max-row-count caps to limit abuse
- Sanitize error messages so they never reveal credentials or connection details
2. SQL Injection Prevention
# Find raw SQL queries — these are high risk
grep -rn "query\s*(\|execute\s*(\|raw\s*(" src/ --include="*.ts" -A 2// ❌ VULNERABLE — string concatenation
const result = await db.query(`SELECT * FROM users WHERE id = '${userId}'`);
// ✅ SAFE — parameterized query
const result = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
// ✅ SAFE — ORM with built-in parameterization
const user = await User.findOne({ where: { id: userId } });3. XSS Prevention
# Find direct HTML rendering with user data
grep -rn "innerHTML\|dangerouslySetInnerHTML\|document\.write\|v-html" src/ --include="*.ts" --include="*.tsx" --include="*.vue"
# Find template rendering without escaping
grep -rn "res\.send\|res\.write" src/ --include="*.ts" -A 3// ❌ VULNERABLE — raw HTML insertion
element.innerHTML = userComment;
// ✅ SAFE — text content (auto-escaped)
element.textContent = userComment;
// ✅ SAFE — sanitize before rendering
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userComment);4. CSRF Prevention
# Check for CSRF middleware
grep -rn "csrf\|csurf\|csrfToken" src/ --include="*.ts"
# Find state-changing endpoints without protection
grep -rn "app\.post\|app\.put\|app\.delete" src/ --include="*.ts"// Add CSRF protection middleware
import csrf from 'csurf';
app.use(csrf({ cookie: true }));
// Include token in forms
app.get('/form', (req, res) => {
res.render('form', { csrfToken: req.csrfToken() });
});5. Schema Validation at the Boundary
Validate all input at the entry point using a schema library:
import { z } from 'zod';
const CreateUserSchema = z.object({
email: z.string().email().max(254),
name: z.string().min(1).max(100).trim(),
age: z.number().int().min(0).max(150),
});
app.post('/users', (req, res) => {
const result = CreateUserSchema.safeParse(req.body);
if (!result.success) {
return res.status(400).json({ errors: result.error.issues });
}
// result.data is now typed and validated
createUser(result.data);
});6. Additional Validation Patterns
// Path traversal prevention
import path from 'path';
function safePath(userInput: string): string {
const resolved = path.resolve('/allowed/base', userInput);
if (!resolved.startsWith('/allowed/base')) {
throw new Error('Path traversal detected');
}
return resolved;
}
// URL validation
function safeUrl(url: string): boolean {
try {
const parsed = new URL(url);
return ['http:', 'https:'].includes(parsed.protocol);
} catch { return false; }
}Examples
Audit Existing Endpoints
# Find unvalidated endpoints — routes without validation middleware
grep -rn "router\.\(post\|put\|patch\)" src/routes/ --include="*.ts" -A 5 | grep -v "validate\|schema\|zod\|joi"Add Validation to an Express Route
// middleware/validate.ts
import { ZodSchema } from 'zod';
export function validate(schema: ZodSchema) {
return (req, res, next) => {
const result = schema.safeParse(req.body);
if (!result.success) return res.status(400).json({ errors: result.error.issues });
req.body = result.data;
next();
};
}Common Rationalizations
| Rationalization | Reality |
| "Frontend already validated it" | HTTP requests can be sent directly without going through a browser. |
| "It's an internal API, we can trust it" | Internal services can be compromised too. Apply zero trust principles. |
| "TypeScript ensures type safety" | TypeScript types are compile-time only. Runtime input must be treated as unknown. |
| "We use Zod/joi/yup, so we're covered" | Validation libraries are only as good as the schema. A wrong schema is still wrong. |
Red Flags
- User input used directly in SQL queries
JSON.parse()results used without validation- User input included in file paths (path traversal risk)
parseInt()orparseFloat()results used withoutNaNchecks- Regex patterns vulnerable to ReDoS (
(a+)+,([a-zA-Z]+)*)
Verification
- Server-side validation present for all API endpoint inputs
- Parameterized queries or ORM used (no raw string interpolation)
- File uploads validated for type, size, and path
- Validation failures return 400 responses (no detailed internal error exposure)
- Input validation tests cover both valid and malicious input cases
Tips
- Validate at the boundary, trust internally — validate once where input enters your system
- Keep credentials and roles least-privileged even when validation is strong
- Always validate type, length, format, and range
- Use parameterized queries for all database access, no exceptions
- Set
Content-Security-Policyheaders to prevent XSS at the browser level - Never trust client-side validation alone — always validate server-side
- Use
exploreagent to trace how user input flows through the application
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.

