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
1. Enhancements Elixir [Code] Add Code.eval_quoted_with_env/4 with support for the :prune_binding option ExUnit [ExUnit.Case] Allow te...
New
josevalim
Hello everyone, This past weekend we have released Ecto v2.1.0-rc.5, hopefully the last release candidate for Ecto v2.1: https://github...
New
Elixir
1. Enhancements Elixir [JSON] Encode any JSON key to string [Kernel] Allow <<_::3*8>> in typespecs Mix [mix loadpaths] Sup...
New
josevalim
Hello everyone, We have released Elixir v1.3.3. This release has some compiler- and dialyzer-related improvements as well as some enhan...
New
Elixir
This release adds basic support for Erlang/OTP 26. When migrating to Erlang/OTP 26, keep it mind it changes how maps are stored interna...
New
ericmj
A few months back we announced on the forum that we are adding support for private packages to Hex, today we are out of beta and going li...
New
josevalim
Hi everyone, We have just released the second release candidate for the next Elixir version: v1.7.0-rc.1. The CHANGELOG and precompiled...
New
josevalim
Elixir v1.14 brings many improvements to the debugging experience in Elixir and data-type inspection. It also includes a new abstraction...
New
josevalim
Official announcement: https://elixir-lang.org/blog/2018/01/17/elixir-v1-6-0-released/ Thanks everyone who gave the release candidate a...
New
josevalim
Elixir v1.5.0-rc.1 has been released. This is the second release candidate for the upcoming Elixir v1.5. It includes bug fixes, enhance...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement