yt-dlp: `--cookies-from-browser`: WARNING: failed to decrypt with DPAPI / ERROR: 'NoneType' object has no attribute 'decode'
DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
- I understand that I will be blocked if I intentionally remove or skip any mandatory* field
Checklist
- I’m reporting a bug unrelated to a specific site
- I’ve verified that I have updated yt-dlp to nightly or master (update instructions)
- I’ve checked that all provided URLs are playable in a browser with the same IP and same login details
- I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
- I’ve searched known issues and the bugtracker for similar issues including closed ones. DO NOT post duplicates
- I’ve read the guidelines for opening an issue
Provide a description that is worded well enough to be understood
Happens on all sites. After removing the “–cookies-from-browser chrome”, the error does not occur.
Provide verbose output that clearly demonstrates the problem
- Run your yt-dlp command with -vU flag added (
yt-dlp -vU <your command line>) - If using API, add
'verbose': TruetoYoutubeDLparams instead - Copy the WHOLE output (starting with
[debug] Command-line config) and insert it below
Complete Verbose Output
yt-dlp -vU -f 248+251 --proxy http://127.0.0.1:10809 --cookies-from-browser chrome --mark-watched https://www.youtube.com/watch?v=v9lMa4BGAuA
[debug] Command-line config: ['-vU', '-f', '248+251', '--proxy', 'http://127.0.0.1:10809', '--cookies-from-browser', 'chrome', '--mark-watched', 'https://www.youtube.com/watch?v=v9lMa4BGAuA']
[debug] Encodings: locale cp936, fs utf-8, pref cp936, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2024.08.06 from yt-dlp/yt-dlp [4d9231208] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.26120-SP0 (OpenSSL 1.1.1k 25 Mar 2021)
[debug] exe versions: ffmpeg 2023-07-19-git-efa6cec759-full_build-www.gyan.dev (setts), ffprobe 2023-07-19-git-efa6cec759-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.07.04, curl_cffi-0.5.10, mutagen-1.47.0, requests-2.32.3, sqlite3-3.35.5, urllib3-2.2.2, websockets-12.0
[debug] Proxy map: {'all': 'http://127.0.0.1:10809'}
Extracting cookies from chrome
[Cookies] Searching for "Cookies": 1 files searched
[debug] Extracting cookies from: "C:\Users\biges\AppData\Local\Google\Chrome\User Data\Default\Network\Cookies"
[debug] Found local state file at "C:\Users\biges\AppData\Local\Google\Chrome\User Data\Local State"
[Cookies] Loading cookie 1842/ 2088WARNING: failed to decrypt with DPAPI
Traceback (most recent call last):
File "yt_dlp\__main__.py", line 17, in <module>
File "yt_dlp\__init__.py", line 1081, in main
File "yt_dlp\__init__.py", line 979, in _real_main
File "yt_dlp\YoutubeDL.py", line 720, in __init__
File "yt_dlp\YoutubeDL.py", line 4070, in print_debug_header
File "functools.py", line 967, in __get__
File "yt_dlp\YoutubeDL.py", line 4245, in _request_director
File "yt_dlp\YoutubeDL.py", line 4220, in build_request_director
File "functools.py", line 967, in __get__
File "yt_dlp\YoutubeDL.py", line 4116, in cookiejar
File "yt_dlp\cookies.py", line 94, in load_cookies
File "yt_dlp\cookies.py", line 115, in extract_cookies_from_browser
File "yt_dlp\cookies.py", line 315, in _extract_chrome_cookies
File "yt_dlp\cookies.py", line 350, in _process_chrome_cookie
File "yt_dlp\cookies.py", line 525, in decrypt
AttributeError: 'NoneType' object has no attribute 'decode'
[17148] Failed to execute script '__main__' due to unhandled exception!
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 15
- Comments: 67 (5 by maintainers)
“Export the cookies with an extension such as this and use --cookies instead”
This works. Export the cookies to a local file. Replace “–cookies-from-browser chrome” By “-cookies …\cookies.txt”
Possible workarounds are:
--cookiesinsteadApplicationBoundEncryptionEnabledenterprise rule as outlined here (maybe)FYI: Added support for the latest Chrome encryption in rookie. Now compatible with Python, JavaScript, and Rust
Thanks to @runassu for amazing RE!
Since there are multiple reports, this seems to be a change in Chrome.
I cannot replicate on my machine.This could potentially be related to https://security.googleblog.com/2024/07/improving-security-of-chrome-cookies-on.html which once rolled out will likely mean
--cookies-from-browser chromewill be permanently broken on Windows.Chrome cookie encrypted_value v20 use
app_bound_encrypted_keyin Local State file. To decrypt this, we first need to decryptapp_bound_encrypted_keywith the SYSTEM DPAPI, followed by the user DPAPI. In other brand browsers, we can directly get the 32-bytes AES key to decrypt encrypted cookies. Chrome requires some additional steps. ref: https://github.com/chromium/chromium/blob/35afbc6f6b81d51d697ea615364a972832dab418/chrome/elevation_service/elevator.cc#L199For example, after the double step DPAPI decryption, the resulting value comes with Chrome path, then 1-byte flag 0x01, 12-bytes IV, 32-bytes ciphertext, 16-bytes TAG.
IV:
ca bf 17 e5 f2 f4 47 b0 e8 1b 64 1bciphertext:f2 7c 22 49 66 e2 5f fc ed d2 e0 cf c0 4e 1f 21 f6 1b c2 da a2 eb 6f 53 2c 47 d3 9e 7b 50 e6 7fTAG:4d 5c 34 3f e6 ee d9 43 58 91 9e d2 3a d8 96 30We can decrypt it using AES-256-GCM, with the key hardcoded inelevation_service.exe:This will yield the decrypted key, which works exactly as
encrypted_keydid.Here is th PoC https://github.com/runassu/chrome_v20_decryption/blob/31ff1e97a42bc548aa9894f72108b922b3cdba1f/decrypt_chrome_v20_cookie.py
Looking at https://github.com/chromium/chromium/blob/99fdd0d45b56eddea940b62796c297b2334e0dc9/chrome/elevation_service/elevator.cc#L198, it seems that Chrome has some more processing after the standard DPAPI decryption
This doesn’t seem to be the case for Edge, and probably other Chromium-based browsers
The new encryption method is basically the same as before with one extra step
Before, we had to take encrypted_key, and decrypt it with the user’s DPAPI. This gave an AES key to decrypt the cookies
Now, app_bound_encrypted_key just contains a different “encrypted_key”-like key, encrypted a second time You just need to decrypt app_bound_encrypted_key with the SYSTEM DPAPI, and you will get another key which works exactly as encrypted_key did, meaning that you can decrypt this key again with the user’s DPAPI and use the result to AES-decrypt the cookies
A quick way to check if this works is to decrypt the app_bound_encrypted_key with SYSTEM’s DPAPI, decrypt the result with the user’s DPAPI, and if the result is 32 bytes long, that’s a valid AES key
With Edge, I get a valid 32 byte key (even though for some reason I only get v10 cookies, so I can’t test it) With Chrome, the key I obtain is 61 bytes, since as I said before Chrome does another step which has no public source AFAIK
BTW, if you hate yourself, you can debug chrome.dll with something like WinDBG and their symbol server (https://chromium-browser-symsrv.commondatastorage.googleapis.com) and print the AES key after it gets decrypted
For me this worked out well. [Export All Cookies] ->
--cookies [file location]Setting “ApplicationBoundEncryptionEnabled” enterprise rule to “Disabled” through group policy:
or through registry:
has NO effect on the DPAPI error.
Okay I have just exported the cookies from Chrome with the Plugin mentioned above and works fine.
I even dont need to close Chrome now to be able to use the Cookies in yt-dlp. Nice!
Another workaround. Personally I’m fine with just reading cookies from my main Firefox profile, but if desired, you may create a dedicated profile:
<profile dir>:--no-remoteoption lets you run it concurrently with other Firefox profiles.On that Firefox instance, log into YouTube, etc. You may then close the Firefox instance.
Use yt-dlp, reading from these cookies:
@yidi000 Add the registry [HKEY_LOCAL_MACHINE\Software\Policies\Google\Chrome] “ApplicationBoundEncryptionEnabled”=dword:00000000 And reboot or kill Chrome process all manually(visible and invisiable processes) That is works of cause since Google official unless not following the instruction. Ignore the wrong information.
I used
--cookies-from-browser firefoxinstead. Worked like a charm. Didn’t have to close the browser either.Yes, it has no effect
Notice that you may need to export the cookie in a private/incognito window because of https://github.com/yt-dlp/yt-dlp/issues/8227#issuecomment-1867184804
Work around…
I know this isn’t solving the issue but for many it will create workaround.
@xyzxye https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies
Since chrome 130 is out, setting [HKEY_LOCAL_MACHINE\Software\Policies\Google\Chrome] “ApplicationBoundEncryptionEnabled”=dword:00000000 should now work I’m not sure if v20 cookies are automatically downgraded to v10, but if not, they will probably be saved as v10 when their value changes or they can be manually deleted and recreated.
We have seen that you need admin privileges to decrypt the app-bound key, and the flow would probably take time to be implemented
I’d say that first step could be fixing the v10 handling for users that set the registry key, so
Has anyone tried clearing cookies after setting the ApplicationBoundEncryptionEnabled and rebuilding them? As mentioned above it doesn’t decrypt once encrypted but it might prevent the encryption of new ones.
:EDIT: I just tried this, it did not work.
chrome://policy reveals that it was off
added to hklm and it still didn’t work on my use case
Mine in particular was throwing invalid continuation bytes, but if it works for others that’s great @mic-user just saying it didn’t work for me or a few others from the thread.