INSERT INTO moz_cookies is not correct?

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Locked
BlackMatrix
Posts: 3
Joined: November 5th, 2013, 9:22 am

INSERT INTO moz_cookies is not correct?

Post by BlackMatrix »

Good evening.

My Application makes some login request to some servers. I want to export theses cookies to cookies.sqlite. What do I have to do that Firefox accepts these cookies? Its not working yet.

I have created a database with a table:

Code: Select all

CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, appId, inBrowserElement))


and after that I try to insert the cookies with:

Code: Select all

INSERT INTO moz_cookies (id,name,value,path,baseDomain,host,expiry) VALUES ("1","name","value","/","www.example.net","www.example.net","2147483647")


In the settings of Firefox the cookies are the same like the real ones, but my inserted cookies are not sent. What's wrong?
User avatar
DanRaisch
Moderator
Posts: 127187
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: INSERT INTO moz_cookies is not correct?

Post by DanRaisch »

Moving to Web Development.
User avatar
jscher2000
Posts: 11742
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA
Contact:

Re: INSERT INTO moz_cookies is not correct?

Post by jscher2000 »

Why not use the the API for working with cookies?

https://developer.mozilla.org/en-US/doc ... ts/Cookies
BlackMatrix
Posts: 3
Joined: November 5th, 2013, 9:22 am

Re: INSERT INTO moz_cookies is not correct?

Post by BlackMatrix »

I'm using .NET. The export ist just a small feature of my application and it shouldn't be difficult to add cookies just with SQLite and some commands. Is it really necessary to include any API? I think I forgot just a little thing for getting my cookies to be accepted by Firefox.
User avatar
Frenzie
Posts: 2135
Joined: May 5th, 2004, 10:40 am
Location: Belgium
Contact:

Re: INSERT INTO moz_cookies is not correct?

Post by Frenzie »

Does Firefox happen to be running while you do this?
Intelligent alien life does exist, otherwise they would have contacted us.
BlackMatrix
Posts: 3
Joined: November 5th, 2013, 9:22 am

Re: INSERT INTO moz_cookies is not correct?

Post by BlackMatrix »

No, Firefox is not running.
I don't understand, because the cookies you can see in the privacy tab are the same like the real ones. If I logon a webpage with my login data I get another cookie with the same name, value, host and path under the same baseDomain like the real one. But Firefox doesn't have any notice of my cookies.

I will explain a little bit more. I have tried it with the "style_cookie" of the mozillaZine board.

Firefox doesn't notices that there is correct cookie already there.

You can see it here:

Image

Both have the same baseDomain, name, value, host and path and the expiry int value is bigger than the current date.

Code: Select all

            // Creating test cookie
            Cookie cookie = new Cookie();
            cookie.Name = "style_cookie";
            cookie.Value = "null";
            cookie.Path = "/";
            string host = "forums.mozillazine.org";

            // Create cookies.sqlite
            SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder();
            sb.DataSource="cookies.sqlite";

            using (SQLiteConnection connection = new SQLiteConnection(sb.ConnectionString))
            {
                // Open cookies.sqlite connection
                connection.Open();

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    // Create table moz_cookies
                    command.CommandText = "CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, appId, inBrowserElement))";
                    command.ExecuteNonQuery();

                    // Insert test cookie
                    command.CommandText = string.Format(
                        "INSERT INTO moz_cookies (baseDomain, name, value, path, host, expiry) VALUES (\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\")",
                        host,cookie.Name,cookie.Value,cookie.Path,host, 1483739327);
                    command.ExecuteNonQuery();
                }
            }
User avatar
raxomi
Posts: 8
Joined: August 2nd, 2014, 12:02 am

Re: INSERT INTO moz_cookies is not correct?

Post by raxomi »

Remember that baseDomain must be only the domain name (ie example.com), and the host can be .example.com (will include all subdomains) or www.example.com (subdomain specific).
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Re: INSERT INTO moz_cookies is not correct?

Post by trolly »

No need to answer a two year old thread. Locking.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
Locked