Skip to main content
Legia

Cybersecurity

What is SQL Injection?

Also called SQLi, SQL code injection.

Short definition

SQL injection is an attack that slips database commands into application inputs, such as forms or page addresses, so the attacker can read, change, or delete data that should be off limits.

How it works

A vulnerable application builds database commands by directly concatenating text from user input. If someone types special characters into a search or login field, that text is read as part of the command instead of as data. As a result, an attacker can bypass the login page, pull the entire contents of the customer table, or, in certain configurations, run commands on the server.

Example in a company

An old internal application has a report page that takes a branch number from the page address. By replacing that number with a fragment of SQL, a tester can display data for every branch and a list of user accounts with their password hashes. Flaws like this often survive in applications built years ago and rarely touched. Because the application's interface works normally, no user suspects anything until the data shows up somewhere else.

How to prevent it

Use parameterized queries or prepared statements, so user input is always treated as data. Modern frameworks provide this by default, but hand-written queries still need to be checked. The database account the application uses gets the fewest privileges possible. Input validation and a WAF add layers, but they do not replace fixing the code. Regular security testing helps find leftover old queries that were missed.

Related Legia service Penetration Testing Manual testing that proves how far a vulnerability can be exploited, with the evidence to back it up.