Skip to content

fix: reject newlines in redirect locations - #19812

Open
FrankChen021 wants to merge 5 commits into
apache:masterfrom
FrankChen021:agent/codeql-redirect-response-splitting
Open

fix: reject newlines in redirect locations#19812
FrankChen021 wants to merge 5 commits into
apache:masterfrom
FrankChen021:agent/codeql-redirect-response-splitting

Conversation

@FrankChen021

Copy link
Copy Markdown
Member

What changed

  • Validate the fully constructed redirect target before placing it in the Location response header.
  • Reject redirect targets containing literal carriage returns or line feeds with HTTP 400.
  • Preserve ordinary redirects and percent-encoded %0D/%0A URL data.
  • Add focused tests for normal, encoded, CR, and LF cases.

Why

RedirectFilter copied a URL derived from request data directly into the Location header. java.net.URL permits 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 -T1C
  • mvn -ntp test -pl server -Dtest=org.apache.druid.server.http.RedirectFilterTest -Dweb.console.skip=true -Pskip-static-checks
  • mvn -ntp checkstyle:check -pl server -Dweb.console.skip=true

@FrankChen021 FrankChen021 changed the title Reject newlines in redirect locations fix: reject newlines in redirect locations Jul 30, 2026
@FrankChen021
FrankChen021 marked this pull request as ready for review July 30, 2026 22:26
Copilot AI review requested due to automatic review settings July 30, 2026 22:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Location response header (returning HTTP 400 on invalid values).
  • Preserve normal redirects and percent-encoded %0D/%0A sequences 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
FrankChen021 requested a review from Copilot July 30, 2026 22:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comment thread server/src/main/java/org/apache/druid/server/http/RedirectFilter.java Dismissed

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants