capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.08k stars 185 forks source link

CookieContainer cache key issue #1455

Closed matcic closed 2 weeks ago

matcic commented 3 weeks ago

Describe the bug

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

I believe the following should be used instead:

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:

matcic commented 3 weeks ago

I just created https://github.com/capricorn86/happy-dom/pull/1456 to fix this, please let me know if it looks good.