/kooky

Go code to read cookies from browser cookie stores.

Primary LanguageGoMIT LicenseMIT

kooky

Reaching into browser-specific, vaguely documented, possibly concurrently modified cookie stores to pilfer cookies is a bad idea. Since you've arrived here, you're almost certainly going to do it anyway. Me too. And if we're going to do the Wrong Thing, at least let's try to Do it Right.

Package kooky contains routines to reach into cookie stores for Chrome and Safari, and retrieve the cookies.

It aspires to be pure Go (I spent quite a while making go-sqlite/sqlite3 work for it), but I guess the keychain parts (keybase/go-keychain) mess that up.

It also aspires to work for all three major browsers, on all three major platforms. Naturally, half of that is TODOs.

Status

No Maintenance Intended

Basic functionality works, on MacOS. I expect Linux to work too, since it doesn't encrypt. The API is currently not expected to be at all stable.

PRs more than welcome.

TODOs

  • Make it work on Windows. (Look at this and this to learn how to decrypt.)
  • Handle rows in Chrome's cookie DB with other than 14 columns (?)

Example usage

usr, _ := user.Current()

var cookies []*kooky.Cookie
var err error

chrome := false
if chrome {
	cookiesFile := fmt.Sprintf("%s/Library/Application Support/Google/Chrome/Default/Cookies", usr.HomeDir)
	cookies, err = kooky.ReadChromeCookies(cookiesFile, "", "", time.Time{})
} else {
	cookiesFile := fmt.Sprintf("%s/Library/Cookies/Cookies.binarycookies", usr.HomeDir)
	cookies, err = kooky.ReadSafariCookies(cookiesFile, "", "", time.Time{})
}
if err != nil {
	return err
}
for _, cookie := range cookies {
	fmt.Println(cookie)
}

Thanks/references