Some years ago, before ColdFusion 9's multi-file Flash based uploader tag, we built our own product to upload multiple files at once, and packaged it as part of our Command Box Share (www.commandboxshare.com) product. No, this blog entry isn't a thinly disguised marketing attempt to get you to go over to that site and sign up -- but feel free if you do like easy file sharing between project users. ;-) Rather, an issue that came about with our custom built Flash uploader is what I wanted to mention today. Basically, with ColdFusion 9, it stopped working in Firefox.
When I initially received the report that our upload tool was no longer working in Firefox, I immediately thought that perhaps an update to Firefox had caused the issue, although that didn't make a lot of sense... the upload tool itself is built in Flash, so it shouldn't matter what browser you're using. The Flash uploader basically just uploads to a page inside the site, and it shouldn't matter what browser you're dealing with, right? Sort of...
See, the site requires you to be logged in so that you only have access to your own projects and files. When we originally built Command Box Share and this Flash tool, we did so in a ColdFusion 8 environment. Unfortunately, in Firefox, at that time, we noticed that sessions were not being carried over to the upload page by the Flash "client"... essentially, your session would tell ColdFusion that you weren't logged in with the Flash client, and the upload wouldn't work, because behind the scenes, your upload request would be rerouted to a login page. To remedy this, we did what we thought at the time was a pretty simple fix -- we appended the currently logged in user's CFID and CFTOKEN values to the URL the Flash uploader calls for the upload. In ColdFusion 8, this worked wonderfully -- with those URL variables in place, the Flash client took on the same session as your browser session, and the upload went though.
Then came CF9. After troubleshooting for awhile, looking at web log files and coming up with nothing out of the ordinary, it dawned on me that perhaps something goofy was going on with sessions again. So, I added some simple ColdFusion logging code to the upload page to track the client's session, and viola... I started seeing that the browser and the Flash client in Firefox were reporting different Session CFIDs and CFTOKENs, despite the fact that the upload page was being provided with URL versions of these variables. I thought this was a bug, until I found the following blurb in the "Managing the client state" ColdFusion 9 Developing CFML Applications Help PDF.
Note: The behavior is as follows when CFID and CFTOKEN are provided in the URL: If session exists, the CFID and CFTOKEN from the URL are ignored. If the session does not exist, CFID and CFTOKEN from the URL are used to validate the session and the session is used if it is valid. If the session is not valid, a new session is created. CFID and CFTOKEN are regenerated.
Basically, this is changed from ColdFusion 8, and you can test that if you have access to both versions of ColdFusion with a simple "test.cfm" page with the following code:
<cfapplication name="test" sessionmanagement="Yes" setclientcookies="Yes" sessiontimeout="#CreateTimeSpan(0,8,0,0)#">
<cfdump var="#Session#">
Run that page once in Firefox, and then run it again in another browser, to ensure that you're not sharing cookies/sessions. Take one browser's CFID and CFTOKEN variables, and append them to the other browser's URL like such: test.cfm?CFID=13119&CFTOKEN=45964259 (obviously, substitute these numbers for the numbers shown in your dump). If you do this on a ColdFusion 8 server, your session will now magically change over to the other browser's session -- you'll have basically changed sessions. If you do this on a ColdFusion 9 server, you'll note that your session does NOT change, despite the CFID & CFTOKEN URL variables.
Now, is this a bug or broken? I don't necessarily think so -- the way ColdFusion 9 is handling this now is much safer and more secure. Hackers can't hijack your session cookie values and theoretically steal away your sessions. I don't think a lot of that really happened, but still, this change in CF9 removes the chance altogether, apparently. The only side effect it has is for solutions such as the one we used for Command Box Share, where a legitimate issue caused the need to sort of "assign" a session to the rogue Flash client in order to upload. I imagine others will likely run into this behind secured sites using the new <CFFILEUPLOAD> tag, too.
What to do then? Well, I don't think there's really a workaround... rather, until Flash or Firefox somehow fixes the apparent bug with Flash getting its own session, we simply have to rethink how we approach the issue. For us, with Command Box Share, the solution will be in providing an internal session tracking GUID to Flash to pass on to the upload page so that it knows the Flash uploader is cleared to do its thing. The alternative, ignoring security altogether and just letting the Flash upload occur without any type of login authentication, is way too risky to consider -- despite the fact that many people do just that, and it's not a good idea.
Let me know if you've seen behavior such as this with your Flash upload applications, and if you solved the issue any differently!