josevalim

josevalim

Creator of Elixir

Cookie security fixes for Plug

Hello everyone,

A vulnerability has been disclosed to Plug. All applications that set cookies based on user input is vulnerable. The vulnerability affects code in the following format:

put_resp_cookie(conn, "username", conn.params["username"])
put_resp_cookie(conn, conn.params["username"], "valid")

In the code above, one of the cookie key or value is set based on user input, which may allow an attacker to set arbitrary headers.

We have released new Plug versions v1.0.6, v1.1.9, v1.2.5 and v1.3.5. If you can’t upgrade immediately, we also include fixes you can directly add to your applications.

  • Versions affected: v1.3.4 and early, v1.2.4 and earlier, v1.1.8 and earlier, v1.0.5 and earlier
  • Versions fixed: v1.3.5+, v1.2.5+, v1.1.9+, v1.0.6+
  • Reporter: Griffin Byatt (@griffinbyatt)

Workarounds

The Plug documentation has always included the following advice in the put_resp_cookie documentation:

The cookie value is not automatically escaped. Therefore, if you want to store values with comma, quotes, etc, you need to explicitly escape them or use a function such as Base.encode64 when writing and Base.decode64 when reading the cookie.

If you are following the advice above, you are safe.

If you can’t upgrade immediately, we recommend encoding and decoding the value, per above, or at least make sure characters such as new lines carriage returns, commas and semi-colons are not present on the cookie value.

For example, instead of:

put_resp_cookie(conn, "username", conn.params["username"])

You may write:

username = conn.params["username"]
if String.contains?(username, ["\r", "\n", ";", ","]), do: raise "no donut for you"
put_resp_cookie(conn, "username", username)

End of life for Plug v1.0.x

We are also announcing the end-of-life support for Plug v1.0.x. If you are running on Plug v1.0, please update to more recent versions. We have updated the README to list all supported versions.

Thanks

We want to thank Griffin Byatt for reporting this vulnerability.

Most Liked

dimitarvp

dimitarvp

Awesome work. We’re very grateful that you guys are on top of these!

griffinbyatt

griffinbyatt

I can’t speak to the broader security policy, but fwiw I’ve been applying for CVEs. They’re just taking forever to be approved :slight_smile:

Where Next?

Popular in News Top

Elixir
Release: Release v1.13.1 · elixir-lang/elixir · GitHub 1. Bug fixes Elixir [Code] Do not show code snippets in SyntaxError and TokenMis...
New
josevalim
Elixir v1.4.5 has been released with fixes for those interested in running Erlang/OTP 20: https://github.com/elixir-lang/elixir/releases/...
New
Elixir
1. Enhancements Elixir [Code] Add :emit_warnings for Code.string_to_quoted/2 [File] Add :offset option to File.stream!/2 [Kernel] Auto i...
New
Elixir
Release: https://github.com/elixir-lang/elixir/releases/tag/v1.10.3 1. Bug fixes Elixir [Code] Return [{mod, bin}] from Code.compile_fi...
New
josevalim
Hi everyone, We have just released v1.7.0-rc.0. The CHANGELOG and precompiled files are here: https://github.com/elixir-lang/elixir/rel...
New
josevalim
Hello everyone, I would like to propose the addition of the Registry project to Elixir: https://github.com/elixir-lang/registry The...
New
Elixir
1. Bug fixes Logger [Logger.Translator] Fix logger crash when :gen_statem’s format_status/2 returns non-tuple Mix [mix deps.get] Fix r...
New
Elixir
Release: https://github.com/elixir-lang/elixir/releases/tag/v1.10.0 Support for Erlang/OTP 21+ Elixir v1.10 requires Erlang/OTP 21+, all...
New
Elixir
Release: Release v1.12.0-rc.0 · elixir-lang/elixir · GitHub Note: this is a release candidate. Please try it out and give us feedback! G...
New
josevalim
Elixir v1.5.0-rc.0 has been released. This is a release candidate for the upcoming Elixir v1.5. It includes bug fixes, enhancements and...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement