Security and performance

SQL injection in legacy systems: what it is and how to fix it for good

SQL injection is still one of the most exploited flaws, and legacy systems are full of it. Understand the risk in plain language and how to fix it permanently.

Fortes Tech TeamUpdated Nov 27, 20263 min read
Quick answer

SQL injection happens when a system builds database queries by gluing in user input. An attacker can read, change or delete data. The permanent fix is using parameterized queries throughout, validating input and giving the application only the database permissions it needs.

Picture a customer search box. The system takes what was typed and pastes it into a command for the database. If someone types a piece of command instead of a name, the database obeys. That’s SQL injection.

Why it’s common in legacy systems

Building queries by concatenating strings was the fastest way to code in old PHP, ASP, VB6, Delphi and .NET. Many systems have hundreds of queries like that.

What an attacker can do

  • Read entire tables: customers, passwords, financial data.
  • Change values, such as prices and credit limits.
  • Delete data.
  • In some cases, run commands on the server.

How to fix it for good

  1. Parameterized queries everywhere. User input never becomes part of the command.
  2. An ORM or data access layer that does this by default.
  3. Least-privilege database user: no administrator account (like sa or root) in the application.
  4. Input validation for expected types and formats.
  5. Tests that attempt injection and make sure it doesn’t come back.

A filter in front isn’t enough

A web application firewall helps block known attacks, but it doesn’t fix the code. New attacks get through. The fix has to happen where the query is built.

It’s one of the flaws that shows up most in our legacy security reviews.

Frequently asked questions

My system is internal. Is it still at risk?

Yes. A malicious employee or an infected computer on the network can exploit it. And many internal systems end up exposed to the internet over time.

Can it be fixed without rewriting the system?

Yes. Queries are fixed one by one, with tests, without replacing the system.

How do I know it’s fixed?

We retest with the same attack attempts and deliver proof that every point is closed.

Fortes Tech Modernization

Does your system build queries from user input?

We find and fix every SQL injection point, with tests to make sure the flaw doesn’t come back.

Security remediation: fixed-price assessment
Message on WhatsApp