browser_cookie3 icon indicating copy to clipboard operation
browser_cookie3 copied to clipboard

Load() overwrites cookie if it exists in multiple browsers

Open Moojuiceman opened this issue 4 years ago • 3 comments

Example: JSESSION cookie exists for www.example.com in both chrome and firefox. browser_cookie3.load("www.example.com") will first get the cookie from chrome, then overwrite it with the one from firefox.

This will happen in the order the browsers are checked: chrome, chromium, opera, edge, firefox.

If you generate the cookie once in a later browser then start using any earlier one, you will end up with the older cookie no matter how many times you generate it in earlier ones. This will continue until the cookie is cleared from the later browser.

Possible solutions:

  • Check the expiration time for the cookie in the current loop and only overwrite if it is later than the existing cookie.
  • Provide both cookies and allow caller to pick the one they want (may not be possible while using stdlib cookiejar methods).
  • Change nothing, but warn about this behaviour for the method so caller can decide to implement their own multi-browser loop order

Moojuiceman avatar Apr 19 '21 20:04 Moojuiceman

i'm not of developer of this code, but an cast some light about your suggestions. first 3rd solution: its easy to to do. second 1st solution: its easy to do too, but will have same problem if you use multi accounts cross browsers, for example if you used account A in firefox and account B in chrome and both of theirs cookies did not expire it will always return account A as load() use loop in which chrome is first of the list and firefox is last so if cookie exist in firefox (and implying this solution is valid) it will return firefox cookie lastly 2nd solution: this is very hard if not impossible, because this code return the cookies in default python urllib2 (the base that other module use to connect to internet like requests) format aka cookiejar methods, which use domain name as key, so the best solution is to create variable for browser that you want (firefo_cookies, chrome_cookies...etc) then chose the variable that you want.

alzamer2 avatar Apr 26 '21 06:04 alzamer2

i was doing some test and found out that even 1st solution is hard (not very hard) because cookies don't expire at same time (for example cloudflare cookies expire super fast) and some sensitive (like auth cookies) can become invalid if use use cookies from multi browser (something to do with useragent)

and as i mentioned in other post its better to use multi variable as cloudflare cookies will be invalid if you used wroung user agent (like using chrome useragent with firefox cloudflare cookies)

alzamer2 avatar Apr 26 '21 06:04 alzamer2

I am experiencing the same problem.

How about modifying load() (or adding a new method like load_all() or something) that returns a dictionary of cookie jars? One entry per browser for which it could find cookies.

That would make it easier for the user to iterate through the cookies of different browsers.

elnigno avatar Mar 14 '23 09:03 elnigno