Skip to content

ColdFusion / Tomcat RFC 6265 (Parentheses truncation) #49

Closed

Description

@JamoCA

I was comparing multiple JS cookie libraries and noticed that client-side generated cookies are correctly created in the browser, but ColdFusion/Tomcat servers haven't been configured for RFC 6265 compliance by default and cookie values are truncated as soon as a the first parenthesis is encountered in a string value.

ie, a(b)c in the client becomes a when read by the server.

In order to get cookie.js to function similar to ColdFusion's CFCOOKIE tag and avoid truncating data (using Tomcat), I've added the following default path setting & encoder function.

cookie.defaults.path = '/';
cookie.utils.encode = function(value){
    return encodeURIComponent(value).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
};

Are there any potential issues with the above code? (It seems to work in my client/server tests.)

NOTE: I'm posting this here in case other ColdFusion/Java developers consider using this library and encounter this issue.

Activity

  1. florian commented on Jul 4, 2019

    @florian
    Owner

    Yep, that generally looks good to me.
    I can't say anything about the specific decoding function for ColdFusion, but setting cookie.utils.encode is the way to go.
    Since your tests work, I'm assuming the exact decoding logic is also correct.

    Thanks a lot for documenting this!
    I've linked this issue in the README.

  2. JamoCA commented on May 10, 2022

    @JamoCA
    Author

    I discovered an issue... the @ symbol needs to be encoded to %40 or ColdFusion can't read it or anything after it.

    cookie.defaults.path = '/';
    cookie.utils.encode = function(value){
        return encodeURIComponent(value).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
    };
    
  3. JamoCA commented on May 10, 2022

    @JamoCA
    Author

    I audited encoding & decoding cookies values between cookie.js and Adobe ColdFusion 2016, 2018 & 2021. (I'm experiencing issues trying to test Lucee CFM at the moment, but will report back later.)

    Here's the tested encoding function for Adobe ColdFusion.

    cookie.utils.encode = function (value) {
    	return encodeURIComponent(value).replace(/%(23|24|26|2F|5E|60|7C)/g, decodeURIComponent).replace(/[\(\)]/g, escape);
    };
    

    No encoding required:

    Code Char
    %23 #
    %24 $
    %26 &
    %2F /
    %5E ^
    %60 `
    %7C |

    Encoding required:

    Code Char
    %2B +
    %3A :
    %3C <
    %3D =
    %3E >
    %3F ?
    %40 @
    %5B [
    %5D ]
    %7B {
    %7D }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions