fix(ssh): parse ssh host string manually, clean up bugs#161
Conversation
📝 WalkthroughWalkthroughThe SSH module's URL parsing is replaced with a custom host/port parser supporting IPv6 link-local addresses with interface identifiers, SSH agent timeouts, stdin validation, and signal validation. This resolves failures when using link-local IPv6 addresses like Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
009a6b6 to
8355a07
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@internal/system/ssh.go`:
- Around line 197-208: The IPv6 handling incorrectly rejects valid unbracketed
addresses that use zero-compression (contain "::") because the code always
treats the last colon-separated token as a potential port; update the branch in
the function that uses variables s and colonCount so that if s contains "::" you
skip the port-parse check (the strconv.ParseUint on last) and immediately return
the whole s as the address (return s, "", nil); ensure the new condition is
evaluated before attempting to parse last to avoid false "IPv6 address with port
must be in brackets" errors.
🧹 Nitpick comments (1)
internal/system/ssh.go (1)
587-589: Consider bracketing IPv6 addresses in the output.For IPv6 addresses (especially with interface identifiers like
fe80::1%eth0), the current format produces ambiguous output likeuser@fe80::1%eth0:22. Usingnet.JoinHostPortwould produce the standard bracketed formatuser@[fe80::1%eth0]:22.♻️ Suggested improvement
func (s *SSHSystem) Address() string { - return fmt.Sprintf("%s@%s:%s", s.user, s.address, s.port) + return fmt.Sprintf("%s@%s", s.user, net.JoinHostPort(s.address, s.port)) }
a21d4db to
fd5c6fd
Compare
This commit moves the SSH system utilities into a separate package and adds tests for it. It now also uses the `net` package to parse and split the host:port portion of the address whenever possible, to simplify case handling, and makes the rules less strict. Bracketed IPv6 addresses are treated specially and are parsed much more strictly, but everything else relies on naive splitting. This should be tolerant enough of bad addresses and attempts it in most cases; edge cases can be handled later if they crop up.
fd5c6fd to
d60aa22
Compare
SSH host strings are not URLs. The previous code treated them as such, and this failed in the case of link-local IPV6 addresses that are bracketed and have percent signs.
This PR adds a small
user@host:portparser that behaves similarly to OpenSSH to correct this behavior, and other future SSH vs. URL disparities.It also fixes some small bugs with the SSH command system.
Closes #146.
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.