AI Security Rules
Deterministic Pattern Library
Every rule documented with examples.
Complete library of deterministic security rules with code examples, severity levels, and remediation guidance. No AI guessing—just facts.
Showing 15 of 15 core AI security rules. These are the deterministic patterns used by the scanner engine.
Rule engine version: v2026.1.0-ea (Early Access). Rules are continuously updated.
User Input Reaches System Prompt
Prompt Injection
Detects when user-controlled input flows into system or developer prompts without sanitization. This is the primary vector for prompt injection attacks.
Code Example:
// Detected Pattern
const systemPrompt = `You are a helpful assistant. User context: ${userInput}`;
await openai.chat.completions.create({
messages: [{ role: 'system', content: systemPrompt }]
});
// CRITICAL: User input in system promptRemediation:
Never interpolate user input into system prompts. Use separate user message roles. Implement input validation and content filtering before AI processing.
Model Output Triggers Privileged Action
Tool Abuse
Detects when AI model output directly triggers privileged operations (database writes, API calls, file operations) without human approval or validation.
Code Example:
// Detected Pattern
const action = await model.generateAction(userRequest);
await executePrivilegedAction(action); // No validation!
// CRITICAL: AI output directly executesRemediation:
Implement human-in-the-loop for privileged actions. Add output validation before execution. Use allowlists for permitted actions.
Tool Arguments Without Validation
Tool Abuse
AI function calling passes arguments to tools without schema validation. Attackers can manipulate AI to pass malicious arguments.
Code Example:
// Detected Pattern
const toolCall = response.tool_calls[0];
await tools[toolCall.name](toolCall.arguments);
// CRITICAL: No argument validationRemediation:
Validate all tool arguments against strict schemas (Zod, JSON Schema). Implement argument sanitization. Use typed function signatures.
RAG Poisoning / Indirect Injection
Prompt Injection
Retrieved documents from RAG systems flow to AI context without content boundary markers. Attackers can poison documents with hidden instructions.
Code Example:
// Detected Pattern
const docs = await vectorStore.similaritySearch(query);
const context = docs.map(d => d.content).join('\n');
// HIGH: No boundary markers on retrieved contentRemediation:
Add clear boundary markers around retrieved content. Implement content filtering on RAG results. Use separate context windows for trusted vs untrusted content.
Missing Authentication on AI Endpoint
Access Control
AI API endpoints lack authentication middleware. Unauthenticated users can access AI features, leading to abuse and cost amplification.
Code Example:
// Detected Pattern
export async function POST(req: Request) {
const { prompt } = await req.json();
return await callAI(prompt);
// HIGH: No auth check before AI call
}Remediation:
Add authentication middleware to all AI endpoints. Verify session/token before processing. Implement rate limiting per user.
Missing Tenant Scoping on AI Data
Access Control
AI-accessible data queries lack tenant isolation. One user's AI queries could access another tenant's data.
Code Example:
// Detected Pattern
const data = await db.query(aiGeneratedQuery);
// HIGH: No tenant filter on AI queryRemediation:
Always include tenant ID in data queries. Use row-level security. Validate AI-generated queries include proper scoping.
Agent Loops Without Guardrails
Stability
Autonomous AI agent execution lacks termination conditions, bounded loops, or human-in-the-loop controls. Can lead to runaway execution.
Code Example:
// Detected Pattern
while (!task.complete) {
await agent.executeStep();
// HIGH: No max iterations or timeout
}Remediation:
Implement max iteration limits. Add timeout controls. Require human approval for long-running agents. Log all agent actions.
Secrets Flow to AI or Logs
Data Leakage
API keys, passwords, or tokens flow into AI prompts or are logged. Secrets could be leaked through AI responses or log files.
Code Example:
// Detected Pattern
const prompt = `Connect to DB with password: ${dbPassword}`;
console.log('Processing:', prompt);
// HIGH: Secret in prompt and logsRemediation:
Never include secrets in AI prompts. Implement secret detection in logging. Use secret managers with runtime injection.
LLM-Chosen URL / SSRF
Data Leakage
AI model output is used to construct URLs for external requests. Attackers can manipulate AI to access internal services (SSRF).
Code Example:
// Detected Pattern
const url = await model.generateUrl(userRequest);
const response = await fetch(url);
// HIGH: AI-controlled URL fetchRemediation:
Implement URL allowlists. Validate AI-generated URLs against permitted domains. Block internal network access from AI-triggered requests.
Non-Deterministic AI on Privileged Path
Stability
AI operations on security-sensitive paths use high temperature or variable configurations. Non-deterministic outputs make compliance validation difficult.
Code Example:
// Detected Pattern
await openai.chat.completions.create({
model: 'gpt-4',
temperature: 0.9, // HIGH temperature
messages: securityDecisionPrompt
});Remediation:
Use temperature=0 for security-critical AI operations. Set fixed seeds for reproducibility. Document AI configuration for audit.
Privileged AI Operation Lacks Authorization
Access Control
AI operations that perform privileged actions do not verify user has required permissions. Attackers can escalate privileges through AI.
Code Example:
// Detected Pattern
async function aiAdminAction(userId, action) {
await executeAdminAction(action);
// HIGH: No permission check
}Remediation:
Implement RBAC checks before AI operations. Verify user permissions match required action level. Audit all privileged AI actions.
AI Output Flows to Dangerous Sink
Stability
AI-generated content flows to code execution, database writes, or external APIs without output validation. Enables XSS, SQL injection, command injection.
Code Example:
// Detected Pattern
const html = await model.generateHTML(userRequest);
element.innerHTML = html;
// HIGH: AI output to innerHTMLRemediation:
Validate and sanitize all AI output before use. Use schema validation for structured output. Implement content security policies.
AI Endpoint Lacks Rate Limiting
Stability
AI endpoint does not have rate limiting protection. Attackers can cause resource exhaustion or denial of wallet attacks.
Code Example:
// Detected Pattern
export async function POST(req: Request) {
// No rate limit check
return await expensiveAICall(req);
}Remediation:
Implement rate limiting per user/IP. Add request quotas. Monitor for abuse patterns. Implement circuit breakers.
No Context Window Overflow Protection
Stability
User input is not truncated or validated for length before AI context. Attackers can exhaust context window, truncating important instructions.
Code Example:
// Detected Pattern
const messages = [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userInput } // Unbounded!
];Remediation:
Validate input length before AI context. Implement token counting. Truncate user input to safe limits. Reserve space for system prompts.
User-Controlled Model Selection
Stability
User input can influence which AI model is used. Attackers can switch to cheaper/weaker models without safety filters.
Code Example:
// Detected Pattern
const model = req.query.model || 'gpt-4';
await openai.chat.completions.create({ model });
// LOW: User controls model selectionRemediation:
Use fixed model selection or strict allowlist. Do not expose model choice to users. Document model selection rationale.