brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
ai-code-securitySecurity review of AI-generated code, and secure practices for working with coding assistants. USE WHEN: reviewing AI-generated code (GitHub Copilot, ChatGPT, Claude, etc.) for security vulnerabilities, or establishing secure AI coding practices DO NOT USE FOR: AI/ML model security, prompt injection attacks on AI systems, or general code review
Independent GitHub snapshot · Automated classification · Original documentation governs
name: ai-code-security description: | Security review of AI-generated code, and secure practices for working with coding assistants.
USE WHEN: reviewing AI-generated code (GitHub Copilot, ChatGPT, Claude, etc.) for security vulnerabilities, or establishing secure AI coding practices
USE WHEN: Reviewing AI-generated code (GitHub Copilot, ChatGPT, Claude, etc.) for security vulnerabilities, or establishing secure AI coding practices. DO NOT USE FOR: AI/ML model security, prompt injection attacks on AI systems, or general code review.
// AI often generates this pattern
const API_KEY = 'sk-abc123...'; // Hardcoded!
const client = new ApiClient({ apiKey: API_KEY });
// Secure alternative
const client = new ApiClient({
apiKey: process.env.API_KEY ?? throwError('API_KEY required')
});
// AI frequently suggests string interpolation
const query = `SELECT * FROM users WHERE id = ${userId}`;
// Secure alternative
const [rows] = await db.query('SELECT * FROM users WHERE id = ?', [userId]);
// AI often suggests deprecated algorithms
const hash = crypto.createHash('md5').update(password).digest('hex');
// Secure alternative
import argon2 from 'argon2';
const hash = await argon2.hash(password, { type: argon2.argon2id });
// AI-generated code often lacks validation
app.post('/users', (req, res) => {
const user = createUser(req.body); // No validation!
});
// Secure alternative
import { z } from 'zod';
const UserSchema = z.object({
email: z.string().email(),
name: z.string().min(1).max(100),
});
app.post('/users', (req, res) => {
const validated = UserSchema.parse(req.body);
const user = createUser(validated);
});
// AI often suggests Math.random()
const token = Math.random().toString(36); // Predictable!
// Secure alternative
import { randomBytes } from 'crypto';
const token = randomBytes(32).toString('hex');
// AI often misses path validation
const filePath = path.join(__dirname, 'uploads', req.params.filename);
fs.readFile(filePath); // ../../etc/passwd possible!
// Secure alternative
const safeName = path.basename(req.params.filename); // Strip directory components
if (safeName !== req.params.filename || safeName.includes('..')) {
throw new BadRequestError('Invalid filename');
}
const filePath = path.join(__dirname, 'uploads', safeName);
// AI may suggest non-existent packages
import { validate } from 'json-validator-pro'; // May not exist!
// Before using ANY AI-suggested package:
// 1. Verify it exists: npm view json-validator-pro
// 2. Check download stats: npmjs.com/package/json-validator-pro
// 3. Check for typosquatting: lodash vs lodesh
| Check | Description | Tool |
|---|---|---|
| Secrets scan | No hardcoded credentials | gitleaks, trufflehog |
| Dependency exists | All imports exist and are popular | npm view, pypi search |
| OWASP Top 10 | No injection, XSS, CSRF, etc. | semgrep, eslint-plugin-security |
| Crypto check | Modern algorithms only | custom rules |
| Input validation | All external inputs validated | zod, joi, manual review |
# Before adding AI-suggested packages:
# 1. Check if package exists
npm view <package-name>
# 2. Check popularity (downloads should be > 1000/week for production use)
npm info <package-name> downloads
# 3. Check for known vulnerabilities
npm audit <package-name>
# 4. Check repository activity
gh repo view <owner>/<repo> --web
# 5. Look for typosquatting variants
npm search <package-name>
When using AI assistants, include security context:
Generate a user authentication endpoint for Express.js that:
- Uses parameterized queries (not string interpolation)
- Validates all inputs with Zod
- Uses Argon2id for password hashing
- Implements rate limiting
- Returns generic error messages (no information disclosure)
- Uses environment variables for secrets
Review this code for security issues:
- Check for OWASP Top 10 vulnerabilities
- Verify all inputs are validated
- Confirm no hardcoded secrets
- Check for secure random generation
- Verify proper error handling
# Run automated security checks on AI-generated code
npm run lint:security
npx semgrep --config=p/security-audit <file>
npx gitleaks detect --source .
{
"plugins": ["security", "no-secrets"],
"extends": ["plugin:security/recommended"],
"rules": {
"security/detect-object-injection": "error",
"security/detect-non-literal-regexp": "error",
"security/detect-unsafe-regex": "error",
"security/detect-buffer-noassert": "error",
"security/detect-child-process": "warn",
"security/detect-disable-mustache-escape": "error",
"security/detect-eval-with-expression": "error",
"security/detect-no-csrf-before-method-override": "error",
"security/detect-non-literal-fs-filename": "warn",
"security/detect-non-literal-require": "warn",
"security/detect-possible-timing-attacks": "error",
"security/detect-pseudoRandomBytes": "error",
"no-secrets/no-secrets": "error"
}
}
# .semgrep/ai-code-rules.yml
rules:
- id: ai-hardcoded-secret
patterns:
- pattern-either:
- pattern: $KEY = "sk-..."
- pattern: $KEY = "api_..."
- pattern: $KEY = "ghp_..."
message: "Hardcoded secret detected (common in AI-generated code)"
severity: ERROR
- id: ai-weak-crypto
patterns:
- pattern-either:
- pattern: crypto.createHash("md5")
- pattern: crypto.createHash("sha1")
message: "Weak hash algorithm (AI may suggest outdated crypto)"
severity: ERROR
- id: ai-sql-injection
patterns:
- pattern: $DB.query(`... ${$VAR} ...`)
message: "String interpolation in SQL (common AI pattern)"
severity: ERROR
eval(), new Function() suggestionsinnerHTML without sanitizationhttpOnly on cookiesMath.random() for security tokenspickle.loads() on untrusted datasubprocess.call(shell=True)yaml.load() without SafeLoaderRuntime.exec() with string concatObjectInputStream deserializationjava.util.Randomtext/templatedefer rows.Close()name: AI Code Security Check
on: [pull_request]
jobs:
ai-security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect AI-generated code patterns
run: |
# Check for common AI code patterns
npx semgrep --config=.semgrep/ai-code-rules.yml .
- name: Verify all dependencies exist
run: |
# Extract all imports and verify they exist
npm ls --all 2>&1 | grep -E "missing|UNMET" && exit 1 || true
- name: Security scan
run: npm audit --audit-level=high
- name: Secrets scan
uses: trufflesecurity/trufflehog@main
with:
path: ./
extra_args: --only-verified
When reviewing AI-generated PRs, prioritize: