ai-code-security
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "ai-code-security":https://skillpi.com/zh/skills/deepskill-29ec3a775255d89acd38970862b080c37c425e9a6459381506c16f8db6dd47dd。安装前核对上游来源和版本:https://github.com/omer-metin/skills-for-antigravity。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
聚焦 AI 生成代码与大型语言模型应用中的安全问题,涵盖 LLM OWASP Top 10、安全编码模式与 AI 特定威胁模型。适用于涉及 AI 代码安全、LLM 漏洞、AI 生成代码审查、OWASP LLM 与安全开发等场景。
介绍来源: third_party · omer-metin · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
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
当前收录版本
0.0.1
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 AI 生成代码安全审查的完整解决方案,覆盖 45% 漏洞率的实际痛点
- 包含 OWASP LLM Top 10、安全编码模式和 CI/CD 集成等实用内容
亮点
- 触发词覆盖全面且边界清晰,明确区分适用/不适用场景
- description 位置正确且内容完整
待提升项
-
缺少 When to Use 独立章节 原报告严重程度:轻微
文档开头已有 USE WHEN 说明,但未单独设立 When to Use 章节
改进建议:建议在正文开头添加独立的 When to Use 章节以增强可读性
亮点
- 结构完整,从风险分析到实践方案形成闭环
- 提供丰富的代码示例、配置文件和自动化脚本
亮点
- 工具链选择合理(semgrep、gitleaks、eslint-security)
- 提供完整的 CI/CD 集成方案和团队使用规范
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
读取本地文件
限定到你选择的文件或项目目录;避免读取无关的个人资料、密钥和配置文件。
主文档提及 · 第 98 行 -
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 185, 186, 286 行 -
调用命令或脚本
先读脚本与参数,使用普通权限和限定目录;安装或执行前由使用工具再次确认。
主文档提及 · 第 254 行 -
账号、密钥或授权
使用专用、最小权限账号,不把密钥粘贴到公开内容或命令日志;核对接收数据的服务与租户。
主文档提及 · 第 21, 27, 31, 32, 36 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。