fix: reject newlines in redirect locations - #19812
Open
FrankChen021 wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens RedirectFilter against HTTP response splitting by rejecting redirect Location header values that contain literal carriage return (\r) or line feed (\n) characters after the redirect URL is fully constructed.
Changes:
- Add CR/LF validation for the redirect target prior to setting the
Locationresponse header (returning HTTP 400 on invalid values). - Preserve normal redirects and percent-encoded
%0D/%0Asequences without decoding them. - Add unit tests covering normal redirects, encoded newline sequences, and literal CR/LF rejection cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| server/src/main/java/org/apache/druid/server/http/RedirectFilter.java | Rejects redirect targets containing literal CR/LF before setting the Location header. |
| server/src/test/java/org/apache/druid/server/http/RedirectFilterTest.java | Adds tests for normal redirects, encoded newline preservation, and CR/LF rejection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
FrankChen021
commented
Jul 31, 2026
FrankChen021
left a comment
Member
Author
There was a problem hiding this comment.
I have reviewed the code for correctness, edge cases, concurrency, and integration risks; no issues found.
Reviewed 2 of 2 changed files.
This is an automated review by Codex GPT-5.6-Sol
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.
What changed
Locationresponse header.%0D/%0AURL data.Why
RedirectFiltercopied a URL derived from request data directly into theLocationheader.java.net.URLpermits literal CR/LF characters, which could allow HTTP response splitting in servlet containers that do not reject them independently.Impact
Legitimate redirect targets retain their exact URL representation. Requests that would produce a raw newline in the response header are rejected before the response status or header is set.
Validation
mvn -ntp test -pl server -am -Dtest=org.apache.druid.server.http.RedirectFilterTest -Dsurefire.failIfNoSpecifiedTests=false -Pskip-static-checks -Dweb.console.skip=true -T1Cmvn -ntp test -pl server -Dtest=org.apache.druid.server.http.RedirectFilterTest -Dweb.console.skip=true -Pskip-static-checksmvn -ntp checkstyle:check -pl server -Dweb.console.skip=true