tubearchivist / browser-extension

Tube Archivist Companion for your Browser
GNU General Public License v3.0
150 stars 19 forks source link

Cookie import fails with "validated: undefined" #22

Closed EpicLPer closed 6 months ago

EpicLPer commented 1 year ago

Heya,

I just tried importing my cookies and I'm getting the following error inside the browser extension: image

In the Inspect tab I get the message {"message":{"cookie_import":"fail","cookie_validated":false}}, the network tab tells me a 400 Bad Request occured.

Not sure if I'm doing something wrong (again) tho :)

Thanks already!

bbilly1 commented 1 year ago

Impossible to say without logs what's happening. Probably means invalid cookie? Sometimes doing this from a blank browser can help, where there has always only been one google account used. Or you can also use the manual import.

DutchEllie commented 1 year ago

I have the same issue, have been having it since forever and always just manually added the cookie, very annoying. This is the log from when I tried to add the cookie using the extension:

cookie preview:

# Netscape HTTP Cookie File
# https://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file! Do not edit.

.youtube.com    TRUE    /       FALSE   1719579328      SOCS    [REDACTED]
.youtube.com    TRUE    /       TRUE    0       YSC     [REDACTED]
.youtube.com    TRUE    /       FALSE   1720011328      CONSENT [REDACTED]
.youtube.com    TRUE    /       TRUE    1725
cookie: activated and stored in Redis
validating cookie
cookie file is invalid
cookie validation failed, exiting...
cookie: revoked
cookie: {'cookie_import': 'fail', 'cookie_validated': False}
[pid: 44|app: 0|req: 1359/1359] 10.0.0.38 () {64 vars in 1070 bytes} [Thu Aug 17 14:16:03 2023] PUT /api/cookie/ => generated 61 bytes in 101 msecs (HTTP/1.1 400) 9 headers in 357 bytes (1 switches on core 0)

It seems to just send bad data, not actually the full cookies file like it needs.

bbilly1 commented 1 year ago

A cookie is valid, if TA can access your liked videos playlist, e.g. https://www.youtube.com/playlist?list=LL. If it can't access that, it's invalid and revoked as you can see in your output.

One of these cases of works on my machine. If it doesn't work for you, please provide a fix.

bbilly1 commented 1 year ago

very annoying

Please be nice.

grantterra commented 1 year ago

I had the same issue.

screenshot1

I compared the original cookies stored in the browser, and it seems that TubeArchivist did not receive the last 54 characters in the cookie value.

image

3urobeat commented 1 year ago

I'm also experiencing this issue for months now.
It did work as expected back in June and then suddenly failed.
Tubearchivist on my server, as well as the browser extension, are on the newest versions.
I have deleted all my YouTube cookies, did a fresh login - also no success.

I'm using LibreWolf Firefox 118.0.1-1 on Linux 6.5.5-arch1-1

Edit: I can confirm the observation by grantterra, the cookie extracted by the extension is too short. After exporting the cookie manually, placing it in the import directory, enabling cookies and reindexing, my playlist it is active again.

clb92 commented 1 year ago

I'm experiencing this in Chrome, but not in Firefox.

bbilly1 commented 1 year ago

It seems to just send bad data, not actually the full cookies file like it needs.

and

I compared the original cookies stored in the browser, and it seems that TubeArchivist did not receive the last 54 characters in the cookie value.

as well as

I can confirm the observation by grantterra, the cookie extracted by the extension is too short.

you'll see in your log output cookie preview. so what is logged is only the first 200 characters (I think) from the complete cookie. as that is sensitive data, so this shouldn't be logged completely somewhere...

cookie building happens in background.js here: https://github.com/tubearchivist/browser-extension/blob/master/extension/background.js#L209

if anybody wants to investigate further.

bbilly1 commented 1 year ago

Some investigation on the live stream could point towards that we limit our domain selection too much, and that www.youtube.com will get excluded.

notes: https://github.com/Rob--W/cookie-manager/issues/26

some traceback:

/usr/local/lib/python3.11/http/cookiejar.py:2083: UserWarning: http.cookiejar bug!
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/http/cookiejar.py", line 2056, in _really_load
    assert domain_specified == initial_dot
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

  _warn_unhandled_exception()
Gentoli commented 9 months ago

For me, looks like the extension included a cookie from the subdomain payments.youtube.com and yt-dlp is not happy with that. Removing it from the POST /api/cookie/ works.

Because the validation is done by yt-dlp, before https://github.com/tubearchivist/tubearchivist/pull/669 which would log the error in the console, you could try capturing the cookie file sent by the extension from the extension developer console, then testing it with downloading any youtube video with a noop arg like -F, then it would give error like:

http.cookiejar.LoadError: invalid Netscape format cookies file 'C:\\Users\\<user>\\Desktop\\cookies.txt': 'payments.youtube.com\tTRUE\t/\tFALSE\t1711779732\tOTZ\t<some-value>'
bbilly1 commented 8 months ago

Interesting, would make sense that I can't reproduce this, I probably won't have any payment subdomain cookies if I didn't make any payments on YT. Will ignoring all subdomains work? Or does this need some other processing?

Gentoli commented 8 months ago

Given yt-dlp is rejecting cookies from the subdomains, I think it's safe to remove all subdomains.

CommanderRedYT commented 8 months ago

I do not have any cookies on subdomains but it still fails. Both on firefox and chrome and with different accounts

wolrah commented 8 months ago

I can confirm that removing the payments.youtube.com cookie solved the problem for me.

bbilly1 commented 6 months ago

Can somebody who can reproduce this check if the linked commit on the https://github.com/tubearchivist/browser-extension/tree/fix-cookie-domain branch fixes that?

This still syncs the cookie correctly for me.

bbilly1 commented 6 months ago

assuming this has been fixed, update to v0.3.0