Skip to main content
Participant
December 16, 2011
Question

httponly cookie

  • December 16, 2011
  • 3 replies
  • 5075 views

Hi,

I am working in CF7 verison and using application.cfm. I want to make cookie secure by enabling httponly to true. There is no option for httpnonly available for cfcookie in CF7, so I am using cfheader.

When using cfheader in application.cfm for enabling httponly,session ID - CFID&CFTOKEN creates for each and every page while navigating. My problem is unable to handle the session tracking for each and every page while doing navigation. I do not want to send the cfid and cftoken in URL parameter for security reason

Below code is using for my applicaion, and I followed all the instruction but no use.

 

<cfapplication  clientmanagement="Yes" sessionmanagement="Yes" name="bsnew" setclientcookies="no" scriptprotect="All">

<cfif NOT IsDefined("cookie.cfid") >
  <cfif isDefined("CGI.HTTPS") AND CGI.HTTPS EQ "on">
     <cfheader name="Set-Cookie" value="CFID=#session.CFID#;secure;HTTPOnly" >
     <cfheader name="Set-Cookie" value="CFTOKEN=#session.CFTOKEN#;secure;HTTPOnly"  >
  <cfelse>
     <cfheader name="Set-Cookie" value="CFID=#session.CFID#;secure;HTTPOnly">
     <cfheader name="Set-Cookie" value="CFTOKEN=#session.CFTOKEN#;secure;HTTPOnly">
  </Cfif>
</cfif>



If anyone knows solution, please let me know and  it would be great help.

    This topic has been closed for replies.

    3 replies

    12Robots
    Participating Frequently
    December 20, 2011

    Remove the word "secure" for any of your CFHEADER values. Unless you are running on an SSL connection (which I am suspecting you are not) then *exactly* what you are describing will happen.

    When you have the word "secure" in the SET-COOKIE header it sets the cookie as a SECURE cookie. This means the browser will NOT send the cookie to the server unless it is over an SSL connection.

    Jason

    cfveeraAuthor
    Participant
    December 21, 2011

    Jason,

    I tried with your suggestion and it is working fine in dev environment. Whereas QA and PROD environment, we are using HTTPS connection. Will it work if remove "secure" word in QA and PROD or need to add "secure" word in CFHEADER. Please clarify me in this.

    thanks for your post.

    veera

    BKBK
    Community Expert
    Community Expert
    December 21, 2011

    cfveera wrote:

    Jason,

    I tried with your suggestion and it is working fine in dev environment. Whereas QA and PROD environment, we are using HTTPS connection. Will it work if remove "secure" word in QA and PROD or need to add "secure" word in CFHEADER. Please clarify me in this.

    Do you mean the last example I gave does not work on QA and PROD?

    Community Expert
    December 16, 2011

    I recommend that you use JSESSIONID instead of CFID and CFTOKEN by enabling J2EE session management in the CF Administrator. Then, do this:

    http://www.12robots.com/index.cfm/2009/5/6/Making-the-JSESSIONID-Session-Token-Cookie-SECURE-and-HTTPOnly-and-settings-its-PATH

    Dave Watts, CTO, Fig Leaf Software

    Dave Watts, Eidolon LLC
    BKBK
    Community Expert
    Community Expert
    December 16, 2011

    4 suggestions:

    1) Make sure the name of your application file begins with capital-A, thus: Application.cfm;

    2) Define timeouts for the application and for sessions;

    3) Remove the if-condition on CGI.HTTPS, as it is unnecessary.(The code within the if-block is the same as that within the else-block);

    4) Set the cookie expiry date.

    <cfapplication  name="bsnew" applicationTimeout="#createTimespan(1,0,0,0)#" clientmanagement="Yes" sessionmanagement="Yes" sessionTimeout="#createTimespan(0,0,20,0)#" setclientcookies="no" scriptprotect="All">

    <!--- cookie set to expire 1 day later --->

    <cfset session.cookieExpiryDate=dateAdd("d", 1, now())>

    <cfif NOT (isDefined("COOKIE.CFID") AND isDefined("COOKIE.CFTOKEN"))>

        <cfheader name="Set-Cookie" value="CFID=#session.CFID#;expires=#getHttpTimeString(session.cookieExpiryDate)#;secure;HTTPOnly">

        <cfheader name="Set-Cookie" value="CFTOKEN=#session.CFTOKEN#;expires=#getHttpTimeString(session.cookieExpiryDate)#;secure;HTTPOnly">

    </cfif>

    cfveeraAuthor
    Participant
    December 20, 2011

    Dave,

    I have tried with your code but no use, same result. whenever page loads for each requests then new session id is creating so not able to maintain the session stable. I want to make cookies httponly anyways.

    Anyhow, thanks for your post......

    BKBK
    Community Expert
    Community Expert
    December 20, 2011

    Cfveera, what happened when you tried the suggestions I gave?