ai-code-security
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "ai-code-security" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-29ec3a775255d89acd38970862b080c37c425e9a6459381506c16f8db6dd47dd. Verify the upstream source and version against https://github.com/omer-metin/skills-for-antigravity before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Focuses on security issues in AI-generated code and large language model applications, covering LLM OWASP Top 10, secure coding patterns and AI-specific threat models. Suitable for scenarios involving AI code security, LLM vulnerabilities, AI-generated code review, OWASP LLM and secure AI development.
Introduction source: third_party · omer-metin · 0.0.1 Reference
SkillPi interpretation
- Tasks
- 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.
- Testing
- Not tested
Browse files
Frontmatter
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
DO NOT USE FOR: AI/ML model security, prompt injection attacks on AI systems, or general code review
allowed-tools: Read, Grep, Glob, BashAI-Generated Code Security Skill
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 Code Security Risks (2024-2025 Research)
Key Statistics
- 45% of AI-generated code contains security vulnerabilities (Stanford/NYU study)
- 40% of Copilot suggestions include hardcoded credentials or insecure patterns
- Package hallucinations create supply chain risks (non-existent packages that could be typosquatted)
- Outdated patterns: AI trained on pre-2023 data may suggest deprecated/vulnerable APIs
Common AI-Generated Vulnerabilities
1. Hardcoded Credentials
// 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')
});
2. SQL Injection
// 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]);
3. Weak Cryptography
// 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 });
4. Missing Input Validation
// 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);
});
5. Insecure Randomness
// AI often suggests Math.random()
const token = Math.random().toString(36); // Predictable!
// Secure alternative
import { randomBytes } from 'crypto';
const token = randomBytes(32).toString('hex');
6. Path Traversal
// 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);
7. Package Hallucinations
// 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
AI Code Review Checklist
Pre-Integration Review
| 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 |
Package Verification Process
# 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>
Secure AI Coding Workflow
1. Context Priming
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
2. Security-First Prompts
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
3. Post-Generation Review
# Run automated security checks on AI-generated code
npm run lint:security
npx semgrep --config=p/security-audit <file>
npx gitleaks detect --source .
Static Analysis Configuration
ESLint Security Rules
{
"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 Rules for AI Code
# .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
Language-Specific AI Code Risks
TypeScript/JavaScript
eval(),new Function()suggestionsinnerHTMLwithout sanitization- Missing
httpOnlyon cookies Math.random()for security tokens
Python
pickle.loads()on untrusted datasubprocess.call(shell=True)yaml.load()without SafeLoader- f-strings in SQL queries
Java
Runtime.exec()with string concatObjectInputStreamdeserialization- Regex DoS patterns
- Predictable
java.util.Random
Go
- Template injection with
text/template - Missing
defer rows.Close() - Unchecked errors
CI/CD Integration
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
Team Guidelines
AI Code Usage Policy
- Never commit without review: All AI-generated code must be reviewed by a human
- Run security scans: Mandatory before merging any AI-suggested code
- Verify packages: Check all suggested dependencies exist and are legitimate
- Update AI context: Include security requirements in prompts
- Track AI usage: Document which code was AI-generated for audit purposes
Code Review Focus Areas
When reviewing AI-generated PRs, prioritize:
- Authentication/Authorization logic
- Input validation at API boundaries
- Database queries for injection
- File operations for path traversal
- Cryptographic operations for weak algorithms
- Third-party packages for existence and security
- Error handling for information disclosure
Current listing version
0.0.1
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 AI 生成代码安全审查的完整解决方案,覆盖 45% 漏洞率的实际痛点
- 包含 OWASP LLM Top 10、安全编码模式和 CI/CD 集成等实用内容
Highlights
- 触发词覆盖全面且边界清晰,明确区分适用/不适用场景
- description 位置正确且内容完整
Areas to improve
-
缺少 When to Use 独立章节 Reported severity: Minor
文档开头已有 USE WHEN 说明,但未单独设立 When to Use 章节
Recommendation: 建议在正文开头添加独立的 When to Use 章节以增强可读性
Highlights
- 结构完整,从风险分析到实践方案形成闭环
- 提供丰富的代码示例、配置文件和自动化脚本
Highlights
- 工具链选择合理(semgrep、gitleaks、eslint-security)
- 提供完整的 CI/CD 集成方案和团队使用规范
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Read local files
Limit access to selected files or the project directory. Avoid unrelated private records, secrets and configuration files.
Mentioned in main document · lines 98 -
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 185, 186, 286 -
Invoke commands or scripts
Read the script and arguments first. Use ordinary privileges and a scoped directory; confirm installation or execution in your host tool.
Mentioned in main document · lines 254 -
Accounts, secrets or authorization
Use a dedicated least-privilege account. Keep secrets out of public content and command logs; verify the receiving service and tenant.
Mentioned in main document · lines 21, 27, 31, 32, 36
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.