Because the web is a stateless system, each connection that a browser makes to a web server is unique to the web server. However, many applications must keep track of users as they move through the pages within the application. This is the definition of client state management.
ColdFusion provides tools to maintain the client state by seamlessly tracking variables associated with a browser as the user moves from page to page within the application. You can use these variables in place of other methods for tracking client state, such as URL parameters, hidden form fields, and HTTP cookies.
ColdFusion provides two tools for managing the client state: client variables and session variables. Both types of variables are associated with a specific client, but you manage and use them differently, as described in the following table:
Session variables are normally better than client variables for values that need to exist for only a single browser session. You should reserve client variables for client-specific data, such as client preferences that you want available for multiple browser sessions.
Because the web is a stateless system, client management requires some method for maintaining knowledge of the client between requests. Normally you do this using cookies, but you can also do it by passing information between application pages. The following sections describe how ColdFusion maintains client identity in a variety of configurations and environments, and discuss issues that can arise with client state management.
To use client and session variables, ColdFusion must be able to identify the client. It normally does so by setting the following two cookie values on the client's system:
CFID
A sequential client identifier
CFToken
A random-number client security tokenThese cookies uniquely identify the client to ColdFusion, which also maintains copies of the variables as part of the Session and Client scopes. You can configure your application so that it does not use client cookies, but in this case, you must pass these variables to all the pages that your application calls. For more information about maintaining client and session information without using cookies, see "Using client and session variables without cookies".
You can configure ColdFusion MX to use J2EE servlet session management instead of ColdFusion session management for session variables. This method of session management does not use CFID
and CFToken
values, but does use a client-side jsessionid
session management cookie. For more information on using J2EE session management, see "ColdFusion and J2EE session management".
Often, users disable cookies in their browsers. In this case, ColdFusion cannot maintain the client state automatically. You can use client or session variables without using cookies, by passing the client identification information between application pages. However, this technique has significant limitations, as follows:
Because the client's system does not retain any identification information, the next time the user logs on, ColdFusion cannot identify the user with the previous client and must create a new client ID for the user. Any information about the user from a previous session is not available, but remains in client data storage until ColdFusion deletes it. If you clear the Purge Data for Clients that Remain Unvisited option in the ColdFusion MX Administrator, ColdFusion never deletes this data.
Therefore, do not use client variables, if you do not require users to enable cookies. To retain client information without cookies, require users to login with a unique ID. You can then save user-specific information in a database with the user's ID as a key.
Note: You can prevent ColdFusion from sending client information to the browser as cookies by setting the setClientCookies
attribute of the cfapplication
tag to No.
To use ColdFusion client or session variables without using cookies, each page must pass the CFID
and CFToken
values to any page that it calls as part of the request URL. If a page contains any HTML href
a=
links, cflocation
tags, form
tags, or cfform
tags the tags must pass the CFID
and CFToken
values in the tag URL. To use J2EE session management, you must pass the jsessionid
value in page requests. To use ColdFusion client variables and J2EE session variables, you must pass the CFID
, CFToken
, and jsessionid
values in URLs.
ColdFusion provides the URLSessionFormat
function, which does the following:
The URLSessionFormat
function automatically determines which identifiers are required, and sends only the required information. It also provides a more secure and robust method for supporting client identification than manually encoding the information in each URL, because it only sends the information that is required, when it is required, and it is easier to code.
To use the URLSessionFormat
function, enclose the request URL in the function. For example, the following cfform
tag posts a request to another page and sends the client identification, if required:
<cfform method="Post" action="#URLSessionFormat("MyActionPage.cfm")#>
Tip: If you use the same page URL in multiple URLSessionFormat
functions, you can gain a small performance improvement and simplify your code if you assign the formatted page URL to a variable, for example:
<cfset myEncodedURL=URLSessionFormat(MyActionPage.cfm)>
<cfform method="Post" action="#myEncodedURL#">
The following client identifier issues can have security implications:
CFToken
identifier
The next sections discuss these issues.
By default, ColdFusion uses an eight-digit random number in the CFToken
identifier. This CFToken
format provides a unique, secure identifier for users under most circumstances. (In ColdFusion MX, the method for generating this number uses a cryptographic-strength random number generator that is seeded only when the server starts.)
However, in the ColdFusion MX Administrator, you can enable the Settings page to produce a more complex CFToken
identifier. If you enable the Use UUID for cftoken option, ColdFusion creates the CFToken
value by prepending a 16-digit random hexadecimal number to a ColdFusion UUID. The resulting CFToken
identifier looks similar to the following:
3ee6c307a7278c7b-5278BEA6-1030-C351-3E33390F2EAD02B9
ColdFusion uses the same client identifiers for the Client scope and the standard Session scope. Because the CFToken
and CFID
values are used to identify a client over a period of time, they are normally saved as cookies on the user's browser. These cookies persist until the client's browser deletes them, which can be a considerable length of time. As a result, hackers could have more access to these variables than if ColdFusion used different user identifiers for each session.
A hacker who has the user's CFToken
and CFID
cookies could gain access to user data by accessing a web page during the user's session using the stolen CFToken
and CFID
cookies. While this scenario is unlikely, it is theoretically possible.
You can remove this vulnerability by selecting the Use J2EE Session Variables option on the ColdFusion Administrator Memory Variables page. The J2EE session management mechanism creates a new session identifier for each session, and does not use either the CFToken
or the CFID
cookie value.
To maintain your application's client identity information in a clustered server environment, you must specify the cfapplication
setdomaincookies
attribute in your Application.cfm page.
The setdomaincookies
attribute specifies that the server-side copies of the CFID
and CFToken
variables used to identify the client to ColdFusion are stored at the domain level (for example, .macromedia.com). If CFID
and CFToken
variable combinations already exist on each host in the cluster, ColdFusion migrates the host-level variables on each cluster member to the single, common domain-level variable. Following the setting or migration of host-level cookie variables to domain-level variables, ColdFusion creates a new cookie variable (CFMagic
) that tells ColdFusion that domain-level cookies have been set.
If you use client variables in a clustered system, you must also use a database or cookies to store the variables.