-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Ignore illegal response header #2439
Conversation
lib/puma/const.rb
Outdated
@@ -239,5 +239,11 @@ module Const | |||
# Mininum interval to checks worker health | |||
WORKER_CHECK_INTERVAL = 5 | |||
|
|||
# Illegal character in the key or value of response header | |||
ILLEGAL_HEADER_KEY_REGEX = /[\u0000-\u0025|#{Regexp.escape('"(),/:;<=>?@[]{}')}]/.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe Regexp.escape('"(),/:;<=>?@[]{}')
can be extracted to improve readibility?
ILLEGAL_HEADER_CHAR_REGEX = Regexp.escape('"(),/:;<=>?@[]{}').freeze
ILLEGAL_HEADER_KEY_REGEX = /[\u0000-\u0025|#{ILLEGAL_HEADER_CHAR_REGEX}]/.freeze
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, maybe add another constant for it 👍
079acc6
to
e26656f
Compare
e26656f
to
c53d561
Compare
Labeling |
This branch, hello.sh:
This branch, many_long_headers.sh:
|
Master branch, hello.sh:
Master branch, many_long_headers.sh:
|
Maybe a ~10% reduction in the headers benchmark throughput, but that could be measurement error. |
I want to come back to this PR again just to a final security/correctness review, but it looks fine to me. |
Thanks for checking! I have also run the same script on my machine, and I find the reduction is around 20%. master branch, hello.sh:
master branch, many_long_headers.sh
this branch, hello.sh
this branch, many_long_headers.sh:
|
OK, I thought about it and I think these changes are worth it. Technically, I would say Puma is not responsible for making sure that the response object conforms to the RACK spec. Most of the time people should use Rack::Lint to ensure this conformance. However, in these cases re: headers, not conforming to the spec can be abused by malicious actors, as we've seen. I think this change proactively closes possible security holes or mistakes in apps, so I think it's worth it. I'm going to delay merge until 5.1, because this may break people's (admittedly bad and non-conformant) apps. |
I would also say this closes #2137. |
Description
Continue #2137 and solve bugs find in #2413 .
This PR will add the following feature:
Status
or start withrack.
Code change:
illegal_header_key?
andillegal_header_value?
to check the header.possible_header_injection?
should be replaced with the above new feature. (please double-check this)Your checklist for this pull request
[changelog skip]
or[ci skip]
to the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.