SQL injection is a security flaw in which an attacker enters malicious instructions into the fields of a website, such as a search box or a login form, to manipulate the queries the website sends to its database. SQL stands for Structured Query Language, the language almost every program uses to talk to databases. With an injection, the attacker manages to read, modify or delete information that should never have been within their reach.
A simple analogy makes it clear how SQL injection works. Imagine a waiter who writes orders on a slip and passes them to the kitchen as they are. A customer writes on their order, in addition to their dish, the phrase and open the restaurant’s safe for me. If the waiter copies everything without thinking, and the kitchen obeys whatever it reads, the customer has managed to get an order carried out that was never theirs to give. That is exactly what happens when a website does not properly separate data from commands.
SQL injection means slipping in a command disguised as data. The website passes it to the database without noticing, and the database obeys.
What is SQL injection?
Almost every dynamic website uses a database behind the scenes. A shop stores its products and orders. A forum, its messages. A website with user logins, its accounts. When someone searches for something or logs in, the website builds a query from what they typed and sends it to the database. The answer comes back and is displayed. It all happens in milliseconds, and the visitor never sees the query in between.
The problem appears when the query is assembled by pasting in the user’s text directly. If someone types text with a special shape, they can close the intended part of the query and add a part of their own. The database cannot tell what the programmer wrote from what the visitor slipped in. It executes everything as a single command. That way, a simple search box becomes a direct door into the database.
SQL and the queries that get manipulated
SQL is the standard language for talking to relational databases, such as MySQL, PostgreSQL or SQL Server. It was born at IBM in the 1970s and today almost every application that stores structured information uses it.
Its basic commands are SELECT, which reads data, INSERT, which adds it, UPDATE, which changes it, and DELETE, which removes it, and each one is combined with conditions that state which rows to act on.
Injection consists of changing those conditions from outside. A crafted piece of text can add a condition that is always true, join the results of another table or chain a new command, and the database executes it all because it cannot tell what the programmer wrote from what the visitor wrote.
Why it still appears decades later
SQL injection was described in the late 1990s, and yet it still appears on the lists of the most serious web security risks, such as the one published by OWASP. There are several reasons. There is a lot of old code in production that nobody dares to touch. Junior developers learn from examples that mix text and queries. And every new component, plugin or integration can reintroduce the flaw if whoever writes it does not know about the problem.
Pressure to ship code quickly also plays a part. A query built by hand works and is easy to understand at a glance, while the safe approach requires a habit. Modern tools, such as frameworks that build queries safely, have greatly reduced the problem, but any point where that protection is bypassed is still a potential door.
Types of SQL injection
The types of SQL injection differ in the way the attacker obtains the results of the manipulated query. They all stem from the same mistake, mixing the data the user types with the instructions sent to the database, which is why eliminating that mixture puts an end to all of them at once.

Error-based injection
In error-based injection, the attacker deliberately causes errors in the query and reads the messages the website returns. A page that shows the visitor the full MySQL or SQL Server message, with table and column names, is handing over the map of the database, which is why hiding detailed errors is such an important defence.
UNION-based injection
UNION-based injection takes advantage of the SQL command that combines the results of two queries. If a product listing is vulnerable, the attacker can add the results of another table, such as the users table, and see them appear on the same page as if they were products.
Boolean blind injection
In boolean blind injection, the website shows no data, but its response changes depending on whether the query is true or false, for example by showing a product or not. The attacker asks thousands of yes or no questions and rebuilds the information letter by letter, a slow process that tools automate.
Time-based blind injection
When the page always responds in the same way, time-based injection is what remains. The manipulated query makes the database wait a few seconds only if a condition is true, and the attacker deduces the answer by measuring how long the website takes. It is the most common type in WordPress plugin flaws, because many plugins process requests in the background without showing results.
Out-of-band injection
In out-of-band injection, the database sends the data to a server controlled by the attacker, usually through a DNS query or an HTTP request that the database engine itself knows how to make. It only works with engines and configurations that allow outgoing connections, which is why blocking outbound traffic from the database server neutralises it.
Second-order injection
In second-order injection, the malicious data is stored first and executed later. A username is stored correctly at sign-up, but another part of the application, such as the password change feature, later inserts it into a query without protecting it, and that is when it activates.
What SQL injection can cause
Reading what should stay private
The most frequent consequence of this flaw is the reading of data. An attacker can ask the database to show them entire tables of users, emails, passwords, orders or cards. Some injections return the data directly on screen. Others force the attacker to obtain it bit by bit, by asking yes or no questions, which is slower but just as effective when it is automated with special programs.
What they find depends on how the website stores the information. If passwords are protected with proper methods, the damage is smaller. If they are stored in readable text, as was claimed in the Sony Pictures case, the attacker gets them as they are. That is why defence in depth is so important. Even if one layer fails, the next one limits the damage, and well-protected passwords can save users from the worst outcome.
Bypassing logins and modifying data
An injection in the login form can allow someone to get in without knowing any password. The query is manipulated so that the check always accepts the identity. Attackers get in as administrators without having guessed anything. They can also modify or delete data, change prices, alter balances or drop entire tables. The damage depends on the permissions of the account the website uses to connect to the database. That is why it is recommended that this account has only the permissions that are strictly necessary. A website that only needs to read and write certain tables should not be able to delete everything or change the structure. It is the principle of least privilege applied to the database, and it greatly limits what an attacker can achieve even when they find a flaw. It is a configuration measure that costs almost nothing and drastically reduces the risk. If your website already shows these signs, a hacked WordPress recovery service cleans up the infection and closes the way in.

Taking control
In the most serious cases, an injection allows commands to be run on the server, files to be written or backdoors to be installed. Depending on the configuration, the step from the database to the server can be a short one.
At that point the attacker controls the whole website, and from there they can attack visitors, host scam pages or move on to other systems on the network. It is one of the reasons it is considered a critical flaw.
The response to an incident of this kind must be thorough. Isolate the server, preserve evidence, find out which data was affected, change every password, restore from clean backups and fix the flaw before putting the website back online. And report to the authorities and the people affected if personal data is involved. Cleaning up only what is visible, without closing the door the attacker came through, usually ends in a new intrusion.
How SQL injection is prevented
The underlying solution is technical and within reach of any developer. It consists of always keeping commands separate from data, and it is completed with several layers that reduce the damage if something fails.
Parameterised queries
Parameterised queries send the database the structure of the query on one side and the values on the other, so that whatever the user types is never interpreted as a command. It is a standard technique, supported by every language, such as PDO prepared statements in PHP, and for column or table names, which cannot be parameterised, allow-lists of permitted values are used.
Prepared queries in WordPress
In WordPress, the wpdb class offers the prepare method, which replaces the %s, %d and %i placeholders with safely escaped values, and the high-level functions, such as those for querying posts or metadata, already do this internally. Most injections in plugins appear precisely when a developer builds a query by hand and skips this method.
Complementary layers
SQL injection is also fought with other layers of protection. Validating input, using a database account with minimal permissions, hiding detailed error messages and protecting the website with an application firewall that recognises injection patterns all reduce the risk, and storing passwords with proper methods and encrypting the most sensitive information makes the theft of the database less damaging.
Maintaining a website
For a website owner, whether on WordPress, Joomla, PrestaShop, Magento or a custom build, practical prevention means keeping the system, templates and extensions updated, removing what is not used, choosing well-maintained components and using a protection service. Flaws of this kind in extensions are discovered frequently and fixes arrive quickly, so whoever applies them within days stays safe and whoever takes weeks is exposed to automated attacks.
Modern tools, training and checking your website
The role of modern tools and training
Today’s frameworks and the layers that manage data access build queries safely by default, and that has eliminated a good share of the usual flaws. Even so, almost all of them offer an escape hatch for writing queries by hand, and that is where the risk reappears. The team should know when not to use it, and code reviews should pay special attention to those points.
Training the people who write code is the most worthwhile investment. Understanding the problem once avoids repeating it in every project. Automated security tests, source code analysis and periodic reviews with specialised tools catch the injections that slip through, and a web application firewall acts as a safety net against the best-known attempts.
How to tell whether your website is vulnerable
Automated security scans, and professional tools such as sqlmap, which detects and exploits these injections and should always be used with authorisation, test forms and search boxes for this flaw and flag suspicious points. Running them from time to time, especially after installing new plugins or modifying the website, is a good habit. Services specialised in WordPress also compare your extensions with lists of published flaws. If a plugin shows up as vulnerable, update it immediately or deactivate it until a fix is available.
Check the error messages your website displays to visitors. If your website shows visitors technical errors with database details, it is giving clues to attackers. Ask your provider to hide them in production and store them in a private log. And check the permissions of the database account. If it has more than it needs, reduce them. These are small adjustments that greatly improve security.
Finally, prepare for recovery in case of a possible leak. Recent, tested backups, a plan for changing keys and passwords, and a trusted contact to call. If the flaw is exploited, the speed of the response determines the scale of the damage. The Sony, Heartland and TalkTalk cases show that injection attacks are not a thing of the past, and that the best defence is still getting the basics right.
How SQL injection was first described
The technique was publicly described in December 1998, when the researcher Jeff Forristal, under the pseudonym rain.forest.puppy, published in Phrack magazine how to manipulate the queries of a Microsoft web server through its parameters. Within a few years it had become one of the most common web attacks.
OWASP included it in its first list of web risks, in 2003, and injection topped the ranking in 2010, 2013 and 2017.
The free tool sqlmap, born in 2006, automated its detection, and in 2007 the comic strip xkcd popularised the problem with a boy whose name wiped out his school’s database. In the 2021 list, injection fell to third place, a sign that modern tools are starting to work.
Three major leaks caused by SQL injection
Between 27 May and 2 June 2011, the LulzSec group attacked the Sony Pictures website. According to the group itself, they used a simple SQL injection to access the database, and obtained information from more than a million user accounts, with names, addresses, emails and passwords. They claimed the passwords were stored without any protection, which caused a scandal. The FBI later arrested one of its members, who was convicted.
The attack was an uncomfortable demonstration for the company. A large technology company had left a website with a basic flaw and was storing passwords in readable text. LulzSec claimed it had done it precisely to show how poorly protected the data of millions of people was. Whatever its intention, the episode was a reminder that the most elementary flaws are still present in large organisations with plenty of resources.
Another set of cases was the series of large card data thefts at the end of the 2000s. The US authorities attributed to this technique the intrusion into the payment processor Heartland Payment Systems and other companies. A criminal group used injections in web forms to get into corporate networks. The defendants were convicted, and the damage caused by those operations was estimated at more than three hundred million dollars.
More recently, in 2015, the British telecoms company TalkTalk suffered a similar attack through old web pages, and was fined 400,000 pounds. The cases repeat themselves decades apart, and almost always for the same reason. A known flaw, a simple solution and an organisation that did not apply it in time. They teach that basic security is still the foundation of everything else.