views:

1463

answers:

5

I know from this question that Firefox 3.0 and up stores its cookies in an SQLite database. My question is: can you access this database from other desktop programs in such a way that you could add a cookie?

I realize this has security implications. However, I do not want to read them at all. I want to be able to set one cookie if possible. I don't even want to overwrite a cookie. I just want to add it if it isn't there already. This is sort of a personal project I'm working on for fun.

This question is mostly language agnostic. I would prefer a solution in C#, but proof of concept in any language will suffice.

Extra credit: It would be cool to set the same cookie in Internet Explorer, too

+1  A: 

You will need to use an SQLite connector and connect to the user's cookie db file. This is located in their default profile folder and is called cookies.sqlite. Check out sqlite-manager for Firefox. You can view all the tables that Firefox uses with that.

Edit: Here is a link to a provider: System.Data.SQLite

Buggabill
I can recommend System.Data.SQLite. The documentation isn't great, but the functionality's there. It's a standard ADO.NET provider, and I just used it on a C# desktop app without problems.
Matthew Flaschen
+6  A: 

For FF3, you can access the cookies.sqlite file with any SQLite wrapper - however, check whether FF is running - it may be write-locking the file (not tested).

The database contains this:

TABLE moz_cookies (
    id INTEGER PRIMARY KEY, 
    name TEXT, 
    value TEXT, 
    host TEXT, 
    path TEXT,
    expiry INTEGER, 
    lastAccessed INTEGER, 
    isSecure INTEGER, 
    isHttpOnly INTEGER
)

Not sure about the primary key, it looks like it is a unix timestamp of when the cookie was created; expiry and lastAccessed are also unix timestamps, the rest is self-explanatory.

Try an INSERT INTO moz_cookies and see if FF becomes immediately aware of the new cookie or if it requires a restart.

Piskvor
Thank you. This is what I was looking for.
Andrew
Firefox 3.5 locks the cookie file exclusively, so this won't work any more. It's closed as WONTFIX; see https://bugzilla.mozilla.org/show_bug.cgi?id=476167
Dan Mitchell
You can still do this with FF not running (which doesn't sound too useful, I admit).
Piskvor
+1  A: 

http://sqlite.phxsoftware.com/

This is great for dealing with SQLite in .NET

McAden
A: 

Hi,

I have a problem with the solution above. I've tried that and successfully inserted a new row to the cookies table.

The problem is that once I load Firefox, the row is deleted...

What am I doing wrong?

Thanks, Shay.

Shay Friedman
A: 

Firefox 3.5 locks the cookie file exclusively so do have a solution for this. i want to get the cookies for the FF or nay browser and saving that cookies or detail and t5he seting that cookies into browser whenever the browser starts. how can i do that. i ll be very thankful Regards Monika

monika
IF you want help with this, you should open a new question (button at the top-right of every page: "Ask Question"). Asking a new question gets you on the home page immediately, and you're much more likely to get help.
Andrew