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

Cookie values incorrectly parsed #85

Closed
Cyrelc opened this issue Oct 6, 2022 · 4 comments
Closed

Cookie values incorrectly parsed #85

Cyrelc opened this issue Oct 6, 2022 · 4 comments

Comments

@Cyrelc
Copy link

Cyrelc commented Oct 6, 2022

Describe the bug
Cookie values are not correctly parsed

To Reproduce
Steps to reproduce the behavior:
Hit any backend that provides a CSRF or XSRF token including data such as an expiry date

Expected behavior
The key is parsed correctly, but the value grabs the entire string, including "Set-Cookie"... it should only grab the string after the key name

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows11
  • Browser N/A
  • Version ^4.7.0
@sehnryr sehnryr added bug Something isn't working and removed bug Something isn't working labels Oct 6, 2022
@sehnryr
Copy link
Collaborator

sehnryr commented Oct 6, 2022

Hi, actually it's that's not a bug. The value you're printing is the result of the implicit method toString() (that outputs you the Set-Cookie header) you're doing when casting the value in the string.
CookieJar stores Cookie with its name as the key. What you should do instead to get the value of the cookie would be:

storedCookies.forEach((key, cookie) => {
	var value = cookie.value; // then do what you want with the value
});

@sehnryr
Copy link
Collaborator

sehnryr commented Oct 6, 2022

Hit any backend that provides a CSRF or XSRF token including data such as an expiry date

Would that mean when you print another cookie it just gives you the value and not the header ?

@Cyrelc
Copy link
Author

Cyrelc commented Oct 6, 2022

Ah you are correct, thank you I was concerned it was sending the entire string back as part of the header.

Laravel provides a new CSRF token with each request, they are constantly rotating, so I was looking for a package like yours that will keep them up to date, but haven't quite got it working yet. So far it seems like a good package, thank you for the effort

@sehnryr sehnryr closed this as completed Oct 6, 2022
@sehnryr
Copy link
Collaborator

sehnryr commented Oct 6, 2022

Laravel provides a new CSRF token with each request, they are constantly rotating, so I was looking for a package like yours that will keep them up to date, but haven't quite got it working yet.

I don't think there should be any issue with that, Requests must overwrite the cookie if the name is the same since the Map.addAll method does so.

storedCookies.addAll(responseCookies);

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

No branches or pull requests

2 participants