9

I'm trying to extract FF cookie from it's database (cookies.sqlite). However, seems that only cookies with expiration date can be found there (I am searching the one that expires when session ends). I even turned the "remember open tabs" feature of FF on. I don't get it - what's the fundamental difference between them. I can see the cookie in FF UI but cannot find on the hard drive.

Any anwers appreciated.

user690954
  • 313
  • 2
  • 9

4 Answers4

6

Session cookies are stored in the sessionstore.js file.

This file is essentially a JSON object. If you parse it, look under windows[0].cookies to get an array of the session cookies.

Typically the only fields in each session cookie are {name, host, path, value}, but occasionally you see an httpOnly parameter.

alain.janinm
  • 19,951
  • 10
  • 65
  • 112
Farlan
  • 1,860
  • 2
  • 28
  • 37
  • 1
    I have a script that can extract normal cookies and session cookies too, see [export_firefox_cookies.py](https://github.com/jabbalaci/Bash-Utils/blob/master/firefox/export_firefox_cookies.py). As of 2017, I didn't find `sessionrestore.js`. I think it's replaced by `recovery.js`, which has the same structure. – Jabba May 18 '17 at 15:35
1

Farlan is correct the session cookies are stored in the sessionstore.js file. I created a module to load cookies from sqlite and this session file, available here: https://bitbucket.org/richardpenman/browser_cookie/

Example usage:

import requests
import browser_cookie
cj = browser_cookie.firefox()
r = requests.get('http://stackoverflow.com', cookies=cj)
hoju
  • 28,392
  • 37
  • 134
  • 178
  • 1
    hoju I was looking at your module. You might want to change line #138 of __init__.py to: `cookie_files = glob.glob(os.path.expanduser('~/.mozilla/firefox/*.default*/cookies.sqlite'))` The firefox profile directory on my Linux system is this: `/home/rushil/.mozilla/firefox/2391y7t8.default-1435311139613` which your code won't find. Also, the cookies that I get from cookies.sqlite file are not complete. I get more cookies from my Cookie Manager plugin in the firefox browser. And there were no more .sqlite files which had that cookies. Any ideas? – Rushil Paul Jul 03 '15 at 11:14
  • this isn't the best place to discuss bugs, so would you mind posting at the repository issues page: https://bitbucket.org/richardpenman/browser_cookie/issues/new. Seems you are using a different version of FireFox than I tested with, where cookies are handled slightly differently. – hoju Jul 05 '15 at 07:20
  • Ok I will post it there. Also, I later discovered the sessionrestore.js file which Firefox seems to delete on starting up, which contains all the session cookies (that are absent in cookies.sqlite) that expire at the end of session. So my problem is solved :-) – Rushil Paul Jul 05 '15 at 07:36
  • ah yes, if you are testing after closing FireFox then would be able to load the sessions cookies – hoju Jul 06 '15 at 09:26
  • Repository on bitbucket.org is gone (404). – hackerb9 Dec 21 '21 at 01:00
1

I was looking for the same thing and found this: http://blog.mithis.net/archives/python/90-firefox3-cookies-in-python I guess the right thing to do is to use the code to add another cookiejar backend

nakee
  • 11
  • 1
0

session cookies probably are kept in memory and deleted once the tab/browser is closed, never entering the database.

tiagoboldt
  • 2,426
  • 1
  • 24
  • 30