Ignore illegal response header (#2439)#5
Open
MitchLewis930 wants to merge 1 commit intopr_055_beforefrom
Open
Conversation
* Ignore illegal response header
Greptile OverviewGreptile SummaryThis PR implements validation to ignore illegal response headers according to the Rack specification. The changes prevent HTTP header injection attacks by filtering out headers with illegal characters and banned keys. Key Changes:
Issue Found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Rack Application
participant Server as Puma Server
participant Request as Request Handler
participant Client as HTTP Client
App->>Server: Return [status, headers, body]
Server->>Request: Process response headers
alt Early Hints Flow
Request->>Request: str_early_hints(headers)
loop For each header
Request->>Request: Check illegal_header_key?(k)
alt Key is illegal
Request->>Request: Skip header
else Key is valid
Request->>Request: Check illegal_header_value?(v)
alt Value is illegal
Request->>Request: Skip header line
else Value is valid
Request->>Client: Send header in 103 response
end
end
end
end
alt Regular Response Flow
Request->>Request: str_headers(env, status, headers)
loop For each header
Request->>Request: Check illegal_header_key?(k)
alt Key is illegal
Request->>Request: Skip header
else Key is valid
Request->>Request: Check k.downcase against special cases
alt Matches BANNED_HEADER_KEY (rack.*, status)
Request->>Request: Skip header
else content-length
Request->>Request: Check illegal_header_value?(vs)
alt Value is illegal
Request->>Request: Skip header
else Value is valid
Request->>Request: Store content_length
end
else Other headers
Request->>Request: Check illegal_header_value?(v)
alt Value is illegal
Request->>Request: Skip header line
else Value is valid
Request->>Client: Write header to response
end
end
end
end
Request->>Client: Send complete response
end
|
| ILLEGAL_HEADER_VALUE_REGEX = /[\000-\037]/.freeze | ||
|
|
||
| # Banned keys of response header | ||
| BANNED_HEADER_KEY = /rack.|status/.freeze |
There was a problem hiding this comment.
Unescaped dot in regex pattern - the dot in rack. matches any character instead of literal period. Headers like rackx or rack5 would incorrectly be banned. Escape the dot: /rack\.|status/
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/puma/const.rb
Line: 248:248
Comment:
Unescaped dot in regex pattern - the dot in `rack.` matches any character instead of literal period. Headers like `rackx` or `rack5` would incorrectly be banned. Escape the dot: `/rack\.|status/`
How can I resolve this? If you propose a fix, please make it concise.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR_055