Repository navigation
fix(ssh): preserve literal backslashes in quoted SSH config paths - #50411
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
splitOpenSshArguments dropped every backslash inside double quotes, so IdentityFile "C:\Users\Test User\.ssh\id_ed25519" was imported as C:UsersTest User.sshid_ed25519. Follow OpenSSH argv_split instead: a backslash is consumed only before ", ' or \, or before a space outside quotes. Every other backslash stays literal. Fixes stablyai#50410 Co-authored-by: Neil <[email protected]>
a1a5691 to
959bfb0
Compare
ELI5
When Orca read your SSH config file, it threw away backslashes inside quoted file paths. Windows paths use backslashes, so
"C:\Users\Me\.ssh\key"turned intoC:UsersMe.sshkey, and Orca looked for a key file that doesn't exist. Orca now reads backslashes the same way OpenSSH does, so the path stays correct.What Changed
splitOpenSshArgumentsinsrc/main/ssh/config/ssh-config-parser.tsdropped every backslash inside double quotes and kept the character after it.IdentityFile "C:\Users\Test User\.ssh\id_ed25519"was imported asC:UsersTest User.sshid_ed25519, andIdentityAgent "/tmp/agent\socket"as/tmp/agentsocket. Outside quotes,\and\\were not handled at all, soC:\Users\My\ Keys\\id_ed25519was cut off at the space.argv_split(misc.c). It consumes a backslash only before",'or\, or before a space outside quotes, both inside and outside quotes. Every other backslash stays literal, including a trailing one.src/main/ssh/config/ssh-config-loader.test.tscovers quoted Windows paths, escaped quotes and backslashes, and an unquoted path with\and\\. The expected values were checked against nativessh -G.Why
These parsed values are saved on imported SSH targets (SshConnectionStore sync), shown in the host picker, and used for fallback authentication when
ssh -Gcannot resolve a value. Matching OpenSSH's own escape rule fixes the root cause in the one tokenizer the importer uses. It doesn't add a separate Windows-path special case.Linked Issue
Fixes #50410
Visual Proof
N/A. This is a config-parsing change with no layout or interaction change. A differential run against native
ssh -Gstands in as before/after evidence (see Testing).Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Reproduced on origin/main: the new loader test fails with
C:UsersTest User.sshid_ed25519and/tmp/agentsocket. With this change,pnpm test src/main/ssh/config/passes 8/8.Differential check on macOS against OpenSSH_10.5p1
ssh -G -F <cfg>on 18 IdentityFile values. On main, 11 differ from ssh. With this change, 16 match, ssh rejects one as invalid, and one (/k/x\#y) still differs. That last one is a separate#comment-handling gap that main also has, so it is not a regression.Targeted oxlint, oxfmt, the anti-slop, code-quality and ast-grep gates, and the changed-code quality gate are all clean.
Platforms: macOS. The change is a pure string function, so it behaves the same on Linux and Windows.
Performance
None, because this only runs on cold main-process paths (SSH config import, host picker, route snapshot). There is no new I/O or subprocess work. Micro-benchmark, old vs new:
Risk
Level: Low
\\,\",\'and\now collapse the way OpenSSH collapses them. For example,\\serverbecomes\server.Review
The fix was compared with OpenSSH
argv_splitand verified against nativessh -G. These gaps exist on main and are out of scope here:#stops parsing anywhere outside quotes, but OpenSSH treats it as a comment only at the start of a token.Agent skill upstream boundary
Notes
Security: no new endpoints, credentials or permissions. Cross-platform: pure string parsing. SSH/remote: only affects how the local
~/.ssh/configis imported. Backwards compatibility: see Risk.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Original fix by @Afloat16 in #50411