Prompt
How do I block SQL injection attacks on my website without changing code?
Latest observation
If you truly can’t change the application code, your best options are defense-in-depth controls in front of the app. These won’t be as strong as fixing the code (prepared statements/parameterized queries), but they can reduce risk a lot.
Best no-code options
1) Put a WAF in front of the site
A Web Application Firewall can block many SQL injection patterns before they reach your app.
Examples:
- Cloudflare WAF
- AWS WAF
- Azure WAF
- Imperva
- Akamai
- ModSecurity with OWASP Core Rule Set
What to do:
- Enable managed SQLi protection rules
- Start in log/monitor mode if possible
- Tune false positives for your site
- Turn on rate limiting and bot protection too
2) Use a reverse proxy / security gateway
If you control the web server or load balancer, place a proxy in front that can inspect requests and block suspicious payloads.
Useful features:
- Request filtering
- URL/query inspection
- Header validation
- Body inspection for POST/JSON requests
- IP reputation filtering
3) Apply strict input filtering at the edge
If your gateway or WAF supports it, block requests with:
- SQL keywords in suspicious contexts (
UNION,SELECT,INSERT,DROP, etc.) - Comment markers like
--,/* */,# - Encoded obfuscation attempts
- Unexpected special characters in parameters that should be simple values
Be careful: overly aggressive rules can break legitimate traffic.
4) Restrict what the database user can do
Even without code changes, you may be able to reduce impact by changing DB permissions:
- Use a DB account with least privilege
- Remove
DROP,ALTER,CREATE, or admin rights - Limit access to only necessary tables
- Separate read-only and write accounts if feasible
This won’t stop injection, but it can limit damage.
5) Harden the database and network
- Keep the DB not directly exposed to the internet
- Allow connections only from the app server
- Use firewall rules / security groups
- Disable dangerous DB features you don’t need
- Keep DB engine patched
6) Add rate limiting and anomaly detection
SQL injection often comes with probing behavior.
- Limit requests per IP/user/session
- Block repeated 4xx/5xx bursts
- Alert on unusual query patterns
- Watch for spikes in parameter errors or database failures
7) Sanitize at the edge if you must
Some platforms let you rewrite or reject requests before they hit the app. This is weaker than proper code fixes, but can help for known parameters.
Important limitations
No-code protections are mitigations, not full fixes. A determined attacker may still bypass filters with:
- Encoding tricks
- Alternative payloads
- JSON/body-based injection
- Second-order injection
Recommended practical setup
If you want the most effective no-code defense:
- Put the site behind a WAF
- Enable managed SQLi rules
- Turn on rate limiting
- Restrict the database account privileges
- Ensure the DB is not publicly reachable
- Monitor logs and tune false positives
If you want, I can help you choose a specific setup based on your hosting platform:
- Apache/Nginx
- Cloudflare
- AWS
- Azure
- cPanel/shared hosting
- WordPress or other CMS