Skip to content
LiveNext 10:12:39

Definition

What is SQL injection?

SQL injection is SQL injection is an attack where someone types database commands into a form or web address, and a poorly built app runs them as if its own developers had written them.

What it is

Most web apps keep their data in a database, and they talk to it in a language called SQL. When you search a site for "red shoes," the app builds a SQL request that asks the database for matching rows.

SQL injection happens when the app builds that request by gluing your text straight into the command. If you type something that looks like database instructions instead of a shoe name, the database cannot tell the difference. It runs your words as part of the command.

A simple picture

Imagine a waiter who writes down your order and reads it aloud to the kitchen exactly as you said it. You say, "A burger, and also give me the safe's combination." A careful waiter treats that as one strange order. A careless one repeats the whole sentence, and the kitchen obeys.

SQL injection is the careless waiter. The fix is to keep the instruction and the customer's words separate.

What attackers can do

Depending on how the app is built, an attacker may be able to:

  • Read data they should never see, such as customer records or password hashes.
  • Skip a login check by making the condition always true.
  • Change or delete rows.
  • In some setups, reach the server itself and escalate from there, a path related to privilege escalation and remote code execution.

How developers prevent it

The standard defense is the parameterized query, sometimes called a prepared statement. The developer writes the command with blank slots, then hands the user's input to the database separately. The database treats that input only as data, never as instructions.

Other layers help but do not replace it: checking input, giving the app's database account only the permissions it needs (least privilege), and putting a web application firewall in front of the site.

Why it matters for AI

SQL injection is decades old, and it is still on security teams' lists. Automated tools, including AI-driven ones used in penetration testing, can probe thousands of forms quickly for exactly this kind of flaw. A mistake that once waited weeks for a human to find it can be found in minutes.

It also has a cousin in the AI world. Prompt injection works on the same basic mistake: a system mixes trusted instructions with untrusted text, and cannot tell which is which. If you use or build software that touches a database, ask one question: does user input ever get pasted into a command?

How to check your own apps

If you build with a framework or an object-relational mapper, you are probably protected by default, until someone writes a raw query by hand. Search your code for places where a query is built by joining strings together. Those are the spots to fix first, and a short list of them is a good week's work.

Questions people ask

What is SQL injection in simple terms?

It is an attack where someone enters database commands into a form or web address, and a poorly built app runs them as part of its own query.

How do you prevent SQL injection?

Use parameterized queries so user input is always treated as data, limit the database account's permissions, and validate input as an extra layer.

SQL injection in the news