delete cookies which have not been accessed in the last x days

3

0

Using Firefox. I would like to get rid of "obsolete" cookies. By "obsolete" I mean cookies which have not been accessed by any website in the last x days.

I have searched high and low but I have not found how to do that. What I have found is, among others:

  • restrict the lifetime of all cookies (about:config -> network.cookie.lifetimePolicy).
  • whitelist or blacklist domains (firefox preferences -> privacy -> cookie exceptions).
  • delete all cookies from the last x hours (firefox history -> clear recent history).

None of that is what I want.

I want to delete all cookies which have not been accessed by any website in the last x days.

lesmana

Posted 2012-01-04T16:06:25.163

Reputation: 14 930

I used this request to show the latest cookies select datetime(lastAccessSec , 'unixepoch', 'localtime') as "lastAccessTime", * from (SELECT lastAccessed/1000000 as "lastAccessSec", * FROM moz_cookies order by lastAccessed desc LIMIT 50). It runs from SQLite firefox manager. – Val – 2014-07-22T14:57:34.913

1Most likely, an extension is needed for this. – Hello71 – 2012-01-04T16:12:32.437

Not sure if this accomplishes what you want, but I have Firefox to not automatically accept cookies, and instead am prompted when cookies try to install. In the prompt dialog box, I choose to store the cookie as a "session" cookie rather than a "standard" cookie. – sawdust – 2012-01-04T22:50:49.403

Answers

1

The Cookie Time extension can be configured to automatically delete cookies that haven't been used for a specified time (expired). It also has a separate setting to force expire / delete all cookies that are beyond a specified age.

Cookie Time configuration screenshot

galacticninja

Posted 2012-01-04T16:06:25.163

Reputation: 5 348

1

I did some research.

  1. Cookies are stored in the cookies.sqlite file in the firefox profile directory.
  2. The file is a sqlite database.
  3. The timestamp of the last access is stored in the lastAccessed column in the moz_cookies table.
  4. The format of lastAccessed is some PRTime format, which is basically the unix epoch time with microseconds.

The following query will list every cookie which has not been accessed in the last 14 days.

select host, name from moz_cookies
where lastaccessed < strftime('%s000000', 'now', '-14 days')
order by lastaccessed;

I just learned some SQL for this, so it might very well be that this query can be done better.

The following query will delete all those cookies.

delete from moz_cookies
where lastaccessed < strftime('%s000000', 'now', '-14 days');

Here is a quick and dirty shell script which does the job. You will need the sqlite3 command installed on your system.

#!/bin/sh

DAYS="14"

SELECT="select host, name"
DELETE="delete"
FROM="from moz_cookies"
OBSOLETE="strftime('%s000000', 'now', '-$DAYS days')"
WHERE="where lastaccessed < $OBSOLETE"
ORDER="order by lastaccessed"

SELECTQUERY="$SELECT $FROM $WHERE $ORDER;"
DELETEQUERY="$DELETE $FROM $WHERE;"

printf '%s\n' "$SELECTQUERY" | sqlite3 cookies.sqlite

lesmana

Posted 2012-01-04T16:06:25.163

Reputation: 14 930

What is the '%s000000' format? I see that SELECT datetime(strftime('%s000000','now'), 'unixepoch', 'localtime') prints extreemly wiered negative time, -1413-03-01 15:07:12, whereas '%s' is fine, it produces 2014-07-22 16:01:17, which is really now. At the same time, I see that firefox uses the wierd time format. What is that? – Val – 2014-07-22T14:03:30.700

Ok, 000000 just means that firefox stores millions of seconds instead of seconds. So, if I want to translate the firefox time into standard epoch date (%s stands for the num of seconds since 1970), I can just divide the firefox date by 1000000. This helped me to realize this, http://support.mozilla.org/en-US/questions/972178#answer-482511

– Val – 2014-07-22T14:47:58.537