securecookie decoding error

46 views
Skip to first unread message

Marcel Hauf

unread,
Jun 25, 2012, 1:31:17 PM6/25/12
to goril...@googlegroups.com
Hello,

I got a problem with the securecookie decoding. I am saving a bson.ObjectId which is converted via ObjectId.Hex() into a string as a "id" field into a session.
The *sessions.Session struct looks like this before being saved (written to the browser): &{ID: Values:map[id:4fccd621ad25b5d8554b1681] Options:0xf840130270 IsNew:true store:0xf840131960 name:}
But on the next page load, store.Get gives a "securecookie: the value could not be decoded" error. The "ID" field seems to be a valid string which should be able to be encoded, am I right?
How can I debug this deeper or much better, how can I fix this?

Thanks in advance,

Marcel Hauf

Rodrigo Moraes

unread,
Jun 25, 2012, 2:03:25 PM6/25/12
to Gorilla web toolkit
On Jun 25, 2:31 pm, Marcel Hauf wrote:
> How can I debug this deeper or much better, how can I fix this?

Can you provide a simple test case? This sounds weird, and I have no
clue what is happening there or how to reproduce it. I tried saving a
securecookie with "id": "4fccd621ad25b5d8554b1681" and it succeeded (I
wasn't surprised :).

-- rodrigo

Marcel Hauf

unread,
Jun 25, 2012, 4:36:02 PM6/25/12
to goril...@googlegroups.com
I found the problem. For some reason my SessionName variable is empty. So the name of the cookie is "". Which somehow screws up the decoding.
You can reproduce this by calling store.Get like this: session, err := store.Get(r, "")

Marcel Hauf

unread,
Jun 25, 2012, 4:41:02 PM6/25/12
to goril...@googlegroups.com
I found the reason for sessionName being empty ("").

var sessionName string

func Init(sessionName string) {
  sessionName = sessionName
}

is a very bad idea.

Rodrigo Moraes

unread,
Jun 26, 2012, 12:27:58 AM6/26/12
to Gorilla web toolkit
On Jun 25, 5:41 pm, Marcel Hauf wrote:
> I found the reason for sessionName being empty ("").

We should use a default name when it is empty. Will take a look.
Thanks for the update.

-- rodrigo
Reply all
Reply to author
Forward
0 new messages