# Injection Attack

> Hiding commands in what a user types. The program then runs them.

**Field:** Software Development  
**Category:** Security  
**Also known as:** Injection Flaw, Code Injection

## Think of it like

Think of it like slipping a line into a recipe. The cook follows it as if it were part of the dish.

## Definition

An injection attack sneaks commands into data that a program trusts. The program builds a command by gluing user text into it. If that text holds commands of its own, the program runs them too. SQL injection does this to a database. Command injection does it to the system shell. The fix is to keep data and commands apart, so text is only ever text.

## Example

A search box passes Emma's text straight into a database query. An attacker types a piece of SQL instead of a word, and the database runs it.

## Why it matters

Injection can leak, change or wipe whole databases. It is number five on the 2025 OWASP Top 10.

## Common mistake

Trying to block bad words in the input. Attackers find new spellings, so keep data apart from commands instead.

## Three principles

- **Data becomes code.** Input gets run as a command.
- **Many targets.** Databases, shells, pages and more.
- **Keep them apart.** Send data apart from commands.

## Related terms

- [SQL Injection](https://learn.benibix.com/term/development/sql-injection)
- [Command Injection](https://learn.benibix.com/term/development/command-injection)
- [Parameterized Query](https://learn.benibix.com/term/development/parameterized-query)
- [Input Validation](https://learn.benibix.com/term/development/input-validation)
- [Cross-Site Scripting (XSS)](https://learn.benibix.com/term/development/cross-site-scripting)
- [Prompt Injection](https://learn.benibix.com/term/ai/prompt-injection)

![Three rows. In the first, SQL glued in, a query ends with the user's text x' OR '1'='1, and the result is that every user comes back. In the second, SQL kept apart, the query ends with a question mark and the same text is sent apart as data, so nothing matches. In the third, shell glued in, the line ping -c 1 example.com is followed by ; cat /etc/passwd, which runs a second command.](https://learn.benibix.com/diagrams/dev2-injection.svg)

---

Source: https://learn.benibix.com/term/development/injection-attack
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
