Extending Encrypted ColdFusion Application.cfm Functionality

Posted August 15, 2008 at 2:11 PM

Tags: ColdFusion

We just had an interesting problem here at work. We are building an eCommerce site that needs to be shut down on certain days. Normally, this would not be a problem - we'd just put some code in the Application.cfm or Application.cfc that would check the date on each request and either render the normal page or render a "Closed" page. The problem that we came up against was that we are implementing an existing software product in which the Application.cfm file is encrypted. This means that we can't go into the file and simply add the desired functionality.

At first, I wasn't sure what to do, but then something dawned on me: the Application.cfm code does NOT need to be in an Application.cfm. Well, ultimately it does, but the code itself doesn't have to be located in a file named Application.cfm. So, what we did was rename the existing, encrypted Application.cfm to be named "EncryptedApplication.cfm". Then, we created a new Application.cfm that simply included the old Application.cfm file:

 Launch code in new window » Download code as text file »

  • <!---
  • Include the template that handles the functionality and
  • display of the "Sorry, We're Closed" page.
  • --->
  • <cfinclude template="site_down.cfm" />
  •  
  • <!--- Include original Application file. --->
  • <cfinclude template="EncryptedApplication.cfm" />

This way, our "site_down.cfm" template can execute on every page request and prevent the page load, if needed. And, we don't lose the functionality of our original Application.cfm file.

Small tip, but I thought this might inspire people who are working with any off-the-shelf products that have encrypted files.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Aug 15, 2008 at 2:46 PM // reply »
11 Comments

Remember that if a directory contains both Application.cfc and Application.cfm, only the CFC is run. So another option would have been to use onRequestStart() in Application.cfc. This would just avoid renaming the existing Application.cfm


Aug 15, 2008 at 2:48 PM // reply »
3 Comments

Can't you just unencrypt it? The same exe that's worked since CF5 still works doesn't it?


Aug 15, 2008 at 2:52 PM // reply »
6,515 Comments

@Adrian,

Then we would have lost all of the functionality of the Application.cfm. But yes, if we built this thing form scratch, I would go with OnRequestStart().

@Russell,

True, I could have unencrypted it, I do have the application, but I believe that would have violated the product terms of use for the eCommerce system. That changes that anything bad would have come of it are pretty much nill, but even still, this seemed like the quicker approach :)


Aug 15, 2008 at 2:55 PM // reply »
34 Comments

I'm curious: if you're allowed to say, why do they want their eCommerce site shut down on certain days?

Most online vendors tremble at the thought of their ordering system being down for even an hour or two, lest they miss a sale.


Aug 15, 2008 at 2:57 PM // reply »
3 Comments

@Ben
Ah ya, the ever elusive terms and conditions... Sorry didn't realize this was a paid for app, I was just assuming this was something a prior developer did because they thought it would help.

Technically speaking, hasn't encrypting cfm files pretty much been a worthless security effort since about 99-00?


Aug 15, 2008 at 3:01 PM // reply »
6,515 Comments

@Brian,

It's for religious reasons. There are certain days / times were the client is not supposed to be actively making money.

@Russell,

Yeah, sorry I was not clear on that. But, definitely, encrypting the file really does nothing. I (and I assume many others) have that CFDecrypt.exe program :)


Aug 15, 2008 at 3:24 PM // reply »
38 Comments

Very clever!

I'm going to use this trick next time my wife is mad because I wasn't paying attention: "I wasn't ignoring you, honey! I was just cfincluding your conversation, which allows me to do what I'm working on now while still taking in your most excellent and awe inspiring wisdom."


Aug 15, 2008 at 3:25 PM // reply »
6,515 Comments

Ha ha ha ha :)


Aug 15, 2008 at 4:20 PM // reply »
11 Comments

@Ben:

<cfcomponent hint="Application.cfc">

<cfinclude template="Application.cfm" />

<cffunction name="onRequestStart">

<!--- yadda yadda yadda --->

</cffunction>

</cfcomponent>


Aug 15, 2008 at 4:41 PM // reply »
38 Comments

Just a thought but couldn't you add an OnRequestStart.cfm to your app which checked the date as you're using Application.cfm?


Aug 15, 2008 at 5:41 PM // reply »
6,515 Comments

@Adrian,

Good thought, but unfortunately, the two don't jive well together:

http://www.bennadel.com/index.cfm?dax=blog:731.view

@John,

Is there an OnRequestStart.cfm? Or do you mean like a custom page in the app?


Aug 16, 2008 at 6:03 AM // reply »
38 Comments

Sorry, Commented a bit too late last night (on UK time)! I meant that you would probably need to put the cfinclude that Adrian suggested in the OnRequestStart method of Application.cfc


Jul 17, 2009 at 2:11 PM // reply »
2 Comments

Do you know of any way to use this trick to "extend" Application.cfm (analogous to what Application.cfc lets you do?)

e.g. you have:
/root/Application.cfm (general application stuff)

/root/mySubSection/Application.cfm (want to include root Application.cfm along with some sub section specific stuff.)

I tried <cfinclude template="/Application.cfm" /> but that did not have the desired effect.


Jul 18, 2009 at 12:53 PM // reply »
6,515 Comments

@Mike,

Maybe use a relative path:

<cfinclude template="../Application.cfm" />

What error is it giving you?


Jul 20, 2009 at 12:06 PM // reply »
2 Comments

@Ben Nadel,

Thanks! Using a relative path worked perfectly.

When I used an absolute path I was getting CF debug output in the content panel of the page - that may be specific to our Application.


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 20, 2009 at 5:38 PM
Learning ColdFusion 8: CFImage Part I - Reading And Writing Images
Hi Ben, Great article. I've been looking around to see if ColdFusion image engine can programatically create the following "wrap around" effect: http://www.creativepro.com/article/photoshop-s-she ... read »
Nov 20, 2009 at 5:35 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Dave: I talked to Gert he suggested: <cfhttp method="get" url="http://{some cf website}" result="stuff" addtoken="yes" /> Note the addition of cfhttp attribute addtoken. That should persist y ... read »
Nov 20, 2009 at 5:23 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Todd, Ahh, gotcha, yeah that makes sense. ... read »
Nov 20, 2009 at 5:17 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
Ben, sorry if I didn't make this clear. You can make it work like that if you want, just put <cfset session.foo = 1> (and <cfset application.foo = 1>) in your OnRequestStart() and it reve ... read »
Nov 20, 2009 at 5:07 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Todd, I have seen tidbits about the way Railo handles session. I can understand that it lazy-loads sessions, but I also think that I might make some things more complicated. For example, often tim ... read »
Nov 20, 2009 at 4:53 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
Ben, you can ramp up the security by turning on J2EE session which gives you a third set of numbers other than CFID/CFTOKEN. There's a reason why ACF put this in place (other than just session replic ... read »
Nov 20, 2009 at 4:52 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
Case in point, Ben, you may not be aware of this, but in Railo - OnApplicationStart() & OnSessionStart() act differently than in ACF. ACF does: OnApplicationStart (1st hit) OnSessionStart (1st and e ... read »
Nov 20, 2009 at 4:46 PM
Maintaining ColdFusion Sessions Across SMS Text Message Requests Without Cookies
@Todd, That's understandable. I am not sure if this really leaves any more security holes than the fact that using old cookie-based CFID / CFTOKEN values will create a new session using the old CFI ... read »