Implementing a cookie whitelist in Chromium

ThreadStates

I started testing the Chromium browser (the open-source project behind google chrome) a few days ago, using the chromium package in Arch's extra repository. I like it fairly well; it is noticeably faster than Firefox. One feature I miss from Firefox is the ability clear all cookies at exit except those from specific domains. So, last night I sat down to write a script to do just that in chromium.

First I located the chromium cookie file at ~/.config/chromium/<profile>/Cookies. Loading the database into sqlite, I was able to determine the cookie table schema:

> sqlite3 ~/.config/chromium/Default/Cookies
sqlite> .schema cookies
CREATE TABLE cookies (creation_utc INTEGER NOT NULL UNIQUE PRIMARY KEY,host_key TEXT NOT NULL,name TEXT NOT NULL,value TEXT NOT NULL,path TEXT NOT NULL,expires_utc INTEGER NOT NULL,secure INTEGER NOT NULL,httponly INTEGER NOT NULL,last_access_utc INTEGER NOT NULL);

I saw that host_key stores the domain that set the cookie, so all I needed to do was develop the sql statement to delete all cookies except those from domains on a whitelist. The statement looks like this:

delete from cookies where host_key not like "%<domain1>" and \
    host_key not like "%<domain2>" ;

All that was left was to wrap everything in a shell script that programmatically builds the delete statement from a whitelist. I named the script "eatcookies", and you can see it on github. I use it in a wrapper script that calls eatcookies if chromium exits cleanly.