> your AI agent picks dependencies from memory; give it dated facts — try starlog.dev ↗ vet your agent's deps ↗ vibe-coding is fine. vibe-importing isn’t. — try starlog.dev ↗ vibe-importing isn’t fine ↗ your agent has never seen your private packages — try starlog.dev ↗ facts for private packages ↗ a linter for the dependencies your AI agent picks — try starlog.dev ↗ a linter for agent deps ↗ whois is redacted, cdns mask the rest — get the real operator — try whoisgeni.us ↗ who really runs that domain ↗ domain attribution that shows its work — full evidence chain — try whoisgeni.us ↗ domain intel w/ evidence ↗

← Back to Articles

Reading Chrome's Cookies Without Opening Chrome: A Forensic Approach in Go

[ View on GitHub ]

Reading Chrome's Cookies Without Opening Chrome: A Forensic Approach in Go

Hook

Every time you automate Chrome with Selenium or Puppeteer, you're spinning up a 200MB browser process just to read a few kilobytes of cookies. What if you could read them straight from the SQLite database like a forensics investigator?

Context

Web scraping and automation typically follow a familiar pattern: launch a headless browser, navigate to a login page, fill forms, capture cookies, then use those cookies for authenticated requests. This approach is slow, memory-intensive, and fragile. Tools like Selenium and Puppeteer require maintaining browser binaries, handling version compatibility, and dealing with detection mechanisms that flag automated browsers.

The alternative—manual cookie extraction—has been surprisingly difficult in Go. Python has pycookiecheat for cookies, but it doesn't handle local storage. Generic LevelDB readers exist, but they don't understand Chrome's serialization format. And critically, most tools ignore the encryption layer: Chromium doesn't store cookies in plaintext. On macOS, cookie values are encrypted with AES-CBC using a key stored in the system Keychain. On Windows, they're encrypted with DPAPI. Reading the SQLite database gives you ciphertext blobs that are useless without the decryption pipeline. chromedb combines SQLite reading, OS-level keychain access, cryptographic decryption, and LevelDB parsing into a single Go binary that outputs clean JSON—no browser required.

Technical Insight

LocalStorage Pipeline

Cookie Pipeline

encrypted_value

security command

password

saltysalt, 1003 iter

v10 prefix + IV + ciphertext

decrypted cookies

raw storage files

key-value pairs

type conversion

stdout

Chrome SQLite DB

Cookie Extractor

macOS Keychain

Key Retrieval

PBKDF2 Derivation

AES-128 Key

AES-CBC Decrypt

JSON Output

Chrome LevelDB

LevelDB Reader

Format Parser

jq / Pipeline

System architecture — auto-generated

chromedb's architecture is two independent extraction pipelines that share nothing except the output format. The cookie pipeline reads Chrome's SQLite database at ~/Library/Application Support/Google Chrome/Default/Cookies, but the encrypted_value column contains AES-CBC ciphertext. The decryption key isn't in the database—it's in macOS Keychain under the service name "Chrome Safe Storage".

Here's how the decryption flow works. First, chromedb shells out to the security command-line tool to retrieve the encryption key:

cmd := exec.Command(
    "security",
    "find-generic-password",
    "-w",
    "-s", "Chrome Safe Storage",
)
keychainPassword, err := cmd.Output()

This returns the password Chrome uses as input to PBKDF2 key derivation. Chromium's encryption scheme uses PBKDF2-HMAC-SHA1 with exactly 1003 iterations and the static salt "saltysalt" (yes, really—this is hardcoded in Chromium's source). The derived key is 128 bits for AES:

key := pbkdf2.Key(
    keychainPassword,
    []byte("saltysalt"),
    1003,
    16, // 128-bit key
    sha1.New,
)

The encrypted cookie value in the database has a three-byte prefix "v10" (version identifier) followed by the IV (initialization vector) and ciphertext. chromedb strips the prefix, extracts the 16-byte IV, and decrypts using AES-CBC:

encryptedValue := row[3].([]byte)
if len(encryptedValue) < 3 || string(encryptedValue[:3]) != "v10" {
    return nil, fmt.Errorf("unsupported encryption version")
}

encryptedValue = encryptedValue[3:]
block, _ := aes.NewCipher(key)
iv := make([]byte, aes.BlockSize)
copy(iv, encryptedValue[:aes.BlockSize])

mode := cipher.NewCBCDecrypter(block, iv)
decrypted := make([]byte, len(encryptedValue)-aes.BlockSize)
mode.CryptBlocks(decrypted, encryptedValue[aes.BlockSize:])

The result is plaintext cookie values with PKCS7 padding that needs stripping. This exact parameter set—1003 iterations, "saltysalt", AES-CBC with prepended IV—is critical. Get any part wrong and decryption fails silently, producing garbage.

The local storage pipeline is architecturally different because Chrome stores localStorage in LevelDB, not SQLite. LevelDB is a key-value store that Chrome uses for multiple subsystems. The localStorage files live in ~/Library/Application Support/Google Chrome/Default/Local Storage/leveldb/. chromedb uses syndtr/goleveldb to iterate through all keys:

db, err := leveldb.OpenFile(leveldbPath, nil)
iter := db.NewIterator(nil, nil)
for iter.Next() {
    key := string(iter.Key())
    value := iter.Value()
    // Parse Chrome's serialization format
}

But here's where it gets interesting: LevelDB gives you raw bytes, and Chrome's serialization format is undocumented. A key might be "_https://example.com\x00\x01username" (domain + null byte + separator + variable name), and the value might be a string, JSON object, or binary data. chromedb uses heuristic type inference—checking if the value starts with { or [ for JSON, detecting quote characters for strings, attempting UTF-8 decoding for text. This is fragile but pragmatic:

func inferType(value []byte) interface{} {
    // Try JSON first
    if len(value) > 0 && (value[0] == '{' || value[0] == '[') {
        var obj interface{}
        if json.Unmarshal(value, &obj) == nil {
            return obj
        }
    }
    // Fall back to string if valid UTF-8
    if utf8.Valid(value) {
        return string(value)
    }
    // Return base64-encoded binary as last resort
    return base64.StdEncoding.EncodeToString(value)
}

The output is JSON to stdout, designed for Unix piping. Want all GitHub cookies? chromedb cookies | jq '.[] | select(.domain | contains("github"))'. Need a specific localStorage key? chromedb storage | jq '.[] | select(.key | contains("auth_token"))'.

This architecture—direct filesystem reads, OS-specific crypto, stream-oriented output—makes chromedb fundamentally different from browser automation. There's no network activity, no process spawning (except the security command), no IPC with Chrome. It's a forensic tool that happens to be useful for automation.

Gotcha

The elephant in the room is platform support: chromedb only works on macOS. The entire decryption pipeline depends on macOS Keychain via the security command. Windows uses DPAPI (Data Protection API) with a completely different key derivation scheme, and Linux distributions vary between gnome-keyring, kwallet, and plaintext storage. If you run this on Windows or Linux, it fails immediately—not gracefully with a helpful error, but with cryptic failures about missing keychain entries.

The second limitation is database locking. Chrome keeps the Cookies SQLite file open with an exclusive lock while running. If you try to read it while Chrome is open, SQLite returns a "database is locked" error. chromedb doesn't handle this—no retry logic, no guidance to close the browser, just a raw error. The workaround is running it while Chrome is closed, or copying the database file first (which introduces race conditions if cookies change mid-copy). For operational use, you'd want to use SQLite's backup API or handle SQLITE_BUSY gracefully. Similarly, the tool provides no validation of profile paths—if you point it at a non-existent directory or a corrupted database, you get opaque errors instead of actionable messages.

Verdict

Use chromedb if you're building macOS-specific automation that needs real user cookies without browser overhead—think CI/CD pipelines that test authenticated endpoints, penetration testing tools that harvest session tokens post-exploitation, or scrapers that need to bypass bot detection with genuine browser state. It's particularly valuable when you need both cookies and localStorage in compiled Go binaries, avoiding Python dependencies. The direct disk access approach means it works on locked browsers and leaves no process artifacts. Skip it entirely if you need cross-platform support today—the macOS-only limitation makes it unusable for most production environments. Also skip if you're already invested in browser automation frameworks; adding chromedb doesn't eliminate the need for Puppeteer if you're doing any actual browser interaction. And definitely skip if you're on Windows or Linux unless you're prepared to fork it and implement DPAPI/libsecret support yourself. For the narrow use case of macOS-only cookie extraction in Go, it's the best tool available; for everything else, you're better off with pycookiecheat or accepting the overhead of headless Chrome.