yt-dlp: Linux/macOS/BSD chromium cookies could not be decrypted; failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed

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’m running yt-dlp version 2023.03.04 (update instructions) or later (specify commit)
  • 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

Trying to download a video from panopto doesn’t seem to work as it doesnt seem to decrypt the cookies. Very similar to https://github.com/yt-dlp/yt-dlp/issues/1073 which seems to be resolved However I have the the most updated version but still seems to be not working.

I am running this on linux mint

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': True to YoutubeDL params instead
  • Copy the WHOLE output (starting with [debug] Command-line config) and insert it below

Complete Verbose Output

yt-dlp -vU --cookies-from-browser chromium https://huji.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=64d725f2-972e-42f7-9eeb-afbf0067727a[debug] Command-line config: ['-vU', '--cookies-from-browser', 'chromium', 'https://huji.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=64d725f2-972e-42f7-9eeb-afbf0067727a']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.03.04 [392389b7d]
[debug] Lazy loading extractors is disabled
[debug] Python 3.8.10 (CPython x86_64 64bit) - Linux-5.15.0-60-generic-x86_64-with-glibc2.29 (OpenSSL 1.1.1f  31 Mar 2020, glibc 2.31)
[debug] exe versions: ffmpeg 4.2.7, ffprobe 4.2.7, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2019.11.28, mutagen-1.46.0, pyxattr-0.6.1, secretstorage-3.3.3, sqlite3-2.6.0, websockets-10.4
[Cookies] Extracting cookies from chromium
[debug] Extracting cookies from: "/home/ratio/.config/chromium/Default/Cookies"
[Cookies] Loading cookie      0/   317[debug] detected desktop environment: CINNAMON
[debug] Chosen keyring: GNOMEKEYRING
WARNING: failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?
[Cookies] Extracted 245 cookies from chromium (72 could not be decrypted)
[debug] cookie version breakdown: {'v10': 0, 'v11': 317, 'other': 0, 'unencrypted': 0}
[debug] Proxy map: {}
[debug] Loaded 1788 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.03.04, Current version: stable@2023.03.04
yt-dlp is up to date (stable@2023.03.04)
[Panopto] Extracting URL: https://huji.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=64d725f2-972e-42f7-9eeb-afbf0067727a
[Panopto] 64d725f2-972e-42f7-9eeb-afbf0067727a: Downloading JSON metadata
ERROR: [Panopto] 64d725f2-972e-42f7-9eeb-afbf0067727a: This video is only available for registered users. Use --cookies-from-browser or --cookies for the authentication. See  https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp  for how to manually pass cookies
  File "/home/ratio/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 694, in extract
    ie_result = self._real_extract(url)
  File "/home/ratio/.local/lib/python3.8/site-packages/yt_dlp/extractor/panopto.py", line 379, in _real_extract
    delivery_info = self._call_api(
  File "/home/ratio/.local/lib/python3.8/site-packages/yt_dlp/extractor/panopto.py", line 62, in _call_api
    self.raise_login_required(method='cookies')
  File "/home/ratio/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 1154, in raise_login_required
    raise ExtractorError(msg, expected=True)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 29 (19 by maintainers)

Commits related to this issue

Most upvoted comments

I fixed it by hacking around the problem.

I tracked the “source” of this message:

WARNING: failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?

The decryption of cookies is decoding the decrypted “plaintext” using UTF-8. And for some reason, I didn’t yet track why exactly, there are 32 extra bytes of garbage at the beginning of the string. As others noted, this started very recently.

https://github.com/yt-dlp/yt-dlp/blob/2a24674/yt_dlp/cookies.py#L1013-L1021

The “return plaintext.decode()” is failing. After comparing values from different steps of the process against my actual cookies, I noticed there were simply extra bytes (garbage? idk…)

I changed it to cut off these extra bytes “return plaintext[32:].decode()” and it stopped failing (for all the cookies).

Hopefully this clue leads to someone solving the issue without hacking around it.

I fixed it by hacking around the problem.

I tracked the “source” of this message:

WARNING: failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?

The decryption of cookies is decoding the decrypted “plaintext” using UTF-8. And for some reason, I didn’t yet track why exactly, there are 32 extra bytes of garbage at the beginning of the string. As others noted, this started very recently.

https://github.com/yt-dlp/yt-dlp/blob/2a24674/yt_dlp/cookies.py#L1013-L1021

The “return plaintext.decode()” is failing. After comparing values from different steps of the process against my actual cookies, I noticed there were simply extra bytes (garbage? idk…)

I changed it to cut off these extra bytes “return plaintext[32:].decode()” and it stopped failing (for all the cookies).

Hopefully this clue leads to someone solving the issue without hacking around it.

This works great! I think a PR should be made with this change as it will keep BC:

diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py
index 4a69c576b..5a5dbe941 100644
--- a/yt_dlp/cookies.py
+++ b/yt_dlp/cookies.py
@@ -1016,7 +1016,10 @@ def _decrypt_aes_cbc_multi(ciphertext, keys, logger, initialization_vector=b' '
         try:
             return plaintext.decode()
         except UnicodeDecodeError:
-            pass
+            try:
+                return plaintext[32:].decode()
+            except UnicodeDecodeError:
+                pass
     logger.warning('failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?', only_once=True)
     return None

@mbway If we try first with the full plaintext before slicing, that should be backwards compatible, yeah?

diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py
index 4a69c576b..6ecc354cc 100644
--- a/yt_dlp/cookies.py
+++ b/yt_dlp/cookies.py
@@ -1013,10 +1013,11 @@ def pbkdf2_sha1(password, salt, iterations, key_length):
 def _decrypt_aes_cbc_multi(ciphertext, keys, logger, initialization_vector=b' ' * 16):
     for key in keys:
         plaintext = unpad_pkcs7(aes_cbc_decrypt_bytes(ciphertext, key, initialization_vector))
-        try:
-            return plaintext.decode()
-        except UnicodeDecodeError:
-            pass
+        for cookie in (plaintext, plaintext[32:]):
+            try:
+                return cookie.decode()
+            except UnicodeDecodeError:
+                pass
     logger.warning('failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?', only_once=True)
     return None
 

I was having the same issue with chromium browser (Gnome desktop)

Using seahorse I saw that I had multiple Chromium Safe Storage entries. In the details of these entries there is a key application, which was set to application: chromium for one of the entries, but other ones were application: discord and application: slack. Once I deleted the other entries, leaving only application: chromium one, the cookie extraction started working.

sorry, with the rookie issue being posted so recently I assumed it had to be related without looking carefully.

Although the symptom is the same as the original post in this issue thread, this probably warrants a new issue being opened since the cause of these new decryption issues is clear (caused by chrome upgrade).

I have been able to reproduce the error with chrome 130.0.6723.19 on Arch/KDE6.

I read through the changelog for recent changes to cookie storage in chromium but didn’t find anything obvious that could be causing the breakage.

https://chromium.googlesource.com/chromium/src/+log/refs/heads/main/components/os_crypt

I tried playing around with some data as well and have some notes:

  • a hand-crafted example with values manually extracted from kwallet and the database still fail, so it isn’t that the password is not being detected properly or something.
  • google-chrome-beta is definitely still using kwallet (new folder created on first launch)
  • looks like a fixed IV is still being used because many cookies had the same 32 bytes of ciphertext after the v11 prefix

I’m running into this after updating my system

Arch with Plasma 6.2.1 with kwallet disabled and --password-store=basic in chromium flags, chromum 130.0.6723.58-1

~/.config/kwalletrc contains

[Wallet]
Enabled=false

For yt-dlp using --cookies-from-browser chromium:/path/to/custom/profile and seeing

[debug] Extracting cookies from: "/path/to/custom/profile/Default/Cookies"
[Cookies] Loading cookie      0/  1154WARNING: failed to decrypt cookie (AES-CBC) because UTF-8 decoding failed. Possibly the key is wrong?
Extracted 705 cookies from chromium (434 could not be decrypted)
[debug] cookie version breakdown: {'v10': 1154, 'v11': 0, 'other': 0, 'unencrypted': 0}

where previously no issues.