second-order-injection-anti-pattern

Audit data flows to detect second-order injection vulnerabilities in applications.

8|1|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/igbuend/grimbard --skill second-order-injection-anti-pattern
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: second-order-injection-anti-pattern
Source: https://github.com/igbuend/grimbard/tree/main/skills/second-order-injection-anti-pattern
Command: npx skills add https://github.com/igbuend/grimbard --skill second-order-injection-anti-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the critical security vulnerability of second-order injection, where malicious data is stored safely but executed later, making it hard to detect.

Core Features & Use Cases

  • Detects Unsafe Data Reuse: Identifies when data retrieved from databases or storage is used in subsequent queries or commands without re-sanitization.
  • Prevents Hidden Payloads: Helps secure applications against attacks where the injection and execution points are separated in time and code.
  • Use Case: Reviewing code that logs user actions. If user data is stored in a log table and later used to construct a report query, this skill helps ensure that data is re-validated to prevent an injection that occurred during the initial logging.

Quick Start

Review the attached Python code for potential second-order injection vulnerabilities.

Frequently Asked Questions about second-order-injection-anti-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is a second-order injection attack and how does it work?▼

A second-order injection attack occurs when malicious data is stored safely in a database but executed later in a dynamic query without re-sanitization. This separates the injection point from execution, making the payload difficult to detect during initial storage.

How do I prevent second-order SQL injection in database-retrieved data?▼

Prevent second-order SQL injection by auditing data flows and treating all database-retrieved data as potentially tainted. Always use parameterized queries for dynamic query construction instead of directly reusing stored data like user action logs.

Do I need to sanitize data extracted from my own database before using it in a query?▼

Yes, you must sanitize data extracted from your own database before using it in a query. Internal storage is not inherently safe; treating all database-retrieved data as potentially tainted prevents hidden payloads from executing during subsequent dynamic query construction.

What's the best way to audit code for unsafe data reuse in dynamic queries?▼

The best way to audit unsafe data reuse is tracing data flows from storage retrieval to dynamic query construction. Identify where database or log data is reused without re-sanitization, ensuring parameterized queries are enforced to prevent hidden payload execution.

Why does parameterized queries fail to stop second-order injection vulnerabilities?▼

Parameterized queries fail to stop second-order injection when developers safely store input but later retrieve and concatenate it into a new dynamic query without parameters. The initial safe storage creates a false sense of security against delayed execution attacks.