[ISSUE #10692] Tolerate malformed HAProxy port values - #10693
Conversation
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot
PR #10693: [ISSUE #10692] Tolerate malformed HAProxy port values
Scope: proxy module — HAProxy message forwarding
Changes Overview
- Adds
parsePort(String)utility that safely parses port values, returningnullon invalid input (non-numeric, empty, out of 0-65535 range) - Replaces 4 direct
Integer.parseInt()calls inbuildHAProxyMessagewith the safe parser - On parse failure,
buildHAProxyMessagereturnsnull(consistent with existing unavailable-data path) - Test: adds coverage for valid/invalid/out-of-range ports, replaces
assertwith JUnit assertions
Assessment
Correctness ✅
- Defensive fix prevents
NumberFormatExceptionfrom propagating up the HAProxy forwarding path - Port range validation (0-65535) is a good addition beyond just catching parse errors
- Null return is consistent with the existing pattern for unavailable HAProxy data
Tests ✅
- Good coverage of edge cases (non-numeric, out-of-range)
- Replacing
assertwith JUnit assertions is correct —assertrequires-eaJVM flag which is not guaranteed in all test runners
Compatibility ✅
- No public API changes
- Behavior change is intentional: malformed ports now silently drop instead of throwing
Suggestion
One minor suggestion — consider adding a log.warn() or log.debug() when port parsing fails in parsePort(). Silently returning null makes production debugging harder if a misconfigured HAProxy starts sending malformed ports. Something like:
private static Integer parsePort(String value) {
if (value == null || value.isEmpty()) {
return null;
}
try {
int port = Integer.parseInt(value);
if (port < 0 || port > 65535) {
log.warn("Parsed port value out of range: {}", value);
return null;
}
return port;
} catch (NumberFormatException e) {
log.warn("Failed to parse port value: {}", value);
return null;
}
}This is optional and can be a follow-up. The core fix is solid.
Overall: LGTM 👍 — clean, focused defensive fix with appropriate test coverage.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #10693 +/- ##
=============================================
- Coverage 48.32% 48.27% -0.05%
+ Complexity 13512 13507 -5
=============================================
Files 1380 1380
Lines 101091 101142 +51
Branches 13101 13108 +7
=============================================
- Hits 48851 48831 -20
- Misses 46279 46321 +42
- Partials 5961 5990 +29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Addressed the Codecov patch coverage gap in the latest commit.\n\nChanges added coverage for:\n- local channel destination port parse failure\n- PROXY_PROTOCOL attribute path with valid ports\n- PROXY_PROTOCOL source and destination malformed port values\n- port range boundaries and out-of-range values\n\nI also tightened |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review)
PR #10693: [ISSUE #10692] Tolerate malformed HAProxy port values
Re-review scope: New commit b57f00f — "Cover HAProxy port parsing branches"
Changes Since Last Review
- Added
log.warn()inparsePort()for both out-of-range and unparseable ports — addresses the suggestion from the previous review - Added comprehensive test coverage for the HAProxy port parsing branches (valid, invalid, out-of-range)
Assessment
Correctness — The logging addition is clean and does not change the control flow.
Tests — Good branch coverage for the port parsing utility.
Overall: LGTM — Feedback addressed, solid fix.
Automated re-review by github-manager-bot
|
[P1] Please avoid failing open when a malformed HAProxy port is present.
That can replace the real client address with the proxy address downstream and affect source-IP ACLs, rate limiting, tenant attribution, and audit logs. Please distinguish "metadata absent" from "metadata present but invalid" and reject/close the latter connection (or propagate an explicit failure) rather than silently continuing. Please add regression tests asserting that malformed source and destination ports do not call |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review)
PR #10693: [ISSUE #10692] Tolerate malformed HAProxy port values
Re-review trigger: New maintainer feedback from @fuyou001 (2026-07-30)
Maintainer Feedback Summary
@fuyou001 raised a P1 security concern: buildHAProxyMessage now returns null for both "metadata absent" and "metadata present but invalid" cases. Since forwardHAProxyMessage treats null as "nothing to forward" and continues with ctx.fireChannelRead(msg), a connection with malformed PROXY metadata will silently proceed to the backend without a PROXY header — potentially replacing the real client address with the proxy address.
Assessment
The concern is valid and important. The parsePort method correctly validates port range (0–65535) and catches NumberFormatException, but the null return conflates two semantically different conditions:
- No PROXY metadata available → legitimate case, skip forwarding
- PROXY metadata present but malformed → should reject/close the connection
The current code path allows case 2 to fall through to ctx.fireChannelRead(msg), which can affect source-IP ACLs, rate limiting, tenant attribution, and audit logs downstream.
Suggested Fix Direction
- Distinguish the two cases: e.g., throw a specific exception or return a sentinel for "invalid metadata" vs. "no metadata"
- In
forwardHAProxyMessage, catch the "invalid metadata" case and close/reject the connection rather than continuing - Add regression tests asserting malformed ports do NOT call
ctx.fireChannelReadand do NOT forward traffic without the PROXY header
Status
No new commits since the maintainer feedback. Awaiting author response.
Automated review by github-manager-bot
|
Addressed the malformed PROXY metadata rejection coverage in Changes:
Local verification passed: |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Review by github-manager-bot (Re-review after new commits)
PR #10693: [ISSUE #10692] Tolerate malformed HAProxy port values
Re-review trigger: New commits pushed on Jul 31 (after previous review on Jul 31 00:36)
Previous P1 Concern Resolution
The previous review raised a P1 security concern: buildHAProxyMessage returned null for both "no metadata" and "invalid metadata", allowing malformed PROXY connections to silently proceed without a PROXY header.
✅ Fully resolved. The new commits introduce a clean separation:
InvalidHAProxyMetadataException— dedicated exception for malformed PROXY protocol metadata (missing/blank/invalid addresses and ports in the proxy protocol attribute path)channelReadproperly distinguishes the two cases:InvalidHAProxyMetadataException→ReferenceCountUtil.release(msg)+ctx.close()— connection rejected, no traffic forwardednullreturn frombuildHAProxyMessage(fallback path with invalid channel port) → still skips forwarding, which is correct for the "no PROXY metadata" case
- No silent bypass — malformed PROXY metadata can no longer reach
ctx.fireChannelRead(msg)
Code Quality
- Port validation:
parsePortvalidates range 0-65535 and catchesNumberFormatException✓ - Proxy protocol validation:
parseProxyProtocolPort,validateProxyProtocolAddress,validateProxyProtocolPortthrow on invalid input ✓ - Resource safety:
ReferenceCountUtil.release(msg)in exception paths prevents memory leaks ✓ - Pipeline safety:
ctx.pipeline().context(this) != nullcheck before handler removal ✓ - Tests: Comprehensive coverage including invalid ports, missing addresses, and channelRead behavior ✓
Verdict
Approve. The P1 security concern is fully addressed with a clean exception-based approach. The two semantic cases (no metadata vs. invalid metadata) are now properly distinguished.
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Defensive fix with proper validation and test coverage. LGTM.
Automated review by github-manager-bot
Which Issue(s) This PR Fixes
Fixes #10692
Brief Description
HAProxyMessageForwarder.buildHAProxyMessagepreviously parsed source and destination ports withInteger.parseIntdirectly, both from proxy protocol attributes and from channel remote/local addresses. A malformed port could throwNumberFormatExceptionand fail HAProxy message forwarding with a runtime parsing exception.This PR adds safe port parsing. Invalid port values now make
buildHAProxyMessagereturnnull, matching the existing behavior for unavailable HAProxy message data, while valid port values keep the existing behavior.The test also replaces Java
assertstatements with JUnit assertions inHAProxyMessageForwarderTest.How Did You Test This Change?
mvn -pl proxy -Dtest=HAProxyMessageForwarderTest -DfailIfNoTests=false testResult:
BUILD SUCCESS,Tests run: 3, Failures: 0, Errors: 0, Skipped: 0.