Firefox cookies & wget
Many websites use cookies to validate a user once they have logged in, and then allow further access to the rest of the website beyond the login page.
Sometimes you want to script access to certain pages using tools such as wget, and given that wget can use (and save) cookies, it can be convenient to take cookies from a working browser session, feed them in to wget, and allow the script to do its job without having to work out how to get it to log in for itself (although this can also be an interesting, and/or useful, exercise in its own right).
Wget uses a cookie file in Netscape format:
Field | Type | Description |
---|---|---|
Host | String | The hostname the cookie belongs to |
Subdomains | Boolean | Whether the cookie is allowed to be used by subdomains |
Path | String | The path the cookie relates to |
Secure | Boolean | Whether the cookie may only be transferred over HTTPS |
Expiry | Integer | Unix epoch timestamp when the cookie expires (0 for never) |
Name | String | The name of the cookie |
Value | String | The value of the cookie |
Firefox (at least, adequately recent versions) stores its cookies in SQLite, so it's handy to have a way of converting from one to the other.
The SQLite table is called moz_cookies and the schema for it is:
CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, originAttributes TEXT NOT NULL DEFAULT '', name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, originAttributes)); CREATE INDEX moz_basedomain ON moz_cookies (baseDomain, originAttributes);
Firefox's SQLite database file is stored at ~/.mozilla/firefox/*.default/cookies.sqlite and you can interrogate the contents using the sqlite3 binary (if it's not already installed on your machine, it's provided by the sqlite3 Debian/Devuan package).
Here's a command which will generate a Netscape-format cookie file from the SQLite database:
sqlite3 -separator $'\t' ~/.mozilla/firefox/*.default/cookies.sqlite "select host, case substr(host,1,1)='.' when 0 then 'FALSE' else 'TRUE' end, path, case isSecure when 0 then 'FALSE' else 'TRUE' end, expiry, name, value from moz_cookies where host like '%domain'"
Replace domain with the trailing part of the website you want to extract cookies for (eg: santander.co.uk).
The result should be similar to (tab-separated fields):
business.santander.co.uk | FALSE | / | TRUE | 1604639593 | ss_cookie | 714f080774e8e24e9e742cdaf1a03ade |
business.santander.co.uk | FALSE | / | TRUE | 1636089193 | SanUK_ID | FredBloggs |
business.santander.co.uk | FALSE | / | TRUE | 1636089248 | deviceTokenCookie | PMV6BKRYTlRlXiC2Xrtfkw4ZOEc3pZj66rocfsYmSO40cqlJCHQvuuSuwBRZtFVtrqaJLdBRPYV4RsNXBUrPI1Qnadug%253D%253D |
business.santander.co.uk | FALSE | / | TRUE | 1636089248 | deviceTokenFSO | PMV6BKRYTlRlXiC2Xrtfkw4ZOEc3pZj66rocfsYmSO40cqlJCHQvuuSuwBRZtFVtrqaJLdBRPYV4RsNXBUrPI1Qnadug%253D%253D |
.business.santander.co.uk | TRUE | / | FALSE | 1612330542 | s_nr | 1604554542535-New |
Go up
Return to main index.