Thursday, December 03, 2015

Those damn BOTS!

So the other day a friend of mine experienced a high amount of Sessions running on their ColdFusion Server. After some troubleshooting it appeared that the high traffic that was causing issues was based on bot activity. He started working on some ideas on how to handle this and contacted me, which then got me interested in doing something for my servers as well.

Others have blogged about this before and his implementation is based on one of Ben Nadel's post which you can see here.

Now, I am a little less lenient on the thought of bots than my friend so I said "Hey why not block them at the Web Server level before it even hits ColdFusion (or any other language)". So while I may opt to block all bots from a web app that I do not care for them to index, he did not quite feel the same. For a website I can see where you may need to be a little more flexible, so I created a set of rules to block most and allow a selected few in.

The rules below allow for bots from Apple, Google, Bing, Yahoo, and Duck Duck Go to pass GO and collect $200. I have included both for IIS URL Rewrite and Apache mod_rewrite.

IIS 7+ using URL Rewrite


Apache using mod_rewrite


But how about them Sessions? Alex, I'll take killing sessions for $400, please.

Well, now with the rules in place blocking bat bots and only allowing a few in, I decided to run a function at onRequestEnd() that takes advantage of a new function since ColdFusion 10 called sessionInvalidate(). Thanks Charlie Arehart for reminding me of it while having a nice discussion on this topic this past CFSummit. As you can see below it is a simple reFindNoCase() on the same expression I used to allow bots in as defined in the RewriteRules.

ColdFusion 10+

I tested this using my trusty Fusion Reactor and seeing the session count go up 1 and back down 1 immediately was great, gratifying and ultimately validated my logic!

Please note, this will not change your CFID, CFTOKEN or JSESSIONID values, it simply kills the session each time. If you want new values, then you would need to do sessionRotate() as well but I did not see the need for it since as it will be only execute by bots. Also, if you are using J2EE Session Variables and want its ID reset, you will need to execute getPageContext().getSession().invalidate().

If you do have to support ColdFusion 9 or less, or some other ColdFusion engine, you can use something like Ben's solution and apply the logic to overwrite the SessionTimeout value.

Incidentally, my friend set the SessionTimeout to equal a function which then returned the TimeSpan based on his validations, rather than wrapping his validation around the settings like Ben did. I was originally worried about rewriting the SessionTimeout setting per request (which they both do), which is the reason why I opted for my way instead.

If you need to support another language, you can simply use the rules I have provided and based on how the language you are working with handles sessions, you can create a solution. Hope this helps some of you out, I know for me I rest a little better at night knowing that bots are not causing havoc on my apps and/or sites.

ColdFusion Summit 2015 Presentation Slides and Code

A little late to post, but I just wanted to say that  this year was another great experience at the CFSummit. Thank you to everyone involved and all the great feedback and interaction after my presentation, it was a very humbling and gratifying experience. Not to mention it was in the presence of my eldest daughter, so I can only say thank you for making me look cool to her, if it was only for a moment :-).

This year I was able to delve more into SSL and Cluster support with enough time to execute some quick demos. Although, my presentation skills till need a little work so I can get a good pace and get the information within the time allowed, the experience alone gave me the desire to improve and present on more things I find important.

I think I may start working on a subject that is very important to me, which is web performance and I am not talking about backend code alone but more in regards to the things we can do to make sure our requests are served as fast as possible and as small as possible. More to come on that topic later, but for now below are the links to the code and slides for this year's presentation.

Code
https://github.com/GiancarloGomez/ColdFusion-CFSummit-WebSockets

Slides
https://github.com/GiancarloGomez/ColdFusion-CFSummit-WebSockets/raw/master/slides/realtime-with-websockets-2015.pdf

Sunday, March 15, 2015

ColdFusion 11 Issue with EncodeForURL

Well this is a simple little post but I thought it would help someone in case they run into this. I tend to always go with the recommendation of using a new Function over an old one, especially when the docs tell you to. So as Adobe recommends to use EncodeForURL over urlEncodedFormat, I did and then this funny thing happened. I was trying to read an image and it would fail and it appears that when the string was being escaped, spaces where entered as "+" instead of "%20" as expected. I do not know if this is a bug or expected behavior but I thought I would share.





Tuesday, October 21, 2014

ColdFusion Summit 14 Presentation Slides and Code

Well, I would like to start this post by thanking everyone involved in this year's CFSummit. By everyone, I do mean each individual person involved even the attendees as without you there is no conference. It was truly a great experience! This being my first time speaking publicly, I can't deny that my nerves where getting the best of me but after a few minutes it just felt like being on stage again after so many years, just without a physical instrument.  I truly hope some of you walked away with helpful knowledge and I am always available to talk, so feel free to email me and as long as my schedule allows I will reply within a day's time.

I have added my slides to the GitHub repo with my presentation code under the /slides folder. So if you have pulled the repo, just do a new pull to get the slides or they can be downloaded using the following link.

UPDATE FOR CFSUMMIT 2015
https://github.com/GiancarloGomez/ColdFusion-CFSummit-WebSockets/raw/master/slides/realtime-with-websockets-2015.pdf

All the code base is available publicly so feel free to download and play with.
https://github.com/GiancarloGomez/ColdFusion-CFSummit-WebSockets

My friend did record my presentation but unfortunately it is in different formats and in 3 parts in order for it to have fit in our memory card. I am reviewing it and I am going to attempt to paste all together into one clip and I will post if successful.

Again thank you everyone! This might be a new thing for me and hopefully I will be given the opportunity to present again.

Monday, September 22, 2014

ColdFusion 11 Update 1 Finally Out!!

So finally the bugs for IIS 8 Issues have been pushed out to the public!!! Go get it now thru your server updates.

REMEMBER ON IIS YOU NEED TO RE-CONFIGURE YOUR CONNECTORS AFTER THE UPDATE!!!

You can find this normally under  {cf_install_home}/cfusion/runtime/bin/wsconfig

Also remember, right click and select "Run as Administrator"

Adobe's Notes:
http://helpx.adobe.com/coldfusion/kb/coldfusion-11-update-1.html