Skip to content

Handle malformed Forwarded host ports#12688

Merged
sdelamo merged 2 commits into
5.0.xfrom
fix-forwarded-host-port-parsing
May 29, 2026
Merged

Handle malformed Forwarded host ports#12688
sdelamo merged 2 commits into
5.0.xfrom
fix-forwarded-host-port-parsing

Conversation

@yawkat

@yawkat yawkat commented May 27, 2026

Copy link
Copy Markdown
Member

Summary

  • parse RFC 7239 Forwarded host= values defensively instead of splitting on every colon
  • ignore malformed forwarded host/port values so host resolution can fall back normally
  • cover malformed ports and bracketed/unbracketed IPv6 forwarded hosts

Verification

  • ./gradlew :micronaut-http-server:compileJava -q -x japiCmp -x checkVersionCatalogCompatibility
  • ./gradlew :micronaut-http-server-netty:test --tests io.micronaut.http.server.netty.util.DefaultHttpHostSpec -q -x japiCmp -x checkVersionCatalogCompatibility
  • ./gradlew :micronaut-http-server:test --tests io.micronaut.http.server.util.DefaultHttpHostResolverSpec -q -x japiCmp -x checkVersionCatalogCompatibility
  • ./gradlew :micronaut-http-server:spotlessCheck :micronaut-http-server-netty:spotlessCheck -q -x japiCmp -x checkVersionCatalogCompatibility
  • git diff --check

Resolves #12687

Copilot AI review requested due to automatic review settings May 27, 2026 17:49

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 pull request hardens parsing of RFC 7239 Forwarded host= values in ProxyHeaderParser to avoid exceptions on malformed input and to correctly handle bracketed IPv6 literals, allowing host resolution to fall back gracefully when the header is invalid.

Changes:

  • Replaced naive host.split(":") parsing for Forwarded host= with a defensive parser that supports bracketed IPv6 and validates ports.
  • Treats malformed Forwarded host/port values as absent (no exception; normal fallback behavior).
  • Added test coverage for malformed ports and bracketed/unbracketed IPv6 Forwarded host= values.

Reviewed changes

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

File Description
http-server/src/main/java/io/micronaut/http/server/util/ProxyHeaderParser.java Adds robust Forwarded host= parsing and safe port validation to prevent NumberFormatException and handle IPv6 correctly.
http-server-netty/src/test/groovy/io/micronaut/http/server/netty/util/DefaultHttpHostSpec.groovy Adds regression tests ensuring malformed Forwarded host/port falls back, and validates bracketed IPv6 behavior.

@yawkat yawkat added the type: bug Something isn't working label May 28, 2026
@yawkat yawkat requested a review from graemerocher May 28, 2026 05:51
yawkat and others added 2 commits May 28, 2026 05:52
Co-Authored-By: multicode <multicode@yawk.at>
Co-Authored-By: multicode <multicode@yawk.at>
Copilot AI review requested due to automatic review settings May 28, 2026 05:56
@yawkat yawkat force-pushed the fix-forwarded-host-port-parsing branch from 5f0fe62 to 3148bfa Compare May 28, 2026 05:56
@yawkat yawkat changed the base branch from 5.1.x to 5.0.x May 28, 2026 05:56

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.

@sonarqubecloud

Copy link
Copy Markdown

@sdelamo sdelamo merged commit 4bd4bce into 5.0.x May 29, 2026
15 checks passed
@sdelamo sdelamo deleted the fix-forwarded-host-port-parsing branch May 29, 2026 13:48
altro3 pushed a commit to altro3/micronaut-core that referenced this pull request Jun 6, 2026
* Handle malformed Forwarded host ports

Co-Authored-By: multicode <multicode@yawk.at>

* Tidy Forwarded host parser branches

Co-Authored-By: multicode <multicode@yawk.at>

---------

Co-authored-by: multicode <multicode@yawk.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed Forwarded host port can throw during host resolution

4 participants