Tim Blair

Active Sessions Across CF Applications (15/08/2005)

A couple of weeks ago I was looking at ways of accessing all active sessions within a given CFMX application. A simple solution I came up with was of storing a reference to the individual session within an application scoped structure:

where sessionid is some variable unique to that session (e.g. user ID, jsessionid etc). The developer can then loop through the application.sessionref structure to access all session variables.

A couple of days later I spotted this post by Samual Neff on rewindlife.com which gives a way of using the underlying java of CFMX to access all sessions directly without creating a reference such as above. Another thought then came to mind - if it's possible to access all session information in this way, can you do the same for application information?

So, I had a look and indeed it is possible! By utilising the ApplicationScopeTracker object it is possible to loop through the names of all applications that are currently active on the server and retrieving the session details using Sam's method above:

Note: all this (except the reference method described first) uses the undocumented underlying java functionality of CFMX and as such may change!

Checking back to the original post by Sam that got me on to this train of thought, there were a couple of comments regarding the possibilty of accessing all applications on a given server instance and security concerns arising from this.

Thinking about it now, it does indeed seem like quite a large security threat, especially on shared servers... Just running a quick test on my local box, it is possible to modify session detail from any application returned by the getSessionCollection() method. Because a reference to the session structure is returned, it's possible to modify the code posted above to modify every session. Add the following in at the bottom of the loop (before the dump):

I don't have access to a shared host (well I do but all access details are at home!) to be able to try this out - does anyone care to try it and post results (without modifying anyone else's sessions of course!).

My guess is that enabling sandbox security and restricting the instantiation of java classes may help this but with the various "get arounds" for grabbing instances using forName() etc it may still be a way to access all session data.

Blimey, what a can of worms...

Article Archive (September '03 – '05)