FreshScanSentry Free vulnerability scanning for your network & web apps Run a free scan

High risk Website · SQL injection

SQL injection found: what it means and how to fix it

Short answer: a page on your site sends what visitors type straight into a database command. An attacker can type database instructions instead of a name or a search term, and make your database hand over, change or delete data, or let them past a login without a password.

The fix: use parameterized queries (prepared statements) everywhere visitor input reaches the database, give the site's database account only the rights it needs, and update the plugin or software that has the flaw. Treat it as urgent.

What is SQL injection?

Most websites keep their data in a database and talk to it in a language called SQL. A search box might run something like SELECT * FROM products WHERE name = 'shoes'. If the site builds that command by gluing in whatever the visitor typed, a visitor can type characters that end the intended command and start their own.

The classic example is a login form: typing ' OR '1'='1 as a password turns "find the user with this password" into "find any user", and the site logs them in. Real attacks use automated tools that try thousands of variations and pull out data one piece at a time.

Why it's so serious

Injection, which includes SQL injection, has been in the OWASP Top 10 list of the most critical web application risks for about two decades.

How it looks in your report your-site.com
  1. 443 SQL Injection Found by the Deep Scan's OWASP ZAP test High
The report names the page and the parameter affected

How it was found

How to confirm it safely

Don't try attack strings from the internet against a live site with real data. Instead:

  1. Give the report to whoever maintains the site: your developer, agency or hosting provider. The page and parameter in the report tell them exactly where to look in the code.
  2. Look at the code behind that page. If it builds a query by joining strings with user input, for example "... WHERE id = " + id, it's vulnerable whether or not the scanner is right about this exact page.
  3. Check your logs for unusual requests to that page: lots of quote characters, the words UNION, SELECT or SLEEP in the address, or database errors. Those suggest someone has already been probing it.

Only test sites you own or have written permission to test.

How to fix it

1. Use parameterized queries everywhere

With a parameterized query, the command and the visitor's input travel to the database separately, so input can never become part of the command. This is the fix that actually works.

LanguageVulnerableSafe
PHP (PDO)$db->query("SELECT * FROM users WHERE email = '$email'")$s = $db->prepare("SELECT * FROM users WHERE email = ?"); $s->execute([$email]);
Node.js (mysql2)db.query("SELECT * FROM users WHERE email = '" + email + "'")db.execute("SELECT * FROM users WHERE email = ?", [email])
Pythoncur.execute(f"SELECT * FROM users WHERE email = '{email}'")cur.execute("SELECT * FROM users WHERE email = %s", (email,))

Frameworks and ORMs (Laravel's Eloquent, Django's ORM, Rails' ActiveRecord, Prisma, Entity Framework) use parameters automatically, as long as you don't drop down to raw SQL built from strings.

2. WordPress and other CMS sites

3. Limit the damage

4. A firewall as a stopgap

A web application firewall, such as Cloudflare's WAF or ModSecurity with the OWASP Core Rule Set, blocks many common attack patterns while the code is being fixed. Attackers often get around firewalls, so don't treat one as the fix.

5. If it was exploitable, assume it was used

Check the logs, change the database password and any API keys stored in the database, reset passwords for admin accounts, and check whether personal data could have been read. If it could, get advice on your notification duties.

6. Re-scan

Run another Deep Scan after the fix to confirm the finding is gone.

Common questions

Isn't escaping input enough?

Escaping helps, but it's easy to get wrong in one place out of hundreds. Parameterized queries remove the problem by design.

The scan says "possible". Should I still act?

Yes. Have the code behind that page checked. A "possible" finding from the free scan is worth a Deep Scan or a developer's look.

Do I need the Deep Scan to find SQL injection?

For a thorough test, yes. The free Basic Scan only tries a few simple checks; the Deep Scan's ZAP test works through your pages and forms. Compare both on the website scanner page.

Sources: OWASP: SQL Injection · OWASP SQL Injection Prevention Cheat Sheet · ZAP alert: SQL Injection · Nmap http-sql-injection · WordPress: wpdb::prepare()