Skip to content

It would be neat to store non-string data in a private cookie #2963

@mcclure

Description

@mcclure

What's missing?

So: Cookies are strings. Rocket's system for inserting and extracting cookies has you reading and writing explicitly the exact strings that will go in the cookie.

However, add_private/get_private are non-explicit. When I read or write a private cookie, the string is not being written literally but rather encrypted.

I have a cookie I write which is, locally, a 64-bit integer. In order to write it to a cookie, I have to convert it to decimal or base64 or something. But I'm using a private cookie. The private cookie, after it encrypts, logically must be base64ing itself (or something).

Why can't I store arbitrary binary data, such as a 64-bit int, in a private cookie?

Ideal Solution

I'm not actually sure what the most Rusty way to communicate the data to get_cookie is. Vec instead of str I guess? Right now add_private uses Cookie<'a> so it might be necessary to either create a PrivateCookie<'a> which supports a broader range of Froms, or add more capabilities to Cookie<'a>.

Why can't this be implemented outside of Rocket?

It doesn't appear to be possible to use the private cookie encryption except through add_private/get_private.

Are there workarounds usable today?

I don't like my workaround as much (base64 then encrypt) because I think that this will result in a longer final encrypted string than encrypting the underlying bytes. That's not a meaningful issue if my cookie is an int64, but for longer cookies it could be.

Alternative Solutions

No response

Additional Context

Is this maybe actually possible already and I'm just missing how?

System Checks

  • I do not believe that this feature can or should be implemented outside of Rocket.
  • I was unable to find a previous request for this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedAn accepted request or suggestionrequestRequest for new functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions