Cold Fusion Cookie Monster

Cold Fusion and Cookies (not so tasty this time, it seems)

I recently came across a problem in a CMS that I write code for where cookies weren't being read properly by the browser. The problem came when a cookie needed to activate the CMS toolbar to turn on the edit capabilities existed in both lower and upper case in the browser but ColdFusion was only updating the upper case one while reading the value of the lower case one as the value used on the cookie{} struct. I didn't find a whole lot on how this was happening but I did eventaully find the answer after some meticulous research and more than a few botched attempts at fixing it.

Cold Fusion Writes Upper Case Cookies

In ColdFusion, anytime the cfcookie tag is used, the cookie is written to the browser in upper case. For example;

gets written to the browser as:


While the value will be written as provided, the name is always upper-cased. However, there is more than one way to set a cookie, and this is where the problem came in.

Three Ways to Bake a Cookie in Coldfusion

There are three different ways to set a cookie in ColdFusion and, of course, the ability to use dot notation or object notation inside of those methods.

cookie.myCookie = "chocolateChip";

All of the above statements write a cookie to the browser but the method yields a browser cookie called "myCookie" (the provided case). This issue is what was yielding my multiple cookies with the same name strings in different cases. Since Coldfusion will only recognize one of the cookie values, it was reading the lower case one and updating the upper case one. Pretty confusing stuff until I got to this.

So, What Do I Do About It?

I finally came to the conclusion that the only real consistent way to write a cookie from ColdFusion was to use the tag and not set the value in or use to handle a missing cookie value. I replaced all of the instances with:


and when the appeared:

This allowed me to keep uniformity with how cookies are being set both when using CFML and by simply creating a simple abstraction of the tag. So far, it has proven 100% effective in resolving ambigous cookies.

As always, I am happy to take comments about this or any other post/page on this site. Shoot me an email if you have something you'd like to point out or add.

posted 11/30/2017 in ColdFusion
Tags: ColdFusion, cookies


No comments have been posted.

Leave a comment:
HTML not allowed, max characters 255, * denotes required field.