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

CookieContainer cache key issue #1455

Closed
matcic opened this issue Jun 10, 2024 · 1 comment · Fixed by #1456
Closed

CookieContainer cache key issue #1455

matcic opened this issue Jun 10, 2024 · 1 comment · Fixed by #1456
Labels
bug Something isn't working

Comments

@matcic
Copy link
Contributor

matcic commented Jun 10, 2024

Describe the bug

The CookieContainer class currently caches a cookie based on the following info:

  • cookie.key
  • cookie.originURL.hostname
  • cookie.originURL.pathname
  • typeof cookie.value

I believe the following should be used instead:

  • cookie.key
  • cookie.originURL.hostname
  • cookie.path
  • typeof cookie.value

To Reproduce
Steps to reproduce the behavior:

  1. Send a fetch request to an endpoint that sets a cookie, e.g. api/signUp
  2. The cookie is cached under the following key: <cookie-name>-<hostname>-/api/signUp-string
  3. Send a fetch request to an endpoint that clears the aforementioned cookie, e.g. api/signOut
  4. The original cookie (i.e. <cookie-name>-<hostname>-/api/signUp-string) is invalidated on the server but still not deleted by CookieContainer
  5. This is an issue when the same cookie is set by another request, e.g. api/signIn because a new cookie will be cached under <cookie-name>-<hostname>-/api/signIn-string and yet the previous expired cookie (i.e. <cookie-name>-<hostname>-/api/signUp-string) will be sent in following requests to the same domain instead of the newer <cookie-name>-<hostname>-/api/signIn-string

Expected behavior
Cookies should be cached based on the following info:

  • cookie.key
  • cookie.originURL.hostname
  • cookie.path
  • typeof cookie.value
@matcic matcic added the bug Something isn't working label Jun 10, 2024
matcic added a commit to matcic/happy-dom that referenced this issue Jun 10, 2024

Verified

This commit was signed with the committer’s verified signature.
matcic Matteo Ciccone
@matcic
Copy link
Contributor Author

matcic commented Jun 10, 2024

I just created #1456 to fix this, please let me know if it looks good.

capricorn86 added a commit that referenced this issue Jun 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
fix: [#1455] Cookie container cache key
rexxars pushed a commit to rexxars/happy-dom that referenced this issue Jul 20, 2024

Verified

This commit was signed with the committer’s verified signature.
rexxars Espen Hovlandsdal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant