browser_cookie3 icon indicating copy to clipboard operation
browser_cookie3 copied to clipboard

Access to cookie file denied on chrome>104.0.5112.102

Open zhenyahacker opened this issue 2 years ago • 22 comments

Several days ago everything worked fine, and today it broke. Seems like new Chrome update make Chrome to prevent python read cookie file. If I shut Chrome down it works fine again.

Checked on two Win10 PCs - same behavour.

Traceback (most recent call last): (my own script cut out) File "E:***.py", line 78, in parse_given_url cookie_jar = browser_cookie3.chrome(domain_name='domain.name') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\AppData\Roaming\Python\Python311\site-packages\browser_cookie3_init_.py", line 1160, in chrome return Chrome(cookie_file, domain_name, key_file).load() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\AppData\Roaming\Python\Python311\site-packages\browser_cookie3_init_.py", line 489, in load with DatabaseConnetion(self.cookie_file) as con: File "C:\Users\Username\AppData\Roaming\Python\Python311\site-packages\browser_cookie3_init.py", line 349, in enter return self.get_connection() ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Username\AppData\Roaming\Python\Python311\site-packages\browser_cookie3_init_.py", line 383, in get_connection con = method() ^^^^^^^^ File "C:\Users\Username\AppData\Roaming\Python\Python311\site-packages\browser_cookie3_init_.py", line 374, in __get_connection_legacy shutil.copyfile(self.__database_file, self.__temp_cookie_file) File "C:\Program Files\Python311\Lib\shutil.py", line 256, in copyfile with open(src, 'rb') as fsrc: ^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied: 'C:\Users\Username\AppData\Roaming\..\Local\Google\Chrome\User Data\Default\Network\Cookies'

zhenyahacker avatar Jun 09 '23 07:06 zhenyahacker

Possible duplicate of #179. Maybe the Chrome update changed something.

Having a look.

rafiibrahim8 avatar Jun 09 '23 16:06 rafiibrahim8

Can't it be used anymore?

zhaotong1121 avatar Jun 12 '23 01:06 zhaotong1121

same issue. began after latest chrome update.

omineko1 avatar Jun 12 '23 08:06 omineko1

There will be issues with the latest version of Chrome, and if the version is rolled back to 104.0.5112.102, there will be no issues

zhaotong1121 avatar Jun 12 '23 09:06 zhaotong1121

@zhaotong1121 @omineko1 Is the issue happing only on windows? I've checked on Linux, works fine there.

rafiibrahim8 avatar Jun 12 '23 09:06 rafiibrahim8

I am on windows 64 bit and I rolled chrome back to 114.0.5735.110 to get it working again

omineko1 avatar Jun 12 '23 09:06 omineko1

Can not reproduce :(.

Need help. Can anyone provide the Python version windows version etc. (as much as you can)?

rafiibrahim8 avatar Jun 12 '23 10:06 rafiibrahim8

Win10 22H2 64bit [Version 10.0.19045.2965] with all updates installed. System has the only user account. Python 3.11.2 Pip upgraded to latest version. Wheel installed. All packages installed via pip as site-packages. Chrome installed as usual using official installer and autoupdated.

zhenyahacker avatar Jun 12 '23 16:06 zhenyahacker

Edition Windows 11 Pro Version 22H2 Installed on ‎1/‎19/‎2023 OS build 22621.1702 Experience Windows Feature Experience Pack 1000.22641.1000.0 Python 3.11.2 pip 23.1.2 Chrome Version 114.0.5735.110 (Official Build) (64-bit)

It's not working on new Chrome version in windows. https://stackoverflow.com/questions/76440733/unable-to-open-cookie-file That link is the post about this issue.

So I solved this issue temporarily by following the post. It's working when I typed the command below in the target section from properties like image. --disable-features=LockProfileCookieDatabase 2023-06-12 12_00_52-Google Chrome Properties

jxchlee avatar Jun 12 '23 16:06 jxchlee

So I solved this issue temporarily by following the post. It's working when I typed the command below in the target section from properties like image. --disable-features=LockProfileCookieDatabase

@jxchlee Confirmed it works, thanks for saving my day!

Xdynix avatar Jun 13 '23 19:06 Xdynix

Is that temp solution to use "--disable-features=LockProfileCookieDatabase" the only option still for windows? Not a ideal work around since default Chrome settings still don't allow the cookie reading functionality to work right.

gameuser1982 avatar Jun 22 '23 13:06 gameuser1982

The LockProfileCookieDatabase temp flag solution will go away once Chrome decides this change is permanent :(

This thread has some more context: https://github.com/yt-dlp/yt-dlp/issues/7271#issuecomment-1584759812. On that project, there's a new PR showing using Win32 ShadowCopy API that sounds like it works even when Cookies is locked, but requires the python process to be elevated...

darthwalsh avatar Jun 25 '23 16:06 darthwalsh

Windows 10 64 python 3.7.9 chrome 114.0.5735.199

browser-cookie3 0.13.0

browser-cookie3 Unable to read cookie data from Chrome, it used to be normal。

githublyff avatar Jul 05 '23 02:07 githublyff

Hey folks, I wrote that PR for yt-dlp.. and somehow found this thread. It uses ShadowCopy and works just fine when elevated. Another way of potentially getting cookies is to read off the disk directly. Basically you would find the NTFS info for the file (including offset) and then you would read it (and i guess have similar issues for other file systems).

Unfortunately that needs elevation as well. I don't think there will be a way to get the locked file content without elevation on Windows unfortunately.

TLDR: ShadowCopy seems like the best way at the moment, but requires elevation.

csm10495 avatar Jul 06 '23 06:07 csm10495

@csm10495 Do you want to write a patch for this package too? I'll appreciate your contribution.

rafiibrahim8 avatar Jul 07 '23 01:07 rafiibrahim8

I think best bet would be for me to take the logic i wrote in yt-dlp and move it out to a simple/small lib. Probably only one function: copy_from_shadow or something like that.

Then browser_cookie3 would be able to import it. I'm a bit nervous about making that exact same change again over here and would honestly rather just have both yt-dlp and browser_cookie3 use the same lib.

That way if there are future issues its a fix in one place instead of multiple.

Would using a lib for this be ok?

csm10495 avatar Jul 07 '23 04:07 csm10495

@csm10495 Sure!

rafiibrahim8 avatar Jul 07 '23 16:07 rafiibrahim8

Sweet. I've made it really easy. https://pypi.org/project/shadowcopy/

pip install shadowcopy

Then to use it:

from shadowcopy import shadow_copy

# Internally this creates a shadow copy instance via WMI, copies the file, then deletes the shadow copy.
shadow_copy("source.txt", "destination.txt")

This will raise if not admin or if called on non-Windows.

csm10495 avatar Jul 07 '23 23:07 csm10495

Woot: https://github.com/borisbabic/browser_cookie3/pull/185

csm10495 avatar Jul 08 '23 03:07 csm10495

browser-cookie3  0.19.1
Version 116.0.5845.111
Python 3.11.4
Windows 10 22H2

At first, I had a privilege problem in the above environment, but at some point, I was able to access the cookie value without a privilege problem.

I'm using the latest version of Chrome and I still have access to the cookie value without any permission issues.

image However, if Python is not installed at all through pyinstaller and uac-admin, and if you run a packaged exe in an environment with the latest Chrome version, the above permission problems occur.

I don't really understand why it works on my computer and it doesn't work on other computers.

pgh268400 avatar Aug 24 '23 13:08 pgh268400

See https://github.com/yt-dlp/yt-dlp/issues/7271#issuecomment-1791933997 for a possible non-admin solution here!

csm10495 avatar Nov 03 '23 06:11 csm10495