ColdFusion Muse

Choices for Client Vars: Registry Bad, Datasource Good

Client Variables and the Registry

Ask any experienced ColdFusion troubleshooter and he will tell you the same thing, "Don't store client variables in the registry." In fact, when examining a sick server one this is one of the first items I look at. If the customer says "It seems like the server stops about every hour" it's a safe bet that the default storage is set to Registry and the default purge interval has been left alone at 1 hour and 7 minutes (which is kind of an odd interval - probably some Adobe employee's anniversary in binary).

In many cases this is a "hidden" problem waiting to burst onto the scenes and bite some poor site owner in his nether regions. The owner launches his or her site and begins to gather traffic with the default settings for client variables. By default ColdFusion stores 90 days worth of client variables in the Registry - so the site can actually perform well for a few months. But then, out of no where, the server starts to drag and even stop every hour or so. Under the hood the purge operation is starting to find client vars that are 90 days old or more and it is taking quite a long time to delete them. The OS sees the registry keys being deleted and (sometimes) attempts to shrink the registry size. This affects a sort of "locking" on the registry where new keys are not being written - meaning requests are queuing and the server is slowing to a crawl. Now you might think that fixing this is as easy as switching from the registry to a datasource or cookie storage as the default, but there are some nuances to this fix that bear mentioning.

[More]

Rebellious Database Programming

Muse Reader Brian Asks:
Do you know of any way to SQL inject the following if the backend is MSSQL Server

<cfquery ...>
select *
from table
where username = '#FORM.username#'
</cfquery>

Occasionally someone asks me this question about CFQUERYPARAM. "Must I use it here or there? In a boat? With a goat?" Yes Sam-I-Am you should make it a habit to use it everywhere. It should be a common part of your best practice guidelines. There are even reasons to use it that go beyond security. Do a quick search for CFQUERYPARAM on this blog and you will find all sorts of information about why to use it and the very rare exceptions (FYI in case you missed the tone here, there is rarely a good reason not to use it).

As for your specific question, I can think of no way to inject the query above. If you moved the query to a MySQL server you might run afoul of the alternate way of escaping single quotes, but on an MSSQL server the query above is safe as far as I know. Just remember, right now some clever hacker in Elbonia is experimenting with ancient character sets, time travel, and a dead cat which he swings over his head while chanting "...one ring to rule them all..." - all in an effort to try and crack into a query like the one above. So I reiterate, there is no way as far as I know. It's what I don't know that keeps me up at night. You really should just use the tag as a matter of course and stop looking for places to not use it. Let me illustrate with a little story my Dad used to tell me.

[More]

Sharing Lyla Captcha Across Applications

Here's an interesting problem we had to solve recently. A customer came to us with a suite of ecommerce sites on a single server. The sites were set structurally with a core set of code that supported all the sites and then individual templates that handled the layout and design. This is actually pretty common. The folder structure allowed for site specific stuff to go in the site folder while all the common stuff (everything but specific images and layout stuff) went into the site folders.

Jasmine fishing The application file specific to each site set up the variables needed for that site, then all of the heavy lifting code was called from the "core" folder using includes, custom tags or CFCs. The idea here is to be able to affect the application code of all 50 sites on the server with a single deployment. This is an idea I endorse although there are other ways of doing it. For the scope of this suite of sites it seemed an acceptable solution.

The problem came when we wanted to run code directly from outside the application (meaning the core) without first running it through the application.

[More]

Ask-a-Muse: Using Implicit Constructors

Muse Reader Howard Asks:
I'm trying to implement the Impel HTML5 ORM on the front-end of a CF powered app. The Impel docs have an example of a PHP JSON web service that is used to return some table version information. They say that the service should return an "array of objects, but I'm a bit stumped as to how their PHP snippet would translate to CF. Could this be a struct? Here's the snippet,

<?php $callback = isset($_REQUEST['callback']) ? $_REQUEST['callback'] : 'callback'; ?>
<?php echo $callback?>([{ "table" : "card", "version" : 1},
{ "table" : "stack", "version" : 1},
{ "table" : "similar_card","version" : 1},
{ "table" : "card_score", "version" : 1} ]);
?>

While I'm not certain I have enough information be sure I'm answering your question, I can tell you that implementing an array of objects is pretty easy if you are using ColdFusion 8. Check this out:

<cfset callback = arraynew(1)/>

<cfset callback[1] = {table = "card", version = 1}/>
<cfset callback[2] = {table = "stack", version = 1}/>
<cfset callback[3] = {table = "similar_card", version = 1}/>
<cfset callback[4] = {table = "card_score", version = 1}/>

<cfdump var="#callback#"/>

Howard, you sound like you already know a good bit of this, but for the rest of you out there I believe this is usually refered to as an "implicit" object constuctor - meaning the type of object created is assumed due to the way the values are arranged in the code. It is a common feature of most languages - including PHP. It is something of a late comer to ColdFusion, but better late than never. Rather than bore you with my own inimitable style I will refer you to the excellent writing and analysis of ColdFusion Guru and all around smarty pants Ben Nadel. See his post on Implicit Struct and Array Creation.

Examining isDefined()

While perusing one of my email lists I stumbled onto a behavior of the "isDefined()" function that bears repeating. This function is commonly used in most ColdFusion applications. In fact, I would put it in the top 10 of functions used (perhaps the top 5), so any bug or interesting behavior related to isDefined( ) should warrant some notice. The short description of the problem is that isDefined() may throw an exception during a lengthy request. The conditions have to be just right.

If you are wondering if this behavior is related to an error you are experiencing, one clue is in the exception information. If you are seeing something like "error Error while reading header [VARNAME]" in conjunction with a socket write error (connection reset by peer: socket write error) then you should probably take a closer look at this post.

But before we discuss the behavior, it's important to understand how "isDefined()" works. As you know everything in ColdFusion belongs to some scope or is a member of some object. So ColdFusion has to work it's way down an order of precedence when trying to figure out if something is defined or not. Something like this.

[More]

Scope of the Month: CGI

Starting with CF 6, most scopes became structures - objects with members - but in the pre Java days of ColdFusion there were a good many differences in how various scopes behaved. Few things were objects or structures. All those neat little structure functions that are so darn useful when dealing with a scope were not invented yet. Instead we had famously ugly, workaround code with loops using lists and evaluate( ). You might remember the good old CF 4.x days when, in order to loop through form variables, you used the "special" form variable called fieldnames which contained all the form field names. Remember this code?

[More]

RIA Unleashed is Coming to Boston

ColdFusion guru and all around fabulous guy Brian Rinaldi has put together what promises to be an outstanding conference called RIA Unleased in the Boston area. The one day event is available for only 30 dollars for early bird registrations - that's unbeatable. The list of speakers includes notables like Jeff Tapper, Adam Lehman, Jason Delmore etc. - the "who's who" of the ColdFusion world (and no doubt dedicated Muse readers :). The even has 3 trackes, Flex and Air, Coldfusion and one focused on overall web development. Knowing Brian it will be an excellent event and well worth the effort. If you have the date free (November 13th from 8 am to 5:30 pm) you should consider attending. You can also follow RIA unleased on twitter at @riaunleased.

Client Variable Database and Reserved Word Alias

I had a question from a reader who was having trouble with his client variables database. You don't have to be using ColdFusion for long before you learn (or are told) that if you are going to use Client variables it is important to use a database and not the registry. This goes back to the old CF 5 days when client vars could cause the registry to grow to astronomic proportions before anyone would notice.

The solution to Client variable performance has always been to move them to a data source on an RDBMS (MySQL, MSSQL, Oracle etc). The process is all done using the ColdFusion Administrator. It is a bit involved but not difficult.

  • Add a datasource with create, update, insert and delete permissions.
  • On the "client variables" page, select the DSN from the drop down and click "add". Follow the instructions to set up the DSN. I always check the box to "disable" global variables because I never use them (things like "hitcount").
  • When you submit, the tables will be created and the DSN will be listed under the curiously named "Actions Storage Name Description" section where the registry and cookies are also choices.
Once your DSN is on the list it can be used to store variables - either by selecting as the "Default" storage location in CF administrator or specifying it in your Cfapplication tag.

Meanwhile, having explained the rudimentary steps for adding a client variable DSN my reader is impatience to hear his problem explained - so here goes. He created a DSN named "coldfusion" and used the steps above to insure that it was specified as the client variable DSN. He noticed immediately that the "global" variables were created, but no actual "client" variables were created. In other words, when he did something like "cfset client.user = 'bob'" it had no effect. Subsequent requests indicated that client.user did not even exist. Clearly the records were not being written to the DB.

The Fix

After some trial and error I suggested that perhaps the datasource name of "coldfusion" was the problem. Why you ask? As a rule I never use what could be a reserve word as a variable or datasource name. I surmised that "coldfusion" seemed to fit that standard so I suggested he create a new alias and try again. As soon as he did the tables began to update. The moral of the story - don't use reserve words for things like variable names or DSN's. Meanwhile, if by some confluence of events and aligning of the stars you have chosen to name your datasource for client variables "coldfusion" and you are scratching your head to figure out why it isn't working - try renaming the DSN.

Kevin Hoyt on ColdFusion 9

You may or may not know that the Muse' company, CF Webtools, sponsors the Nebraska ColdFusion User's Group (NE CFUG). Actually all the real work is done by our ColdFusion and Linux Guru, Ryan Stille who's energy keeps ColdFusion thriving here in the heartland. Last night we heard a presentation by the affable and knowledgeable (and really really tall) Kevin Hoyt. He spent about 2 hours both in presentation and chatting with us afterward. He was pretty cool and called his presentation a "slide deck" and talked about how the "newbies" put in too many "transitions". Oh you Adobe people and your fancy pants lingo. What will you think of next.

Now in the interest of full disclosure, I'm a ColdFusion zealot. I know that's not news to my regular readers, but it bears mentioning in case I slip up and say something negative. All in all the Muse has been thrilled with each release of ColdFusion and I have waited with bated (or is it baited) breath for each Beta (or is it Baita) version. When CF 8 came out I rewrote our entire tracking and project management system to take advantage of the new UI features. I'm an early adopter and a CF enthusiast. Also I should note that, although I have the beta version of CF 9, I will only be talking about what was in the presentation. Here's my take.

[More]

My Funny Val()entine and SQLi

Regular readers know I'm always on the lookout for interesting issues regarding SQL Injection and ColdFusion. This year has been a banner year for injection on ColdFusion sites and if you are not on the Cfqueryparam bandwagon yet I have one more example of a code that might seem to be inoculated but is not. It has to do with the use of val( )....

[More]

Ask-a-Muse: How Do I Upgrade the JVM?

Muse Reader Rob Asks:
I have a silly question. How exactly do you upgrade the JVM on your ColdFusion server? My server is on Win2k3 x64 and the JVM version is 1.6.0_04. Do you specify it manually in the jvm.config file?

I'm glad you asked this question because it reminds me that I sometimes give advice without any follow through - which is the same problem I have with my 8 iron. Upgrading the JVM on a windows installation is pretty easy. Just remember that you will need the correct Java Runtime for your platform and ColdFusion version. Rob specified Win2k3 x64 so I assume he means he is running ColdFusion 8 enterprise 64 bit - in which case the target version is 1.6 update 14 (or 1.6.0_14). I usually start at the Sun Java download page. Once you have the right version in hand the rest is easy.

[More]

Certain JPGs Can Crash Your ColdFusion 8 Server

This issue was brought to my attention by Adrian Lynch on CF-Talk. It seems that if you use the new image functions in ColdFusion 8 against certain kinds of JPG images you can actually cause your JVM to crash. If you have code that uses the latest image functions to handle uploaded images you should definitely take note of this post. I cannot yet see how a user might take advantage of this bug to penetrate your server, but a malicious (or even non-malicious) user could easily perform a denial of service attack and cause your CF server to go up and down like Jack LaLanne doing jumping jacks. So if you fit into that category (handling uploaded images using CF 8 image functionality) here's the scoop.

[More]

Connector Problems - Win2k8, IIS7 and Multi-Server ColdFusion 8 x 64 Bit

I have not yet had this problem specifically, but it was pointed out by CFG Tom Forrest who spent some time wrangling with it. He was trying to use the connector widget to connect IIS 7 sites to ColdFusion instances (running in Multi-Server Mode). He reports as follows:

The connector refused to install anything into IIS. When I started it, the first window would appear. When I clicked "add" I would see something to the effect of, Installing required IIS7 components. It may take 2 to 5 minutes to complete. The window that allows you to set all the parameters would open, and you could select any of your running CF servers. However, you couldn't select any of the IIS sites that were created. Assuming you give up and click ok, allowing it to "install to all" you would get an error window stating error creating IIS application extensions ColdFusion.

According to Tom the fix is to install the IIS 6 Management Compatibility role service. This service allows an IIS 7 server to "act like" an IIS 6 server. Once installed the configuration tool began to work.

While I haven't had this specific problem, I have noticed that a number of other things are easier and more familiar with the IIS Management Compatibility installed. Thanks Tom.

Ask-a-Muse: Killing the Immortal Thread

Muse Reader Joe Asks:
How do I kill a request? Every other day or so there will be a runaway process that cannot be killed. Clicking on the red exclamation in the monitoring tool does not give an error but it does not kill the request either. My question is how to kill this process?

Ah the immortal thread - like a god coming down from Mt. Olympus and laughing with his (or her) hands on his mighty hips (see why I chose "his"? ... "her mighty hips" ... well, I just didn't want to go there). Such threads are mind bogglingly frustrating. In actual fact, there are some requests spawned by ColdFusion that may not be able to be terminated by ColdFusion. For the long version read on McDuff.

[More]

Cfinclude for Good or Evil

Yesterday I was doing some searches on a sick server to troubleshoot the Iframe Injection issue. A user had posted some additional information regarding a file that appeared on his server that had this issue. The file was named "fection.cfm" so we now know the hacker casually removes his prefixes (or I should say 'emoves his 'efixes). I began my search by looking for the file specifically, then moved on to look for the string "cfexecute" in all of the *.cfm files. But that got me thinking. A clever hacker might know some things about ColdFusion. He could in fact, further obscure his code with some knowledge of cfinclude and IIS. Such a technique can be used to secure your code as well. You can create code that is only runnable by ColdFusion using cfinclude. Here's the skinny.

[More]

More Entries




Blog provided and hosted by CF Webtools. Blog Sofware by Ray Camden.