Skip to content

ColdFusion / Tomcat RFC 6265 (Parentheses truncation) #49

@JamoCA

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions