Ionic ISAPI URL Rewrite Decodes "%26" Into Ampersand (&) By Default

Posted May 26, 2011 at 9:24 AM by Ben Nadel

Tags: ColdFusion

Yesterday, I discovered a very confusing behavioral difference between a development server and a production server. Locally, query string variables could contain "%26" which represents a url-encoded ampersand. This escaped ampersand would then become decoded and available within the given URL variable at the ColdFusion level. On the production server, however, this "%26" was being decoded into a regular ampersand before the request was routed to the ColdFusion application server. As such, ColdFusion would treat the rendered "&" as a query string name-value-pair-delimiter and would end up creating an additional, invalid variable. After 3 hours of Googling, I finally figured out that this had to do with the default behavior of Ionic's ISAPI URL rewrite filter.

To illustrate what was happening, imagine that I was making a request to the ColdFusion server with the following query string:

?foo=this%26that

Locally, this would result in the URL name-value pair:

  • foo = "this&that"

On the production server, however, we were getting the following URL name-value pairs:

  • foo = "this"
  • that = ""

As you can see, the premature decoding of "%26" into "&" caused ColdFusion to use it as a query string delimiter rather than as an embedded character.

Apparently, Ionic's ISAPI URL rewrite filter decodes certain values by default in order to make it easier for you to write your regular expression rules. This decoding gets applied to both the script name and the query string, which is what was causing the problem. To fix this situation, I had to add the following directive to the Ionic ISAPI config file:

  • UrlDecoding OFF

This allowed the "%26" to fall through, unaltered, to the ColdFusion application server where it could be handled more appropriately.

This strikes me as a rather unusual default behavior for a URL rewriting engine. I have to assume that I am missing something critical about URL decoding as I can't think of a single reason why I'd want to handle decoding at the rewrite level vs. the underlying application level (whichever technology that may be).




Reader Comments

May 26, 2011 at 10:00 AM // reply »
2 Comments

I had a similar problem a while ago. I was using an ajax post to send form variables but due to some funny interaction the server was creating the html simbol for an ampersand so my url varables were not sending through correctly.

my workaround was to send via form variable and instead of rewriting 1000's of lines of url's to forms I wrote a nested if statement to redo all the form variables as url variables. please note this process was faster than to rename all the url to form as the code was originally written badly.


May 26, 2011 at 10:04 AM // reply »
10,743 Comments

@Herman,

I had considered looking at the POST angle as well; but, we did have one point of 3rd party contact where that wasn't a possibility (and was, in fact, where the problem first presented itself).

You can't imagine how frustrated I was getting trying to debug this problem!! :D


May 26, 2011 at 10:44 AM // reply »
38 Comments

We've had other issues with Ionics & have had to roll back to an earlier version. Due to its recent verified inconsistency of returning the correct file, we've had to disable one of the rules that we were using (we added a 14 digit timestamp to the end of js/css resource filenames).

If you use 2.1.1.26 & SSL, make sure that "Site Logging" is enabled.
http://iirf.codeplex.com/workitem/27582

Could Adobe build a MODRewrite feature into ColdFusion or is there another, more dependable way of doing it in IIS?

BTW: I couldn't post this message using Firefox 4.0.1 (Windows7) and re-posted using Google Chrome. In FF Firebug, I see "$ is not defined". The local javascript file can load before the jQuery library since they are coming from 2 different domains & not loaded serially.

The versioning that you are using on resource files (?v=9) doesn't update some network caches properly & is the primary reason that I started adding a date hash to the end of filenames. Since you are serving up a CF file, I recommend adding it to the path instead and add the "js" extension to satisfy security software. (ie, javascript.cfm/v/9.js) Since using CF, make sure that you are returning "text/javascript" mime type (I see that you are doing this correctly.)

Here's the IIRF rule I am using:
RewriteCond %{SCRIPT_NAME} ^/_scripts/(.*)$ [I]
RewriteRule ^(.*)(_[0-9]{14}\.)(css|js)$ $1.$3 [I,QSA,L]

I maintain a server-scoped structure of the js/css filenames & dates. I wrote a function to access the structure and rewrite the resource URL & append the date/time hash if it exists. (Everything would be perfect if IIRF worked consistently... to many reports from clients that it wasn't working. sigh.)


May 26, 2011 at 11:22 AM // reply »
10,743 Comments

@James,

Locally, I use Apache mod_rewrite, and on this blog, personally, I use IIS MOD-Rewrite. I only have Ionic running on one particular production site; I've not had occasion to test this anywhere else (as I very rarely have escaped ampersands in anything).

That's not good to hear about the "$" undefined issue! The two script files *should* load in serial, even if they are retreived in parallel. From my understanding, the browser will optimize the HTTP connections (in parallel); but, once gotten, it will still execute the Script tags in the order in which they were defined in the DOM.

I haven't made any changes to the JS in some time, so I don't think it would be a caching issue.

I'll see if I can figure it out - thanks for letting me know!


May 26, 2011 at 4:08 PM // reply »
164 Comments

@Ben:

I wonder if it's really not a bug in Ionic. My guess is it's not really supposed to be passing back the decoded parameters. I can't think of a single situation in which that wouldn't ultimately cause potential issues.


May 26, 2011 at 4:16 PM // reply »
10,743 Comments

@Dan,

Right, the only reason I can think of it is that was intended only for the "file path" part of the URL. Since certain characters are illegal in the URL, that would be the only place where it would make pattern matching easier.

Given the fact that using illegal characters in URLs it a bad idea to begin with, I certainly can't think of a reason it would make sense for the query string.


Jun 1, 2011 at 12:16 PM // reply »
9 Comments

This happened to me today in fact. The problem was that Ionic was taking spaces in file names, decoding them, and then when IIS got it, it got "%20" literally-- not the encoded version--thus IIS couldn't decode it and I got a 404. At least, that's what appeared to be happening. The funny thing was that it only happened if I was trying to pass the URL into the CGI.Path_Info and not into a query.

I guess I'm lucky you addressed this issue just a few days ago, otherwise I'd probably still be pulling my hair out.


Jun 1, 2011 at 12:24 PM // reply »
10,743 Comments

@Doug,

Awesome, I'm glad that I could help. Seems like such a frustrating problem to waste time on. That's weird though that it only affected the path_info variable. Very odd!


Jun 1, 2011 at 12:51 PM // reply »
38 Comments

Does anyone use any other mod-rewriting tools for IIS?

I recently found "IIS Mod-Rewrite". It's not free, but it has 100% compatible syntax and behavior with Apache mod_rewrite and override (.htaccess) configurations.
http://www.micronovae.com/ModRewrite/

I'd like to know how it compares to IIRF (or other solutions). I've had to disable some IIRF rules since IIS didn't seem to be consistently returning the correct files.

I'm considering using this reverse proxy product for hosting resource files with a datehash added to the end of filenames (for permanent caching/cache busting). It handles rewriting rules and seems more robust than IIS (15,000 requests/sec):
http://www.iqproxyserver.com/


Jun 1, 2011 at 12:55 PM // reply »
10,743 Comments

@James,

I actually use IIS Mod-Rewrite for this blog:

http://www.bennadel.com/blog/1696-Exploring-IIS-Mod-Rewrite-For-Rewriting-URLs-In-A-ColdFusion-Application.htm

I've been very happy with it. It seems to be extremely compatible with my local Apache mod_rewrite module, which makes mirroring live and local a snap!


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 21, 2012 at 1:58 AM
Updated: Converting A ColdFusion Query To CSV Using QueryToCSV()
Hi Ben, why do you need to have so many double quotes when adding the field and field name to the row data? ----------------------------------------- <cfset LOCAL.RowData[ LOCAL.ColumnIndex ] = ... read »
AXL
May 21, 2012 at 1:24 AM
URL Rewriting And ColdFusion's WriteToBrowser Image Functionality (CFFileServlet)
@Mounir, Open your lower case URL Rewrite rule and add the following condition. Condition input: {REQUEST_URI} Check if input string: Does Not Match the Pattern Pattern: ^/CFFileServlet/_cf_ca ... read »
May 20, 2012 at 4:28 AM
Understanding The Complex And Circular Relationships Between Objects In JavaScript
@Will Vaughn I tried your javascript example but got this error:- foo.print is not a function ... read »
May 19, 2012 at 5:37 AM
A Graphical Explanation Of Javascript Closures In A jQuery Context
Thanks for this article, but I fear you missed an important point. If variables in the outer context change, these changes affect the inner anonymous functions as well. That means: if you change the ... read »
May 18, 2012 at 3:39 PM
Parsing CSV Data With An Input Stream And A Finite State Machine
Can you use file upload button with this? and read live? or does the file have to already be on the server saved? ... read »
May 18, 2012 at 1:06 AM
VIRGO (Aug. 23-Sept. 22): Dead On The Money!
A friend of mine and I were arguing about astrology and she told me that he believes in astrology. She hasn't provided me with any evidence that the belief makes any sense to me. She she been telling ... read »
May 17, 2012 at 11:32 PM
Using ColdFusion to Handle 404 Errors (Page Not Found) On Development Server
Very easy the configuration. I read a lot pages and I can't find the solution. I open the administrator and change this Administrator/server settings/Error Handlers/Missing Template Handler and p ... read »
May 17, 2012 at 3:13 PM
LOCAL Variables Scope Conflicts With ColdFusion Query of Queries
I never cease to be amazed that almost EVERY random CF issue I come across lands me on your site. Thank you for documenting your findings for the world. ... read »