Repository navigation
Security: Fix for HTTP request smuggling in API end-point #622
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
Open
AjayPAnand
wants to merge
7
commits into
doubtfire-lms:11.0.x
Choose a base branch
from
AjayPAnand:pr-89
base: 11.0.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a1ea9b2
fix(security): harden Puma against HTTP Request Smuggling (CVE)
8b8731c
feat(dev-infra): add nginx config for request smuggling tests
AjayPAnand d4f6eb5
Merge branch '10.0.x' into pr-86
AjayPAnand bf2e76d
Revert schema.rb to match 10.0.x
b36f0c8
Reverting schema.rb -removed enforce_feedback_before_discussed_in_cla…
AjayPAnand 7822439
Reverting schema.rb
AjayPAnand 98b4aa1
fix: resolve RuboCop offenses
AjayPAnand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -592,7 +592,7 @@ DEPENDENCIES | |
| net-smtp | ||
| oauth2 | ||
| pdf-reader | ||
| puma | ||
| puma (>= 6.4.3) | ||
| rack-cors | ||
| rails (~> 8.0) | ||
| rails-latex | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'json' | ||
|
|
||
| # | ||
| # Rejects ambiguous HTTP framing headers to reduce request smuggling risk. | ||
| # | ||
| class RequestSmugglingProtection | ||
| BAD_REQUEST_RESPONSE = [ | ||
| 400, | ||
| { 'Content-Type' => 'application/json', 'Connection' => 'close' }, | ||
| [{ error: 'Malformed request framing headers' }.to_json] | ||
| ].freeze | ||
|
|
||
| def initialize(app) | ||
| @app = app | ||
| end | ||
|
|
||
| def call(env) | ||
| return BAD_REQUEST_RESPONSE if malformed_framing_headers?(env) | ||
|
|
||
| @app.call(env) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def malformed_framing_headers?(env) | ||
| content_length = env['CONTENT_LENGTH'] | ||
| transfer_encoding = env['HTTP_TRANSFER_ENCODING'] | ||
|
|
||
| conflicting_content_length_and_transfer_encoding?(content_length, transfer_encoding) || | ||
| invalid_content_length?(content_length) || | ||
| invalid_transfer_encoding?(transfer_encoding) | ||
| end | ||
|
|
||
| def conflicting_content_length_and_transfer_encoding?(content_length, transfer_encoding) | ||
| header_present?(content_length) && header_present?(transfer_encoding) | ||
| end | ||
|
|
||
| def invalid_content_length?(content_length) | ||
| return false unless header_present?(content_length) | ||
|
|
||
| content_length.include?(',') || content_length !~ /\A\d+\z/ | ||
| end | ||
|
|
||
| def invalid_transfer_encoding?(transfer_encoding) | ||
| return false unless header_present?(transfer_encoding) | ||
|
|
||
| normalized = transfer_encoding.split(',').map(&:strip).reject(&:empty?) | ||
| normalized != ['chunked'] | ||
| end | ||
|
|
||
| def header_present?(value) | ||
| !value.nil? && !value.strip.empty? | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you remove these additions as they seem unrelated to the original security fix? the port and environment also seem to be duplicates to lines 18 and 22 in puma.rb