Search code examples
gosession-cookies

securecookie: the value is too long when using sessions.NewFilesystemStore


I am building an app that uses sessions to store user data. For that I use the gorilla/sessions package.

The problem I encounter is that the user data I would like to store is getting bigger and bigger as the application grows.

At some point, i get that error while saving the session : securecookie: the value is too long

Here is how I build my storage :

sessions.NewFilesystemStore("", []byte("abcdef"))

How should I do to store large session data ?

Thank you for your help


Solution

  • This is heritage from the 4Kb maximum size of a browser cookie. Of course the filesystem store and probably any other store that is not the cookie store can hold large(r) session data. However, it defaults to 4Kb for some reason. To change it just do something like:

    fs := sessions.NewFilesystemStore("", []byte("mysecretkey"))
    fs.MaxLength(8192) // 8Kb is now maximum size of the session