Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve cookie chunk handling via base64url+length encoding #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hf
Copy link
Collaborator

@hf hf commented Jan 31, 2025

Improves cookie chunk handling by introducing a new cookie encoding scheme that includes the length of the encoded Base64 value. It will prevent reconstructing data from stale cookies.

Due to bad uses of this package, some cookie chunks are not being properly deleted. Meaning that if a session was encoded in 3 chunks now suddenly goes down to 2 chunks, the last chunk is not being deleted. When it gets reconstructed, all the 3 chunks get concatenated and parsed. In some situations this leads to an invalid UTF-8 sequence (mainly because Base64 packs 6 bits into 8).

This PR addresses this by implementing a different Base64 encoding of the chunks. Instead of just splitting up a Base64 string into chunks, the first chunk will now contain the length of the string that follows. This will prevent a leftover chunk from being parsed as valid.

The encoding is as follows:

base64l-<length of base64 encoded string as base 36>-<base64 encoding>

The library now checks for these conditions and emits warnings to let the developer know that they have a bug in their integration.

@hf hf force-pushed the hf/fix-invalid-utf8 branch 2 times, most recently from 35f4b68 to af6e190 Compare January 31, 2025 14:54
Copy link
Member

@kangmingtay kangmingtay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to bad uses of this package, some cookie chunks are not being properly deleted.

Do we know what causes the chunks to not be properly deleted? From a DX perspective, it seems rather confusing to have to deal with knowing whether to set the encoding to base64url or base64url+length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants