SQL injection: what is it and how can you reduce the risk to your company?
SQL injection is a web application vulnerability that allows user-supplied data to influence database queries. For a company, the risk is not limited to a technical issue: it can lead to data loss, business interruption and claims from clients.
- 🧩 The root cause is the improper separation of data and commands. The attack occurs when an application builds SQL queries by directly concatenating values received from forms, URLs or other sources.
- 🔐 Parameterised queries are the fundamental safeguard. They treat supplied values as data rather than executable SQL instructions.
- 🛡️ Validation alone is not enough. Allow-lists, testing and restricted database account permissions must be used together.
- 📊 The impact can extend beyond the vulnerable application. Customer data, transactions, reputation and contractual relationships may all be affected.
- ⚖️ A technical risk can become a professional liability risk. For companies that develop or manage applications, code security must be assessed alongside their liability towards clients.
🧠 What is SQL injection and how does it work?
🔎 A vulnerability introduced through improperly handled data
SQL injection occurs when an application sends data to a database without processing it correctly, allowing that data to alter the structure of a query. The attack is often described as an attempt to exploit applications that pass insufficiently processed input to databases.
The issue may arise in a login form, a search function, a URL parameter or a service that receives JSON data. An attacker does not need prior administrative access to attempt an attack.
⚠️ What an attacker may be able to obtain
Depending on the vulnerability and the permissions of the account used by the application, an attack may allow records to be read, modified or deleted. In certain configurations, the consequences may extend to file exposure or the execution of operating system commands.
🛡️ How to prevent SQL injection
🔒 Use parameterised queries
With parameterised queries, the structure of the SQL command is defined separately from the values supplied by the user. The database interprets those values as data rather than instructions, preventing them from changing the logic of the query.
This rule also applies when using database access libraries, stored procedures or ORM tools. A stored procedure is not automatically secure if it builds dynamic queries internally by concatenating text received from an external source.
📋 Validate the structure and restrict permissions
Parameters cannot safely replace table names, column names or sort directions. For these elements, the application should use a short allow-list of options defined in the code, and unknown values should be rejected.
The account used by the application should have only the permissions it needs. If a function only reads data, it should not be able to delete tables or operate with administrator privileges. This principle limits the damage but does not replace parameterised queries.
| Measure | Purpose | Limitation |
|---|---|---|
| Parameterised queries | Separate data from the SQL structure | Must be applied consistently |
| Allow-list | Controls elements that cannot be parameterised | Requires maintenance in the code |
| Least-privilege permissions | Reduce the access available after a compromise | Do not eliminate the vulnerability |
| Authorised testing | Identifies errors before production | Must be repeated after changes |
🧪 Test the application with proper authorisation
Testing should include code analysis, parameter testing and an examination of procedures that build dynamic queries. It is advisable to combine code review with automated and manual testing of parameters, headers, URLs and the data sent to the application.
A systematic review published in 2023 summarises methods for detecting, preventing and reducing SQL injection risks in web applications (Nasereddin et al., 2023). In practice, testing must not be performed on websites or systems without explicit permission.
💼 From a technical vulnerability to a business risk
📉 Compromised data can generate cascading costs
A breach associated with SQL injection may expose personal data, account information, business records or transaction data. If the application supports a client’s processes, the incident may lead to notifications, investigations, system restoration and compensation claims.
For a company that develops software, manages databases or provides IT services, the issue may become a contractual matter. The client may argue that the security measures were insufficient, even if the incident originated in a single vulnerable function.
🤝 How technical protection relates to insurance
Technical measures remain the first line of defence. A risk assessment may be complemented by cyber insurance, which is evaluated according to the type of data, the company’s activity and the possible incident scenarios.
For companies that deliver IT services or products, IT professional liability insurance may also be relevant. It should be assessed separately from security measures and aligned with the obligations assumed under contracts with clients.
👥 What community experiences show
In a discussion about protecting PHP applications, a user named “cybero” asked whether using the PDO library was sufficient to prevent SQL injection. The discussion highlights a common misconception: the tool itself does not guarantee security if the developer constructs the query incorrectly (cybero, 29 April 2012).
In a comment on an educational resource, the user “antiHUMANDesigns” reported observing SQL injection attempts on their own website, despite having implemented protection and monitoring measures. This experience shows why logs and regular reviews should not be overlooked (antiHUMANDesigns, approximately 10 years ago).
Sources and references
- Nasereddin, M. et al. “A systematic review of detection and prevention techniques of SQL injection attacks”. Information Security Journal, 2023. https://www.tandfonline.com/doi/abs/10.1080/19393555.2021.1995537
Community experiences
- cybero, Forocoches forum, question about protecting a PHP application, 29 April 2012 – https://forocoches.com/foro/showthread.php?t=2725183
- antiHUMANDesigns, YouTube, account of SQL injection attempts observed on their own website, approximately 10 years ago – https://www.youtube.com/watch?v=ciNHn38EyRc