Code Monkey home page Code Monkey logo

cookies's Introduction

Cookies

Extracts cookies from the user's Chrome, Chromium, Firefox or Safari cookie database. A single cookie value can be retrieved, or all cookies applicable to given URL can be retrieved and output in a format appropriate for use in the HTTP Cookie header. Both of these usages are useful for scripting purposes.

The core cookie-reading code is provided by the zellyn/kooky cookie extraction library. This cookies tool provides a command-line interface to that library that allows you to select which browser cookie databases to use and filter for all or a particular cookie that are relevant for a given URL.

Installing

On MacOS with Homebrew:

brew install barnardb/cookies/cookies

Alternatively, or on other platforms, follow the instructions below for building an executable.

Usage

As explained by cookies --help:

usage: ./cookies [options…] <URL> [<cookie-name>]

The following options are available:
  -a, --accept-missing        don't fail with exit status 1 when cookies aren't found
  -b, --browser stringArray   browser to try extracting a cookie from, can be repeated to try multiple browsers (default [chrome,chromium,firefox,safari])
  -v, --verbose[=level]       enables logging to stderr; specify it twice or provide level 2 to get per-cookie details (`-vv` or `--verbose=2`)
      --version               prints version information and exits

cookies version 0.5.1  (https://github.com/barnardb/cookies)

To get all cookies relevant to a URL in the format expected by the Cookie header, provide the URL as an argument. E.g., running

cookies http://www.example.com

might yield

some.random.value=1234;JSESSIONID=0123456789ABCDEF0123456789ABCDEF;another_cookie:example-cookie-value

Or you can get just the value of a particular cookie by providing both a URL and a cookie name. E.g. running

cookies http://www.example.com JSESSIONID

might yield

0123456789ABCDEF0123456789ABCDEF

cURL example

curl --cookie "$(cookies http://www.example.com)" http://www.example.com

might produce an HTTP request like this:

GET / HTTP/1.1
Host: www.example.com
User-Agent: curl/7.54.0
Accept: */*
Cookie: some.random.value=1234;JSESSIONID=0123456789ABCDEF0123456789ABCDEF;another_cookie:example-cookie-value

HTTPie example

http http://www.example.com Cookie:"$(cookies http://www.example.com)"

might produce an HTTP request like this:

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: some.random.value=1234;JSESSIONID=0123456789ABCDEF0123456789ABCDEF;another_cookie:example-cookie-value
Host: www.example.com
User-Agent: HTTPie/1.0.2

Status

I use this tool for day-to-day tasks on multiple MacOS systems. (Note that there is a cookie database permission issue you will have to deal with if you want to read Safari cookies: zellyn/kooky #7.)

As the library is essentially a wrapper around zellyn/kooky and the library supports other platforms as well, this tool should also work on other platforms.

Pull requests are welcome.

Building

Requires Go.

To build the code, check out the repository and run:

go build

This produces a cookies executable.

Releasing

Releases are prepared by running:

./prepare-release.sh "${version}"

${version} should be a semantic version number in the "0.0.0" format. This tags the release (e.g. as "v0.0.0") and creates a draft release in GitHub, which can be given release notes and published.

Once the new release is published to GitHub, the homebrew formula in barnardb/homebrew-cookies should be updated following the instructions in that repo's README.

cookies's People

Contributors

barnardb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cookies's Issues

Support Chrome Profiles on MacOS

If there are multiple Chrome profiles on MacOS, it'd be really helpful to be able to pass a --profile argument to use the Cookies file in that profile's directory, instead of always/only using Default.

Add link to this Github repo in `--help` output? 🙂

I installed this a while ago and re-found it recently -- and I couldn't for the life of me figure out where it came from! 😆

14:13:55 ❯ cookies -h
usage: cookies [options…] <URL> [<cookie-name>]

The following options are available:
  -a, --accept-missing        don't fail with exit status 1 when cookies aren't found
  -b, --browser stringArray   browser to try extracting a cookie from, can be repeated to try multiple browsers (default [chrome,chromium,firefox,safari])
  -v, --verbose[=level]       enables logging to stderr; specify it twice or provide level 2 to get per-cookie details (`-vv` or `--verbose=2`)

~/code
14:30:41 ❯ cookies --version
unknown flag: --version
usage: cookies [options…] <URL> [<cookie-name>]

The following options are available:
  -a, --accept-missing        don't fail with exit status 1 when cookies aren't found
  -b, --browser stringArray   browser to try extracting a cookie from, can be repeated to try multiple browsers (default [chrome,chromium,firefox,safari])
  -v, --verbose[=level]       enables logging to stderr; specify it twice or provide level 2 to get per-cookie details (`-vv` or `--verbose=2`)

~/code
14:30:43 ❯ help cookies

~/code
14:30:46 ❯ man cookies
No manual entry for cookies

~/code
14:30:52 ❯ which cookies
/usr/local/bin/cookies

~/code
14:30:55 ❯ type cookies
cookies is /usr/local/bin/cookies

~/code
14:31:02 ❯ head -n1 (which cookies)
�H__PAGEZERO�__TEXT�D�D
                       __text__TEXT�'��$�'�__stubs__TEXT�%
                                                          ��__stub_helper__TEXT�%$�%�__rodata__TEXT�% d�%__typelink__TEXT|3�|3__itablink__TEXT��3@��3__gopclntab__TEXT��3+���3__gosymtab__TEXT�|D�|D__cstring__TEXT�|D�|D__const__TEXT�D�D__unwind_info__TEXT�D��D�__DATA�D��D__nl_symbol_ptr__DATA��D�__got__DAT�D�D�__la_symbol_ptr__DATA8�D8�D�__go_buildinfo__DATAP�D P�D__noptrdata__DATA��D����D__data__DATA AH� AH__bss__DATA �H�__noptrbss__DATA��K(1H__LINKEDIT@L�b(W"�0bb�
                                                                                                                                                                                                      �bEb�w��i��
                                                                                                                                                                                                                 P�v�vH=w�h�i

                                                                                                                                                                                                                              /usr/lib/dyld��:'�P8��f�&�2

                                                                                                                                                                                                                                                           	�*(���
                                                                                                                                                                                                                                                                      8d
                                                                                                                                                                                                                                                                        /usr/lib/libSystem.B.dylib
                    hev��/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
X��h�N__zdebug_loc__DWARF�YR��P__zdebug_pubtype__DWARFa�]�yaqT__zdebug_aranges__DWARF�                `jdj�/System/Library/Frameworks/Security.framework/Versions/A/Security&h&b�Eb�__DWARFI�__zdebug_line__DWARF RƑI__zdebug_pubname__DWARFƱV�[ƑM__zdebug_ranges__DWARFh

~/code
14:31:31 ❯ brew search cookies
==> Formulae
barnardb/cookies/cookies ✔                                                                                                              cookiecutter

==> Casks
cookie

Once I finally found barnardb/cookies/cookies ✔ in the brew search output I was able to google and find this repo -- but it'd be great to include a link to this repo in the --help and/or a --version output to make it easy to find source information. 🙂

Great tool!

is there a hidden feature like deleting cookies?

If I can request a new feature, it definitely would be the "delete cookies" feature.
BTW, can I ask another Q, is it possible to find out which cookies belong to which profiles.
The results for a same domain is really mixed from all kinds of profiles and browsers. I have used -v option, but it looked really a mess.

Bug feedback: Chrom and Firefox work well, Safari doesn't return any result.

Not working Windows Chrome

Doesn't seem to be working for me for Windows and Chrome. I try the host, which clearly displays in cookies in Chrome, but Cookies doesn't bring back anything. In fact, I can't get any cookies from Cookies.

Here the output from verbose:

Loading cookies from &{{C:\Users\{REMOVED}\AppData\Local\Google\Chrome\User Data\Default\Cookies <nil> chrome Person 1 windows true} <nil> [] [] <nil>}
Error loading cookies from &{{C:\Users\{REMOVED}\AppData\Local\Google\Chrome\User Data\Default\Cookies <nil> chrome Person 1 windows true} <nil> [] [] <nil>}: 

dependency issue

Hello,

I'm trying to do the build but there's a dependency issue :

go build
go: downloading github.com/barnardb/kooky v0.0.0-20210125015714-b0182bf77e67
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/go-ini/ini v1.62.0
go: downloading github.com/go-sqlite/sqlite3 v0.0.0-20180313105335-53dd8e640ee7
go: downloading golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
go: downloading github.com/bobesa/go-domain-util v0.0.0-20190911083921-4033b5f7dd89
go: downloading golang.org/x/net v0.0.0-20201031054903-ff519b6c9102
go: downloading github.com/gonuts/binary v0.2.0
go: downloading golang.org/x/text v0.3.4
../../go/pkg/mod/github.com/barnardb/[email protected]/internal/chrome/chrome_linux.go:9:2: missing go.sum entry for module providing package github.com/zalando/go-keyring/secret_service (imported by github.com/zellyn/kooky/internal/chrome); to add:
go get github.com/zellyn/kooky/internal/[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.