cmv has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks-

I would like to be able to read my Chrome cookies on a Mac.

My understanding is that I can use HTTP::Cookies::Chrome to do this. The following is an example script I pulled from the git repository and modified it for my Chrome profile.

When I run it I get the attached failure messages with no other output. Any help or pointers are much appreciated.

Thanks

Craig

Script:

#!/opt/homebrew/bin/perl use v5.10; use strict; use warnings; use Mojo::Util qw(dumper); use HTTP::Cookies::Chrome; my $class = 'HTTP::Cookies::Chrome'; #my $path = $class->guess_path; my $path = '/Users/cmv/Library/Application Support/Google/Chrome/P +rofile 1/Cookies'; my $password = $class->guess_password; say <<~"HERE"; File: $path Pass: $password HERE my $cookies = HTTP::Cookies::Chrome->new( chrome_safe_storage_password => $password, ignore_discard => 0, ); $cookies->load( $path ); $cookies->scan( \&summary ); sub summary { state $previous_domain = ''; my( @cookie ) = @_; say $cookie[4] unless $cookie[4] eq $previous_domain; $previous_domain = $cookie[4]; printf "\t%-5s %-16s %s\n", map { $_ // '' } @cookie[3,1,2]; }

Errors:

$ ./chromecookie.pl File: /Users/cmv/Library/Application Support/Google/Chrome/Profile 1/C +ookies Pass: XXXXXXXXXXXXXX Encrypted value is unexpected type <1> at ./chromecookie.pl line 27. Encrypted value is unexpected type <1> at ./chromecookie.pl line 27. Encrypted value is unexpected type <1> at ./chromecookie.pl line 27. Encrypted value is unexpected type <1> at ./chromecookie.pl line 27. ... Argument "v10?M-\f??&#695;M-^EM-^T>^YM-^EdtM-^F^Y??kM-\0&dkYh!M-^Q??M- +^F..." isn't numeric in division (/) at /Users/cmv/perl5/lib/perl5/HT +TP/Cookies/Chrome.pm line 451. Argument "v108M-^Q-^D<-?^Z?^K?vM-\r%M-^[K?7%?M-^\^UM-^_?3&#1381;M-^[&# +1760;?..." isn't numeric in division (/) at /Users/cmv/perl5/lib/perl +5/HTTP/Cookies/Chrome.pm line 451. Argument "v10????BA^G^D?dM-^TM-^A^Z???$^H]\n0??^^?:F?g??"^[G?EM-^H..." + isn't numeric in division (/) at /Users/cmv/perl5/lib/perl5/HTTP/Coo +kies/Chrome.pm line 451. ...

Replies are listed 'Best First'.
SOLVED: HTTP::Cookies::Chrome fails with Chrome cookies
by cmv (Chaplain) on Jun 23, 2025 at 13:02 UTC
    UPDATE: Changing the prepare() call below to the following seems to fix the issue:
    my $sth = $dbh->prepare( 'SELECT creation_utc,host_key,name,value, +path,expires_utc,is_secure,is_httponly,last_access_utc,has_expires,is +_persistent,priority,encrypted_value,samesite,source_scheme,source_po +rt FROM cookies' );

    Folks-

    Upon further investigation, it seems that the Chrome.pm file is not up-to-date with the latest version of how Chrome stores its cookies. Specifically in the _get_rows function:

    sub _get_rows { my( $self, $file ) = @_; my $dbh = $self->_connect( $file ); my $sth = $dbh->prepare( 'SELECT * FROM cookies' ); # CHANGE THIS + LINE $sth->execute; my @rows = map { if( my $e = $_->encrypted_value ) { my $p = $self->_decrypt( $e ); $_->decrypted_value( $self->_decrypt( $e ) ); } $_; } map { HTTP::Cookies::Chrome::Record->new( $_ ) } @{ $sth->fetchall_arrayref }; $dbh->disconnect; \@rows; }

    The fetchall_arrayref list that is returned needs to match the %columns hash in HTTP::Cookies::Chrome::Record.

    my %columns = map { state $n = 0; $_, $n++ } qw( creation_utc host_key name value path expires_utc is_secure is_httponly last_access_utc has_expires is_persistent priority encrypted_value samesite source_scheme source_port is_same_party decrypted_value );
    Adding some debug printing statements to Chrome.pm, I see the following - which do not seem to be aligning:
    creation_utc=13394990094757976 host_key=www.costco.com name= value=CriteoSessionUserId path= expires_utc=v10?a@uV?0^t?,h????????... is_secure=/ is_httponly=13397582094000000 last_access_utc=0 has_expires=0 is_persistent=13395156037532475 priority=1 encrypted_value=1 samesite=1 source_scheme=-1 source_port=2 is_same_party=443 decrypted_value=13394990094757976

HTTP::Cookies::Chrome doesn't seem to decrypt properly
by cmv (Chaplain) on Jun 23, 2025 at 23:35 UTC
    Folks-

    If you follow my solution above, and run the example script, you can see the cookies path, name, and value in the output.

    However many of the values are now encrypted. HTTP::Cookies::Chrome claims to know how to decode them by finding a password in my keychain on Mac. However the results don't look like they've decoded properly. see update below

    Any pointers are much appreciated!

    Thanks

    Craig

    Example Output:

    .33across.com / 33x_ps ?C?5?T-76?Q???$?HW>... .3lift.com / tluid ?0j???t?*??3M?("D???1?0... / tluidp ?0j???t?*??3M?("D???1?0... .a-mo.net / amuid2 ;??\????W{??"?$?b???K?S... / pamuid2 ;??\????W{??"?$?b???K?S&...
    UPDATE: Hold on there cowboy! It seems that the entries are being decoded, but with a bunch of binary poop before them.

    Here is an example of a cookie that the Chrome developer shows a value of: 1af15945-c298-4041-a6e7-45b5e233cf82

    .costco.com / BVBRANDID {?'}~???X???2?6%t????7T????#1af15945-c2 +98-4041-a6e7-45b5e233cf82

    Anybody know what that stuff is before the hash?

    Thanks

    Craig