Prompt
How do I protect my website from SQL injection without changing code?
Latest observation
You can reduce SQL injection risk without changing application code, but you usually can’t fully eliminate it unless the app is fixed. The best no-code protections are layered defenses:
1) Put a WAF in front of the site
Use a Web Application Firewall to block common SQLi payloads.
- Examples: Cloudflare WAF, AWS WAF, Azure WAF, ModSecurity
- Enable managed rule sets for SQL injection
- Tune rules to avoid false positives
2) Restrict database access at the network level
Make it harder for an attacker to reach the database directly.
- Allow DB connections only from the web server/app server
- Block public access to the DB
- Use private subnets/VPC rules/firewall rules/security groups
- Restrict admin ports and remote management
3) Use least-privilege database accounts
Even if SQLi happens, limit damage.
- App account should only have needed permissions
- Avoid using
root,sa, or superuser accounts - Separate read/write/admin accounts
- Remove dangerous privileges like
DROP,ALTER,FILE,EXECUTEunless required
4) Harden the database server
- Disable unnecessary features/procedures
- Remove sample/test databases
- Keep the DB patched
- Turn off dangerous functions if possible
- Ensure error messages are not exposed to users
5) Hide detailed SQL errors from users
Verbose SQL errors help attackers refine injection payloads.
- Configure the web server/app platform to show generic errors
- Log detailed errors server-side only
6) Use parameterized proxy/filtering tools if available
If you can’t change code, sometimes you can put a reverse proxy / API gateway or security layer that validates requests before they hit the app.
- Works best for APIs with predictable parameters
- Less reliable for complex web forms
7) Segment and monitor
- Log suspicious requests
- Alert on SQLi patterns, spikes in 4xx/5xx errors, unusual DB queries
- Use an IDS/IPS if available
- Rate-limit abusive traffic
8) Apply virtual patching
If the app has known vulnerable endpoints, create WAF rules specifically for them.
- This is a common short-term mitigation
- Update rules as attackers adapt
9) Secure cookies and sessions
Not SQLi-specific, but reduces follow-on damage:
HttpOnly,Secure,SameSite- Short session lifetimes
- Regenerate sessions after login
What not to rely on
- Input validation at the network edge alone: helpful, but not enough
- Blocking quotes or common SQL words only: easy to bypass
- Obfuscation: doesn’t stop real SQLi
Best practical no-code stack
If you want the strongest protection without touching code:
- WAF with SQLi rules
- DB not publicly reachable
- Least-privilege DB user
- Generic error pages
- Logging/alerting
If you want, I can give you a step-by-step checklist for Cloudflare / AWS / Nginx / Apache / IIS depending on what you use.