Hostxpeed
Login Get Started →
Security

How to Block SQL Injection Attacks

5 min read
26 views
Jun 12, 2026

Using ModSecurity

OWASP CRS automatically blocks SQLi patterns. Create custom rule:

SecRule ARGS "@rx (?i)(select|union|insert|update|delete|drop|--)" "id:1000,phase:2,deny,status:403,msg:'SQL Injection Detected'"

Using Nginx Native (without ModSecurity)

location ~* (select|union|insert|update|delete) {
return 403;
}

Application-Level Protection

Use prepared statements and parameterized queries in your code.

Test with sqlmap (authorized only)

sqlmap -u "http://example.com/page?id=1" --batch

Was this article helpful?