fix: strip port from pasted URLs, sanitize RNode/UDP hosts#537
fix: strip port from pasted URLs, sanitize RNode/UDP hosts#537torlando-tech merged 2 commits intomainfrom
Conversation
…vel stripping Address Greptile review feedback on #533: - Strip trailing :port from hostnames (e.g. "example.com:8080" → "example.com") - Use cleaned values from validateHostname() in RNode TCP and UDP entityToConfig branches - Strip http:// and https:// in UI text field onValueChange handlers for immediate feedback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR enhances hostname/IP validation by stripping port numbers from user input (e.g.,
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: ce385b7 |
Add IPV6_REGEX check before port-stripping to prevent corrupting IPv6 addresses like "2001:db8::1" where the trailing ":1" looks like a port number. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| // Strip trailing :port (e.g. "example.com:8080" → "example.com") | ||
| // but not from IPv6 addresses which use colons extensively | ||
| if (!cleaned.startsWith("[") && !IPV6_REGEX.matches(cleaned) && cleaned.matches(Regex("^.+:\\d+$"))) { | ||
| cleaned = cleaned.substringBeforeLast(":") | ||
| } |
There was a problem hiding this comment.
Bug: The IPV6_REGEX does not match compressed IPv6 addresses, causing validateHostname to incorrectly truncate valid addresses by treating part of the address as a port number.
Severity: CRITICAL
Suggested Fix
Update the IPV6_REGEX in ValidationConstants.kt to a more comprehensive pattern that correctly validates all standard IPv6 address formats, including compressed notation (e.g., 2001:db8::1). Consider using a well-vetted, standard regular expression for IPv6 validation to cover all edge cases.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location:
app/src/main/java/com/lxmf/messenger/util/validation/InputValidator.kt#L295-L299
Potential issue: The regular expression `IPV6_REGEX` fails to match compressed IPv6
addresses that use `::` notation (e.g., `2001:db8::1`). When `validateHostname` is
called with such an address, the check `!IPV6_REGEX.matches(cleaned)` incorrectly
returns `true`. This, combined with other conditions, triggers logic that mistakenly
identifies the last segment of the IPv6 address as a port number. As a result, the
function incorrectly truncates the address, for example, turning `2001:db8::1` into the
invalid address `2001:db8:`. The existing tests do not cover compressed IPv6 formats,
which is why this issue was not caught.
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Follow-up to #532, addressing Greptile review feedback:
:portfrom hostnames (e.g.http://example.com:8080→example.com)validateHostname()in RNode TCP and UDPentityToConfig()branches (previously discarded)http://andhttps://in UI text fieldonValueChangehandlers for immediate visual feedbackTest plan
http://example.com:8080in TCP host field, verify it becomesexample.com🤖 Generated with Claude Code