pre-code-security-check
Skill2 starsChanged 8 months agoMITView on GitHub
Execute BEFORE generating code to identify security requirements based on AI error patterns. Automatically consults anti-patterns reference.
In this repository34 other files it gives its agents.
- global/CLAUDE.mdCLAUDE.md
- templates/CLAUDE.mdCLAUDE.md
- accessibility-reviewSkill
- api-designSkill
- audit-runnerSkill
- auto-fixSkill
- brainstormSkill
- compliance-checkSkill
- continuous-testing-guardianSkill
- contract-lookupSkill
- explainSkill
- idea-validatorSkill
- load-test-auditSkill
- monthly-reviewSkill
- new-featureSkill
- nextjs-reviewSkill
- perfection-auditSkill
- performance-deep-auditSkill
- post-code-security-auditSkill
- pre-deploymentSkill
- project-setupSkill
- pro-samuelSkill
- quick-auditSkill
- risk-scoreSkill
- roadmap-builderSkill
- secret-scannerSkill
- seo-auditSkill
- supabase-reviewSkill
- token-economySkill
- typescript-reviewSkill
- ux-cognitive-load-checkSkill
- ux-heuristic-auditSkill
- ux-progressive-disclosureSkill
- welcomeSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
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 61
Create a spec BEFORE writing code:
- Distinctive: line 101
Before generating code, show:
- Distinctive: line 155
If ANY blocker detected, STOP and warn user:
- Distinctive: line 174
No input validation on API routes
- Very specific: line 204
Override: Use --skip-security-check flag if absolutely needed (not recommended)
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill 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
🔒 Pre-Code Security Check
Trigger: Automatically BEFORE generating:
- API routes
- Database functions
- Authentication/Authorization logic
- File operations
- Any code handling user input or sensitive data
Reference: .claude/resources/ai-security-antipatterns.md
🎯 EXECUTION FLOW
Step 1: Classify Code Type
Determine which category applies:
□ API Route (Next.js /app/api/*)
□ Database Function (SQL/PL/pgSQL)
□ Authentication Logic
□ File Upload/Download
□ Payment/Banking
□ Admin Panel
□ Messaging/Chat
□ Search/QueryStep 2: Identify Security Requirements
Based on classification, check anti-patterns resource for:
- Required validations:
- Input validation (Zod schema)
- File type/size limits
- Query param min/max
- Path sanitization
- Required protections:
- Authentication level (public, authenticated, admin)
- Authorization checks (RLS, role-based)
- Rate limiting tier
- Encryption needs
- Required logging:
- Audit log entry
- IP + User-Agent capture
- Log sanitization
Step 3: Generate Security Specification
Create a spec BEFORE writing code:
## Security Specification for [Feature Name]
### Input Validation
- Field X: Zod schema with min/max
- Field Y: Enum whitelist
- Field Z: Regex pattern
### Authentication
- Level: authenticated users only
- Re-verification: YES (password required)
- Session timeout: 30min
### Authorization
- RLS: user_id = auth.uid()
- Role check: admin_only
### Rate Limiting
- Tier: 5 requests/minute (sensitive)
### Encryption
- IBAN: Supabase Vault (AES-256-GCM)
- Password: bcrypt cost 10
### Logging
- Action: BANK_INFO_UPDATED
- Fields: IP, UA, timestamp
- Sanitization: YES (remove newlines)
### BLOCKER Checks
- No hardcoded secrets: ✓
- No always-true auth: ✓
- No SQL concatenation: ✓
- No plaintext sensitive data: ✓Step 4: Present to User
Before generating code, show:
★ Security Requirements Identified ─────────────
Based on anti-patterns research, this feature needs:
• Input validation (Zod) for [fields]
• Password re-verification (sensitive data)
• Rate limiting: [tier]
• Encryption: [what needs encrypting]
Proceeding with secure implementation...
───────────────────────────────────────────────📋 QUICK REFERENCE CHECKLIST
For API Routes
□ Zod validation schema defined?
□ Authentication required?
□ RLS authorization checked?
□ Rate limiting configured?
□ Errors generic (not verbose)?
□ Audit logging present?
□ Input sanitized (logs, paths)?For Database Functions
□ bcrypt used for passwords (NOT SHA256)?
□ Parameters used (NOT concatenation)?
□ SECURITY DEFINER only if needed?
□ RLS policies defined?
□ Sensitive columns encrypted?
□ Audit triggers configured?For File Operations
□ File type whitelist?
□ Size limit enforced?
□ Filename sanitized (basename)?
□ Path traversal blocked (no ..)?
□ Virus scanning (if prod)?
□ Storage RLS configured?🚨 AUTO-STOP CONDITIONS
If ANY blocker detected, STOP and warn user:
❌ BLOCKER DETECTED: [Pattern name]
Found: [Code snippet]
Risk: [Security impact]
Source: Anti-pattern #X (AI failure rate: Y%)
Recommendation: [Fix]
Proceed? (y/n)Blocker patterns (from anti-patterns resource):
- Hardcoded secrets
- Always-true/false auth
- SQL string concatenation
- Plaintext sensitive data
- No input validation on API routes
- SHA256/MD5 for passwords
- Unvalidated redirects
- Debug endpoints in production
📊 TRACKING
Log each security check execution:
{
"timestamp": "2026-01-18T12:00:00Z",
"feature": "API route for bank info update",
"classification": "Payment/Banking",
"requirements_identified": 8,
"blockers_found": 0,
"estimated_security_coverage": "90%"
}Track over time to measure improvement:
- % of code generated with pre-check
- % of blockers caught before generation
- Reduction in post-audit vulnerabilities
Usage: This skill auto-loads when code generation starts
Override: Use --skip-security-check flag if absolutely needed (not recommended)
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.

