Blocking SQL Injection with htaccess
Join the DZone community and get the full member experience.
Join For FreeI've had a recent spate of SQL injection attempts on a site I maintain. The site passes SQL parameters which greatly reduces the risk of a hacker doing anything nasty (look up cfqueryparam if you want to know more); however, the server is still having to process the request and throw an error which has an overhead and also there may be an unprotected query (such as an order by clause) so I've like to add a set of rules to my htaccess file to stop the request at the webserver level (using Apache's mod_rewrite or Helicon's ISAPI_Rewrite on IIS) before it reaches my CFML server.
These are the rules I'm using. I thought I'd share in case it's useful for others and also to ask if anyone has any improvements.
RewriteEngine On # -------------------------------------------------------------------- # SQL Injection Protection # -------------------------------------------------------------------- RewriteRule ^.*EXEC\(@.*$ - [R=404,L,NC] RewriteRule ^.*CAST\(.*$ - [R=404,L,NC] RewriteRule ^.*DECLARE.*$ - [R=404,L,NC] RewriteRule ^.*DECLARE%20.*$ - [R=404,L,NC] RewriteRule ^.*NVARCHAR.*$ - [R=404,L,NC] RewriteRule ^.*sp_password.*$ - [R=404,L,NC] RewriteRule ^.*%20xp_.*$ - [R=404,L,NC]
Published at DZone with permission of John Whish, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Building a Robust Data Engineering Pipeline in the Streaming Media Industry: An Insider’s Perspective
-
DevOps Midwest: A Community Event Full of DevSecOps Best Practices
-
Redefining DevOps: The Transformative Power of Containerization
-
Incident Response Guide
Comments