Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Blocking SQL Injection with htaccess

DZone's Guide to

Blocking SQL Injection with htaccess

· Database Zone
Free Resource

What if you could learn how to use MongoDB directly from the experts, on your schedule, for free? We've put together the ultimate guide for learning MongoDBSign up and you'll receive instructions for how to get started!

I'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]



 

What if you could learn how to use MongoDB directly from the experts, on your schedule, for free? We've put together the ultimate guide for learning MongoDBSign up and you'll receive instructions for how to get started!

Topics:

Published at DZone with permission of John Whish, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}