SlideShare a Scribd company logo
CFMLSessionsfor
Dummies
EricPeterson
Whatthistalkisn't
!
· Live coding
· Outlining best practices
· For people who use sessions and either already
know or don't care that much how they work
Whatthistalkis
!
· Theory — definitions and examples
· Understanding the what and the why rather
than the when would I use this
· For people who use sessions and don't know
how they work
OtherSessionsRightNow
· PostCSS: A Dumb Name For An Awesome Thing
Room 238
· SQL Server Tips For Everyday Programmers
Room 334
· Crash Course In Ionic & AngularJS
Auditorium
WhoamI?
EricPeterson
! Utah
" O.C. Tanner
# 1 wife, 1 kid
Whatisasession?
Disclaimer:
Out of the box setup
(Other setups later)
Whatisasession?
· Data stored in memory on the server
· Client variables used to access the data on the
server
Datastoredinmemoryon
theserver
Datastoredinmemoryontheserver
· Data is lost when not accessed within a time-out
period
· Data is available only to a single client and
application
· Any CFML data type can be stored
Datastoredinmemoryontheserver
Data is accessed by using a combination of a CFID
and a CFTOKEN
· CFID: A sequential client identifier
· CFTOKEN: A random client security token
Whatdoyougetinthesessionscopebydefault?
Andanydatayouaddyourself!
session.simpleValue = 5;
session.complexValue = [
{ id = 1, permissions = [/* ... */] }
];
session.user = new User(/* ... */);
OtherFacts
· CFID and CFTOKEN are reused by the client
when starting new sessions (if possible)
· Someone with your CFID and CFTOKEN could
access your session
· For this, reason it's bad to pass it in the query
string. Use Client Variables instead
Clientvariablesusedto
accessthedataonthe
server
ClientVariables=Cookies
DefaultCookiesstoredwhenusingSessions
Clientvariablesusedtoaccessthedataontheserver
If you didn't use cookies, you'd have to pass
these values in the url or form every time
Which makes them very easy to steal and hijack a
session
Sodon'tdothat!
!
EnablingSessionsin
yourCFMLApplications
EnablingSessionsinyourCFMLApplications
component {
// Required
this.name = 'MyAwesomeApp';
this.sessionManagement = true;
// Optional: default timeout is 20 minutes
this.sessionTimeout = createTimeSpan(0, 0, 45, 0);
}
SessionLifecycle
Whatstartsasession?
Ausercomingtoyour
website
DuringaSession
ReadingandWritingtotheSession
// write values to the session
session.favorites = [1, 45, 67, 109];
// read values from the session
local.favorites = session.favorites;
// though, it is smart to check that
// the value exists first.
if (structKeyExists(session, 'favorites')) {
local.favorites = session.favorites;
} else {
local.favorites = [];
}
SessionLocks
SessionLocks
function getProductCount() {
lock scope="session" type="read" timeout="2" throwontimeout="true" {
return session.items;
}
}
function incrementProductCount(count) {
lock scope="session" type="exclusive" timeout="2" throwontimeout="true" {
session.items += count;
}
}
Whendoyouusesessionlocks?
Race Conditions
SessionRotate()
Available in ACF10+ and Lucee 4.5+
1. Invalidates the current session
2. Creates a new session
3. Migrates the data from the old to the new
4. Overwrites the old cookies with the new
"BestPractices"
· Keep your session scope small
· Only store lookup values in your session scope
(like userId)
· Especially avoid storing values shared between
users in the session scope
· SessionRotate() a!er a successful login1
1
See Learn CF in a Week for more session security tips
EndingaSession
Whatdoesnotendasession?
· Logging out
· Closing the browser
· structClear(session)
Whatdoesendasession?
· Session Timeout
· sessionInvalidate()
(ACF10+ and Lucee 4.5+)
SessionLifecycleMethods
function onSessionStart() {
// set defaults for session values
// you want to make sure are available
session.sessionStartedAt = Now();
}
function onSessionEnd(applicationScope, sessionScope) {
if (sessionScope.isShopping) {
// clean up any long standing objects
// Log any important messages
applicationScope.shoppingInsightLogger.info(
'User timed out while shopping at #Now()#'
);
}
}
J2EESessions
J2EESessions
· Uses the servlet (e.g. Tomcat) for session
management
· Share session information between ColdFusion
and other servlet applications
J2EESessions
· Does not reuse the session identifiers
· Generates a new identifier for each session,
reducing the impact of the the! of the token
· Can terminate the session manually
getPageContext().getSession().invalidate();
ColdFusionSessionsvs.J2EE
Sessions
Whichshouldyouuse?
Storingyoursessiondata
elsewhere
(Notinmemoryontheserver)
Firstoff,
Why?
ServerClusters
ServerClusters
If your session information is being stored in the
memory of a server,
then only that one server can handle all your
requests.
In other words, you can't scale.
Whatareouroptions?
· Don't use the session scope
!
· Store the session scope somewhere else
"
TheHardWay:
ManualSessionManagement
Doityourself!
function onRequestStart() {
var urlToken = 'CFID=' & cookie.cfid & '&CFTOKEN=' & cookie.cftoken;
var sessionClient = new cfcouchbase.CouchbaseClient({
bucketName = 'sessions'
});
StructAppend(
session,
sessionClient.get(id = urlToken, deserialize = true),
true
);
}
function onRequestEnd() {
var urlToken = 'CFID=' & cookie.cfid & '&CFTOKEN=' & cookie.cftoken;
var sessionClient = new cfcouchbase.CouchbaseClient({
bucketName = 'sessions'
});
sessionClient.set(id = urlToken, session );
}
OneEasyWay:
SessionStorages
(Requires ColdFusion 2016+ or Lucee 4.5+)
Done
AnotherEasyWay:
J2EESessions
Sticky sessions at the servlet level
Done
Extras
First,SessionFixation
An attacker provides the session identifiers in
order to try and know them
<a href="http://a-legitimate-site.com/?CFID=b1c8-30f3469ba7f7&CFTOKEN=2">
Click here for free stuff!
</a>
HowthiscancauseSessionLoss
More than one CFML application on
the same domain2
2
Pete Freitag, Session Loss and Session Fixation in ColdFusion, March 01, 2013
HTTPOnlyCookies
· These cookies are only available over HTTP
connections, NOT Javascript
HTTPOnlyCookies
Set once for the entire application
// CF 10+ & Lucee 4.5+
this.sessioncookie.httponly = true;
# Java JVM args (CF 9.0.1+)
-Dcoldfusion.sessioncookie.httponly=true
HTTPOnlyCookies
OR set them manually
<!-- CF 9+ & Lucee 4.5+ -->
<cfcookie name="CFID" value="#sessoin.cfid#" httponly="true" />
<!-- CF 8 and lower -->
<cfheader name="Set-Cookie" value="CFID=#session.cfid#;path=/;HTTPOnly" />
SSL
Enable the secure flag on your cookies
// CF 10+ & Lucee 4.5+
this.sessioncookie.secure = true;
<!-- CF 9+ & Lucee 4.5+ -->
<cfcookie name="CFID" value="#sessoin.cfid#" httponly="true" secure="true" />
<!-- CF 8 and lower -->
<cfheader name="Set-Cookie" value="CFID=#session.cfid#;path=/;HTTPOnly;secure" />
Turningoffclientmanagement
If you are setting your own cookies,
remember to turn off client management
// Application.cfc
component {
this.clientmanagement = false;
}
Questions
!
Other talks at dev.Objective()
LiveTestingaLegacyApp
Thursday
1:45 PM to 2:45 PM
ThankYou!!
elpete
@_elpete
! dev.elpete.com

More Related Content

PPTX
My Database Skills Killed the Server
PDF
Developing High Performance and Scalable ColdFusion Application Using Terraco...
PDF
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
PPT
Roy foubister (hosting high traffic sites on a tight budget)
PDF
Realtime with-websockets-2015
PDF
Super Fast Application development with Mura CMS
PDF
10 common cf server challenges
PDF
Keep Applications Online
My Database Skills Killed the Server
Developing High Performance and Scalable ColdFusion Application Using Terraco...
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
Roy foubister (hosting high traffic sites on a tight budget)
Realtime with-websockets-2015
Super Fast Application development with Mura CMS
10 common cf server challenges
Keep Applications Online

What's hot (20)

PDF
Locking Down CF Servers
PPTX
Introduction to vSphere APIs Using pyVmomi
ODP
The secret life of a dispatcher (Adobe CQ AEM)
PDF
Instant ColdFusion with Vagrant
PDF
10 things every developer should know about their database to run word press ...
PDF
Aem dispatcher – tips & tricks
PPTX
Accelerate your ColdFusion Applications using Caching
PDF
Scaling WordPress
ODP
Choosing a Web Architecture for Perl
PPTX
Adobe CQ5 for Developers - Introduction
PPTX
cache concepts and varnish-cache
PPTX
Performance all teh things
PPTX
Anthony Somerset - Site Speed = Success!
PDF
Modern PHP Ch7 Provisioning Guide 導讀
PPTX
Drupal, varnish, esi - Toulouse November 2
PDF
Realtime with websockets
PDF
Automatic testing and quality assurance for WordPress plugins and themes
PDF
Less and faster – Cache tips for WordPress developers
PDF
Redundancy Rocks. Redundancy Rocks.
PDF
Use Xdebug to profile PHP
Locking Down CF Servers
Introduction to vSphere APIs Using pyVmomi
The secret life of a dispatcher (Adobe CQ AEM)
Instant ColdFusion with Vagrant
10 things every developer should know about their database to run word press ...
Aem dispatcher – tips & tricks
Accelerate your ColdFusion Applications using Caching
Scaling WordPress
Choosing a Web Architecture for Perl
Adobe CQ5 for Developers - Introduction
cache concepts and varnish-cache
Performance all teh things
Anthony Somerset - Site Speed = Success!
Modern PHP Ch7 Provisioning Guide 導讀
Drupal, varnish, esi - Toulouse November 2
Realtime with websockets
Automatic testing and quality assurance for WordPress plugins and themes
Less and faster – Cache tips for WordPress developers
Redundancy Rocks. Redundancy Rocks.
Use Xdebug to profile PHP
Ad

Viewers also liked (20)

PDF
Locking Down CF Servers
PDF
Java scriptconfusingbits
PDF
PPTX
Intro to JavaScript Tooling in Visual Studio Code
PPTX
2014 cf summit_clustering
PDF
This is how we REST
PPTX
ColdFusion builder 3 making the awesome
PDF
Bring Order to the Chaos: Take the MVC Plunge
PDF
Automate all the things
PDF
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
PDF
Dependency injectionpreso
PPTX
Load Balancing, Failover and Scalability with ColdFusion
PDF
Hidden gems in cf2016
PDF
Fr sponsor talk may 2015
PDF
Refactoring your legacy app to a MVC framework
PDF
Node withoutservers aws-lambda
PDF
Expand Your ColdFusion App Power with AWS
PDF
Dependency Injection Why is it awesome and Why should I care?
PDF
Dev objective2015 lets git together
PDF
Multiply like rabbits with rabbit mq
Locking Down CF Servers
Java scriptconfusingbits
Intro to JavaScript Tooling in Visual Studio Code
2014 cf summit_clustering
This is how we REST
ColdFusion builder 3 making the awesome
Bring Order to the Chaos: Take the MVC Plunge
Automate all the things
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
Dependency injectionpreso
Load Balancing, Failover and Scalability with ColdFusion
Hidden gems in cf2016
Fr sponsor talk may 2015
Refactoring your legacy app to a MVC framework
Node withoutservers aws-lambda
Expand Your ColdFusion App Power with AWS
Dependency Injection Why is it awesome and Why should I care?
Dev objective2015 lets git together
Multiply like rabbits with rabbit mq
Ad

Similar to CFML Sessions For Dummies (20)

PDF
Top5 scalabilityissues
PPTX
Using cookies and sessions
PPTX
PPTX
PPT
Php 07-cookies-sessions
PDF
Client Side Secure Storage
ODP
PHP Sessions and Non-Sessions
PDF
Architecting for scalability in cf
PPT
Session and state management
PPTX
Sessions&cookies
PPT
Sa204 W Cfmx7 Application Framework Camden
PPT
Lecture8 php page control by okello erick
PPTX
2.session management
PDF
Top5 scalabilityissues withappendix
PPTX
Caching & Performance In Cold Fusion
PDF
Maximize your Cache for No Cash
PPT
Session,cookies
PPT
PHP - Introduction to PHP Cookies and Sessions
PDF
WEB MODULE 5.pdf
Top5 scalabilityissues
Using cookies and sessions
Php 07-cookies-sessions
Client Side Secure Storage
PHP Sessions and Non-Sessions
Architecting for scalability in cf
Session and state management
Sessions&cookies
Sa204 W Cfmx7 Application Framework Camden
Lecture8 php page control by okello erick
2.session management
Top5 scalabilityissues withappendix
Caching & Performance In Cold Fusion
Maximize your Cache for No Cash
Session,cookies
PHP - Introduction to PHP Cookies and Sessions
WEB MODULE 5.pdf

More from ColdFusionConference (20)

PDF
Api manager preconference
PDF
PDF
Building better SQL Server Databases
PDF
API Economy, Realizing the Business Value of APIs
PDF
Don't just pdf, Smart PDF
PDF
Crafting ColdFusion Applications like an Architect
PDF
Security And Access Control For APIS using CF API Manager
PDF
Monetizing Business Models: ColdFusion and APIS
PDF
Become a Security Rockstar with ColdFusion 2016
PDF
ColdFusion in Transit action
PDF
Developer Insights for Application Upgrade to ColdFusion 2016
PDF
Where is cold fusion headed
PDF
ColdFusion Keynote: Building the Agile Web Since 1995
PPT
Restful services with ColdFusion
PDF
Build your own secure and real-time dashboard for mobile and web
PDF
Why Everyone else writes bad code
PDF
Securing applications
PDF
Testing automaton
PDF
Rest ful tools for lazy experts
PDF
Herding cats managing ColdFusion servers with commandbox
Api manager preconference
Building better SQL Server Databases
API Economy, Realizing the Business Value of APIs
Don't just pdf, Smart PDF
Crafting ColdFusion Applications like an Architect
Security And Access Control For APIS using CF API Manager
Monetizing Business Models: ColdFusion and APIS
Become a Security Rockstar with ColdFusion 2016
ColdFusion in Transit action
Developer Insights for Application Upgrade to ColdFusion 2016
Where is cold fusion headed
ColdFusion Keynote: Building the Agile Web Since 1995
Restful services with ColdFusion
Build your own secure and real-time dashboard for mobile and web
Why Everyone else writes bad code
Securing applications
Testing automaton
Rest ful tools for lazy experts
Herding cats managing ColdFusion servers with commandbox

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation theory and applications.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Monthly Chronicles - July 2025
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx

CFML Sessions For Dummies