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

Fix crash on invalid rails6-format cookie #1

Draft
wants to merge 2 commits into
base: rails-6
Choose a base branch
from

Conversation

guisehn
Copy link

@guisehn guisehn commented Dec 13, 2024

When providing an invalid cookie in Rails 6 format (with 3 parts), MessageEncryptor.authenticate_and_decrypt/2 would return {:ok, :error} instead of {:error}, which would crash on:

Request: GET /
** (exit) an exception was raised:
    ** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an iodata term

        :erlang.iolist_to_binary(:error)
        (jason 1.3.0) lib/jason.ex:69: Jason.decode/2
        (plug_rails_cookie_session_store 2.0.0) lib/plug_rails_cookie_session_store.ex:171: PlugRailsCookieSessionStore.decode/2
        (plug 1.13.6) lib/plug/session.ex:78: anonymous fn/5 in Plug.Session.fetch_session/1
        (plug 1.13.6) lib/plug/debugger.ex:287: Plug.Debugger.maybe_fetch_session/1
        (plug 1.13.6) lib/plug/debugger.ex:187: Plug.Debugger.render/6
        (plug 1.13.6) lib/plug/debugger.ex:162: Plug.Debugger.__catch__/5

We fixed to return just :error in that case, which gracefully falls back to an empty session.

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