Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why setting object as cookie value get modified #2815

Closed
JSteunou opened this issue Nov 24, 2015 · 5 comments
Closed

Why setting object as cookie value get modified #2815

JSteunou opened this issue Nov 24, 2015 · 5 comments
Assignees

Comments

@JSteunou
Copy link

I see my cookie value with a {j: original} wrapped around my original value. Why is that? Is this from some RFC?

@dougwilson
Copy link
Contributor

Hi! It's not part of any standard, as the RFC for cookies says the value can only be a string. Ideally if we followed the standard, we would reject your cookie if it wasn't a string. As a convenience, Express.js allows you to set non-strings as the values, and we'll JSON.stringify the value, pre-pending a j: so we know the value should be JSON.parsed when we read it again for you.

If you do not want this behavior, simply provide a string as the cookie's value and we won't touch it.

@JSteunou
Copy link
Author

That's what I though but I needed confirmation. Thank you @dougwilson

@dougwilson
Copy link
Contributor

No problem!

@neverendingqs
Copy link

neverendingqs commented Nov 13, 2016

Hi @dougwilson,

(Disclaimer: I don't know the difference between an unsigned cookie and a signed cookie).

I noticed signed tokens get a s: appended prepended:

val = 's:' + sign(val, secret);

I'm interested in your thoughts on this as at this point in the code, the cookie value is already a string, so the RFC reason for j: can't be applied here.

Thanks.

@dougwilson
Copy link
Contributor

dougwilson commented Nov 13, 2016

Hi @neverendingqs , please try and open new issues, rather than resurrecting old, closed issues :) disclaimer: the decision to prepend (not append) the s: was before I worked on Express, so my only good answer is "that's just how it is", but I know that's not a great answer, but I don't have the insight to the decisions before I was involved.

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

No branches or pull requests

3 participants