Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
SQL injection is a web application vulnerability in which untrusted input is inserted into a database query, letting attackers read, change, or delete data they should never reach.

What Is SQL Injection?
SQL injection (SQLi) is a vulnerability that occurs when an application builds a database query by combining fixed SQL code with input supplied by a user, without handling that input safely. An attacker can then craft input that changes the meaning of the query, allowing them to read data they should not see, modify or delete records, bypass logins, and in some cases take control of the database server.
It is one of the oldest web vulnerabilities, first described publicly in the late 1990s, and it is still found regularly in penetration tests. Injection remains a category in the OWASP Top 10, the most widely used list of web application risks.
Consider a login form that builds its query like this:
SELECT * FROM users WHERE username = 'input' AND password = 'input'
If the application inserts the username directly, an attacker can enter a value such as admin' --, which closes the quoted string and turns the rest of the query into a comment. The password check disappears, and the attacker logs in as the administrator without knowing the password.
The same principle applies anywhere user input reaches a query: search boxes, URL parameters, cookies, HTTP headers, and API requests.
Automated tools such as sqlmap can detect and exploit these flaws quickly, which means even low-skilled attackers can abuse them.
SQL injection has caused some of the UK’s most notable breaches. In October 2015, attackers used SQL injection against legacy web pages at TalkTalk, accessing personal data of around 157,000 customers. The Information Commissioner’s Office fined the company £400,000, criticising its failure to fix a vulnerability that was easy to prevent. In May 2023, the Cl0p group exploited a SQL injection vulnerability in the MOVEit Transfer file transfer software (CVE-2023-34362), stealing data from hundreds of organisations worldwide. In the UK, staff data at British Airways, the BBC, and Boots was exposed through their payroll provider.
The fix is well established:
A web application firewall can block many common SQL injection attempts and provide temporary protection, but it should never replace fixing the code.
Code review and static analysis tools can find unsafe query construction during development, especially when built into secure software development pipelines. Dynamic scanners and manual penetration testing find vulnerabilities in running applications, including complex blind and second-order cases that automated tools miss.
At Privia Security, our Web Application Security Services test your applications and APIs for SQL injection and other injection flaws, with clear remediation guidance for your developers.
Yes. Although modern frameworks make it easier to avoid, SQL injection still appears in legacy code, custom queries, reporting features, and third-party products. The MOVEit Transfer breach in 2023, which affected hundreds of organisations, was caused by a SQL injection vulnerability. It remains a standard part of every web application penetration test.
Input validation helps, but it should not be relied on alone, because attackers are skilled at finding inputs that slip past filters. The reliable defence is parameterised queries, which keep code and data separate regardless of what the input contains. Validation, least privilege, and a web application firewall then add extra layers.
No. NoSQL databases such as MongoDB do not use SQL, but they can still suffer from NoSQL injection when applications build queries from untrusted input, for example by accepting query operators inside JSON requests. The same principles apply: avoid building queries from raw input, validate data types, and use safe query APIs.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.