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

Sometimes $cookies.set is not consistent with document.cookie= #66

Open
lifubang opened this issue Dec 16, 2020 · 5 comments · May be fixed by #67
Open

Sometimes $cookies.set is not consistent with document.cookie= #66

lifubang opened this issue Dec 16, 2020 · 5 comments · May be fixed by #67

Comments

@lifubang
Copy link

When we use document.cookie='email=lifubang@acmcoder.com', the value of document.cookie is email=lifubang@acmcoder.com;
But when we use this.$cookies.set('email', 'lifubang@acmcoder.com'), the value of document.cookie is email=lifubang%40acmcoder.com.

It's ok when we just use cookie in front-end, but the back-end will get an inconsistent cookie value when we use vue-cookies to replace document.cookie= in front-end, it would cause the back-end to upgrade their code.

@lifubang lifubang changed the title $cookies.set is not consistent with document.cookie= Sometimes $cookies.set is not consistent with document.cookie= Dec 16, 2020
@cmp-cc
Copy link
Owner

cmp-cc commented Dec 17, 2020

The cookie value string can use encodeURIComponent() to ensure that the string does not contain any commas, semicolons, or whitespace (which are disallowed in cookie values).

encodeURIComponent/decodeURIComponent escape sequences (e.g. comma, quotes, [], : , ; etc)

back-end transcoding

Java Example:

URLDecoder.decode("lifubang%40acmcoder.com", "utf-8");

PHP Example:

urldecode("lifubang%40acmcoder.com")

@lifubang
Copy link
Author

The cookie value string can use encodeURIComponent() to ensure that the string does not contain any commas, semicolons, or whitespace (which are disallowed in cookie values).

I think the operation document.cookie=*** will handle these cases by itself. You can try it in chrome console window.

back-end transcoding

Yes, back-end can decode it correctly. My thought is that we should not force the back-end to change the code when I use vue-cookies to replace document.cookie=.

@Connor1st
Copy link

I agree with @lifubang in that I am having issues with this as well.

I don't mind if the value is encoded in the cookie storage, but the decode does not work for me when I get cookies back.
When I use Vue.$cookies.get() it returns the escaped strings for me, so the functionality is ruined.

My understanding is that the cookie stores a standard string and handles all required escaping itself as well.

@lifubang
Copy link
Author

but the decode does not work for me when I get cookies back

Yes, we may hit this issues when we read the cookie created by the back-end.
So I update the commit of the #67 .

@liuyang92
Copy link

当cookie含有 ASCII 特殊符号时,encodeURIComponent会对key or value 进行编码,这样会导致接下来的请求后端cookies校验无法通过,希望不要对@&=+$#这些特殊符号进行编译。

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

Successfully merging a pull request may close this issue.

4 participants