Handle malformed Forwarded host ports#12688
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 forForwarded host=with a defensive parser that supports bracketed IPv6 and validates ports. - Treats malformed
Forwardedhost/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. |
Co-Authored-By: multicode <multicode@yawk.at>
Co-Authored-By: multicode <multicode@yawk.at>
5f0fe62 to
3148bfa
Compare
|
graemerocher
approved these changes
May 29, 2026
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>
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.



Summary
Forwardedhost=values defensively instead of splitting on every colonVerification
./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 checkVersionCatalogCompatibilitygit diff --checkResolves #12687