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

Crystal 1.0 support #1445

Merged
merged 2 commits into from
Mar 31, 2021
Merged

Crystal 1.0 support #1445

merged 2 commits into from
Mar 31, 2021

Conversation

jwoertink
Copy link
Member

Purpose

Update for Crystal 1.0 support

Description

The only main issue to support Crystal 1.0 is that cookie values are now more strict according to rfc6265. Crystal will raise IO::Error when setting a cookie value that contains invalid characters, so I added a nicer error that tells you which cookie is getting the error, and which characters to be on the look for.

NOTE:
This PR points all shards to master branch, but it's sort of 🐔 🥚 while everything gets updated.

@@ -117,7 +126,7 @@ describe Lucky::CookieJar do
it "raises an error if the cookie is > 4096 bytes" do
expect_raises(Lucky::CookieOverflowError) do
jar = Lucky::CookieJar.empty_jar
jar.set_raw(:overflow, "x" * (4097 - 27)) # "overflow=x...x; path=/; HttpOnly",
jar.set_raw(:overflow, "x" * 4097) # "overflow=x...x; HttpOnly",
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why there was maths here, but it wasn't throwing an exception, so I just made it the raw number because "x" * 4097 is 4097 bytes

@@ -1,6 +1,6 @@
class Lucky::CookieJar
MAX_COOKIE_SIZE = 4096
LUCKY_ENCRYPTION_PREFIX = Base64.encode("lucky") + "--"
LUCKY_ENCRYPTION_PREFIX = Base64.strict_encode("lucky") + "--"
Copy link
Member Author

Choose a reason for hiding this comment

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

Base64.encode adds a newline at the end, but newline characters are invalid cookie values.

@jwoertink jwoertink merged commit cf5b125 into master Mar 31, 2021
@jwoertink jwoertink deleted the crystal1.0 branch March 31, 2021 22:52
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.

1 participant