Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

cookie created with { path : '/' } is still only valid for the creation page #40

Closed
phtrivier opened this issue Dec 9, 2011 · 5 comments

Comments

@phtrivier
Copy link

Hi !

I know this is a FAQ, and it's explained in the documentation that if you want a cookie to be valid on the whole site, it needs to be created with something like

$.cookies("foo", "bar", {
path : "/"
});

I'm in a situation where the cookie is created in a login page, where the user is redirected when they try to access a page like "/foo/bar/baz". But I want the cookie to be valid on all pages, so I obviously create it with the "path" : "/" options.

For some reason, when I open the Webdevelopper "View cookie information pane" in FF8, or when I use the settings screen to look at cookie details in Chrome, the cookie is displayed with a path like "foo/bar" (typically, the parent of the page I tried to access). So obvioulsy if I navigate to another page, the browser does not send the cookie.

I debugged the source of the plugin, and as far as I can tell the call
"""javascript
document.cookie = name + '=' + encodeURIComponent(value) + expires + path + domain + secure;
"""
is done with path being "; /", which is what I expect, isn't it ?

I have absolutely no clue as to what can be messing up with the cookies on the client side ; is there any thing I can have a look at ? Could the server somehow modifiy the cookie, so that on a subsequent request the browser feel the need to modify its 'path' ?

Any help welcome.

@phtrivier
Copy link
Author

Note that when I use the docCookies library from MDN https://developer.mozilla.org/en/DOM/document.cookie I can finaly get a site-wide cookie ... but they seem to call document.cookie in a slightly different ; is it FF specific ?

document.cookie = escape(sKey) + "=" + escape(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");  

@carhartl
Copy link
Owner

escape is deprecated in favor of decodeURIComponent. Will look into this.

@jessegavin
Copy link

This issue is affecting me as well.

@miccek
Copy link

miccek commented Sep 13, 2012

up

@carhartl
Copy link
Owner

Test showed for me it's working on Firefox 18 (that is quite some versions ahead). Maybe the issue occured because with the older version of the plugin you seem to have been using the name wasn't yet correctly encoded and Firefox borked on the name:

document.cookie = name + '=' + encodeURIComponent(value) + ...

Please everyone let me know if the issue still occurs with an up-to-date version of the plugin and I'm going to reopen.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants