Skip to content

Commit

Permalink
Validate cookie headers
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Apr 17, 2017
1 parent aff88b6 commit 8857f8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/plug/conn.ex
Expand Up @@ -990,6 +990,7 @@ defmodule Plug.Conn do
"cookie named #{inspect key} exceeds maximum size of 4096 bytes"
end
defp verify_cookie!(cookie, _key) do
validate_header_value!(cookie)
cookie
end

Expand Down
8 changes: 8 additions & 0 deletions test/plug/conn_test.exs
Expand Up @@ -605,6 +605,14 @@ defmodule Plug.ConnTest do
end
end

test "put_resp_cookie/4 raises on new line" do
assert_raise Plug.Conn.InvalidHeaderError, fn ->
conn(:get, "/")
|> put_resp_cookie("foo", "bar\nbaz")
|> send_resp(200, "OK")
end
end

test "put_resp_cookie/4 is secure on https" do
conn = conn(:get, "https://example.com/")
|> put_resp_cookie("foo", "baz", path: "/baz")
Expand Down

0 comments on commit 8857f8a

Please sign in to comment.