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

Make illegal header matching more stringent #2510

Merged
merged 1 commit into from Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions History.md
Expand Up @@ -10,6 +10,7 @@
* Bugfixes
* Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
* Fix compiler warnings, but skipped warnings related to ragel state machine generated code ([#1953])
* Fix over eager matching against banned header names ([#2510])

## 5.1.0 / 2020-11-30

Expand Down Expand Up @@ -1680,6 +1681,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
* Bugfixes
* Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)

[#2510]:https://github.com/puma/puma/pull/2510 "PR by @micke"
[#2472]:https://github.com/puma/puma/pull/2472 "PR by @ccverak, merged 2020-11-02"
[#2438]:https://github.com/puma/puma/pull/2438 "PR by @ekohl, merged 2020-10-26"
[#2406]:https://github.com/puma/puma/pull/2406 "PR by @fdel15, merged 2020-10-19"
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/const.rb
Expand Up @@ -246,6 +246,6 @@ module Const
ILLEGAL_HEADER_VALUE_REGEX = /[\x00-\x08\x0A-\x1F]/.freeze

# Banned keys of response header
BANNED_HEADER_KEY = /rack.|status/.freeze
BANNED_HEADER_KEY = /\A(rack\.|status\z)/.freeze
end
end
15 changes: 15 additions & 0 deletions test/test_response_header.rb
Expand Up @@ -87,11 +87,26 @@ def test_status_key
assert_ignore_header("Status", "500")
end

# The header key can contain the word status.
def test_key_containing_status
server_run app: ->(env) { [200, {'Teapot-Status' => 'Boiling'}, []] }
data = send_http_and_read "GET / HTTP/1.0\r\n\r\n"

assert_match(/HTTP\/1.0 200 OK\r\nTeapot-Status: Boiling\r\n\r\n/, data)
end

# Special headers starting “rack.” are for communicating with the server, and must not be sent back to the client.
def test_rack_key
assert_ignore_header("rack.command_to_server_only", "work")
end

# The header key can still start with the word rack
def test_racket_key
server_run app: ->(env) { [200, {'Racket' => 'Bouncy'}, []] }
data = send_http_and_read "GET / HTTP/1.0\r\n\r\n"

assert_match(/HTTP\/1.0 200 OK\r\nRacket: Bouncy\r\n\r\n/, data)
end

# testing header key must conform rfc token specification
# i.e. cannot contain non-printable ASCII, DQUOTE or “(),/:;<=>?@[]{}”.
Expand Down