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

Compatibility issue with plug_crypto 2.0.0 #1184

Closed
leolaudouard opened this issue Nov 9, 2023 · 3 comments
Closed

Compatibility issue with plug_crypto 2.0.0 #1184

leolaudouard opened this issue Nov 9, 2023 · 3 comments

Comments

@leolaudouard
Copy link

We upgraded plug to 1.15.1, which landed wth plug_crypto 2.0.0, and we have this error, using session cookie plug.

16:41:06.357 [error] #PID<0.372.0> running Testo.Router (connection #PID<0.371.0>, stream id 1) terminated
Server: localhost:4040 (http)
Request: GET /testo
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Plug.Crypto.MessageEncryptor.encrypt/4
        (plug_crypto 2.0.0) lib/plug/crypto/message_encryptor.ex:36: Plug.Crypto.MessageEncryptor.encrypt(<<131, 116, 0, 0, 0, 1, 109, 0, 0, 0, 5, 102, 108, 97, 115, 104, 104, 2, 100, 0, 4, 116, 111, 116, 111, 100, 0, 4, 116, 105, 116, 105>>, "A128GCM", <<201, 153, 215, 221, 133, 125, 182, 6, 55, 108, 238, 58, 253, 163, 219, 175, 191, 227, 150, 182, 73, 235, 71, 160, 82, 194, 25, 94, 144, 218, 180, 191, 173, 24, 158, 25, 178, 217, 174, 67, 48, 13, 190, 174, 99, 229, 238, 104, 236, 255, ...>>, <<201, 86, 89, 65, 230, 208, 26, 150, 158, 231, 82, 238, 121, 234, 138, 145, 119, 212, 80, 99, 230, 136, 73, 251, 22, 106, 64, 136, 50, 138, 57, 202, 6, 29, 0, 103, 128, 83, 156, 40, 132, 224, 0, 186, 186, 216, 100, 213, 225, 214, ...>>)
        (plug 1.15.1) lib/plug/session.ex:96: anonymous fn/3 in Plug.Session.before_send/2
        (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (plug 1.15.1) lib/plug/conn.ex:1836: Plug.Conn.run_before_send/2
        (plug 1.15.1) lib/plug/conn.ex:441: Plug.Conn.send_resp/1
        (plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:12: Plug.Cowboy.Handler.init/2
        (cowboy 2.10.0) testo/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.10.0) testo/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3

You can reproduce the issue by starting this application:

https://github.com/leolaudouard/plug_issue_example

iex -S mix & then curl localhost:4040/testo

Here is the commit where I add the session cookie, maybe I missed something in the docs:

leolaudouard/plug_issue_example@35d2bb3

@josevalim
Copy link
Member

Your key length is incompatible. Remove it or set it to 32. :) This means you will log out users once you do a new deploy, so please plan accordingly!

@josevalim josevalim closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2023
@leolaudouard
Copy link
Author

Thanks for the quick answer @josevalim 🙏

What is the constraint? Max length is 32?

I suppose this example should be updated: https://github.com/elixir-plug/plug/blob/main/lib/plug/session/cookie.ex#L62

@pablopen
Copy link

pablopen commented Apr 2, 2024

Hi @josevalim , thanks for your work!

I've found a similar issue when updating the library while using a :key_length of 64 instead of 32 in the Plug.Session.COOKIE.

Should this value still and option when the only valid value is 32? Is listed in the documents here https://hexdocs.pm/plug/Plug.Session.COOKIE.html

Looks like this option is incompatible with plug_crypto's Plug.Crypto.MessageEncryptor.encrypt

Thanks for your time

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

No branches or pull requests

3 participants