Skip to content

fix(ssh): read single-quoted and escaped-space SSH config paths like OpenSSH - #50976

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/ssh-config-single-quotes
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/ssh-config-single-quotes

Conversation

@Pr1p

@Pr1p Pr1p commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Your ~/.ssh/config tells your computer how to reach other machines. Paths in it can contain spaces if you wrap them in quotes or put a backslash before the space. Orca read some of those lines differently from the real ssh program, so it could miss hosts or point at the wrong key file. Now Orca reads the file the same way ssh does, so the host list and key paths match what actually works.

What Changed

Before:

  • Include '~/.ssh/my configs/a' (single quotes) and Include ~/.ssh/my\ configs/b (escaped space) loaded no hosts.
  • Host 'quoted-key' was imported as the alias 'quoted-key', quotes included.
  • IdentityFile '/keys/my key' came out as '/keys/my.
  • Host team#1 was cut down to team, because any # started a comment.

After: all of these resolve the same way ssh -G resolves them.

Mechanism:

  • There were two tokenizers. splitOpenSshArguments in ssh-config-parser.ts only knew " quotes. splitQuotedArguments in ssh-config-include-expander.ts also only knew ", and it ignored \ , \\ and \'.
  • Both are replaced by one shared splitOpenSshArguments in the new src/main/ssh/config/ssh-config-arguments.ts, modeled on OpenSSH argv_split (misc.c, called from readconf.c). '...' and "..." both quote. \\, \", \' and unquoted \ are escapes. Any other backslash stays literal, so Windows paths are unchanged (fix(ssh): preserve literal backslashes in quoted SSH config paths #50411). An unquoted # starts a comment only at the start of a token, so Host team#1 and Include ~/.ssh/t#1 keep their #.
  • The shared function lives in its own file because the parser already imports the Include expander.

Why

Follow-up to #50411, which aligned backslash handling with argv_split but left out single quotes and the second tokenizer. With one shared tokenizer, Include lines can't drift from the other directives again. ssh-g-config-resolution.ts's splitIncludeArguments is intentionally left alone. It has a different contract: it returns null when it is unsure.

Linked Issue

Fixes #50975

Visual Proof

N/A. This is a config-parser change, and the only visible effect is which SSH hosts and key paths Orca imports. The before/after parser output is in Testing below.

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

  • The new case in ssh-config-loader.test.ts covers a single-quoted Include, an escaped-space Include, a single-quoted Host and IdentityFile that contain ", and team#1 followed by a trailing # comment.

    • On main it fails, and the other 8 cases pass. Main returns host 'quoted-key' and IdentityFile '/keys/my, cuts team#1 down to team, and loses both included hosts.
    • With this change it passes 9/9. All of src/main/ssh/ passes (12 files, 49 tests).
  • Ran real ssh -G -F (OpenSSH_10.5p1, macOS) on scratch configs: the Include spellings, Host 'quoted-key' x#y, and IdentityFile edge cases (a'b, f#g, h\ i, C:\keys\l, #x). The parser matches ssh in every case.

  • Ran a differential fuzz of about 160k random strings against a JS port of argv_split. The only mismatch is an empty quote right before # (""#x), which also diverges on main.

  • The original author also tested on Windows 10 with OpenSSH_for_Windows 9.5p1 and Git's OpenSSH 10.0p2.

  • oxlint, oxfmt --check, the anti-slop and native-plugin oxlint configs, ast-grep, and the changed-code quality gate are all clean on the touched files.

Performance

None, because the tokenizer still makes a single pass over each line, with no new I/O, subprocess or polling. It runs in the main process only when the SSH config loads (host picker, import or reconcile, and alias claims behind a 5 s TTL cache). Median of 3 runs of parseSshConfig, main vs this PR:

  • typical 60-host config: 0.131 vs 0.133 ms
  • 20k hosts: 28.3 vs 27.4 ms
  • one 200k-pattern Host line: 36.3 vs 35.7 ms
  • quote-heavy config: 10.0 vs 8.3 ms

Risk

Level: Low

  • An unescaped ' in a config value is now a quote and a # inside a token is now literal, as in OpenSSH. A config that relied on the old reading was already read differently by ssh itself.
  • If Orca previously imported a host under a wrong alias ('foo', or team from team#1), the next reconcile adds the correctly named host once. The old entry stays until the user deletes it.
  • Hosts from single-quoted or escaped-space Include files now appear.
  • ProxyCommand keeps its raw text, as before.
  • To back it out, revert this commit.

Review

Original fix by @Pr1p in #50976. The maintainer follow-up adds the token-boundary # handling and its test.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

This parsing change behaves the same on every platform: OpenSSH tokenizes identically on every OS, and Windows backslash path separators stay literal.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds splitOpenSshArguments and uses it to parse SSH config scalar values, host patterns, and Include arguments. The parser handles quoted text, selected escapes, unquoted comments, and whitespace. A loader test covers single-quoted and escaped-space Include paths, a single-quoted host pattern, and a single-quoted identity path containing double quotes.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 8e85e

SSH config parsing now follows OpenSSH for single-quoted values and escaped-space Include paths, and a # inside a path no longer truncates it. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: SSH config parsing of single-quoted paths and escaped-space paths now follows OpenSSH. It matches the changeset, which adds a shared splitOpenSshArguments tokenizer th…
Description check Passed The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #50975), Visual Proof (N/A with reason), Testing with checkboxes and manual Windows verific…
Linked Issues check Passed Issue #50975 requires Orca to read SSH config Include and IdentityFile values as OpenSSH does for single quotes and backslash-escaped spaces. At head, src/main/ssh/config/ssh-config-arguments.ts expor…
Out of Scope Changes check Passed The changed tokenizer in ssh-config-arguments.ts serves #50975. Its # boundary rule keeps values such as team#1 and ~/.ssh/t#1 intact, which keeps the shared tokenizer consistent with the values the P…
Full details: Title check

Explanation

The title names the main change: SSH config parsing of single-quoted paths and escaped-space paths now follows OpenSSH. It matches the changeset, which adds a shared splitOpenSshArguments tokenizer that handles single quotes and escaped spaces. The title is specific and uses the conventional fix(ssh) prefix.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #50975), Visual Proof (N/A with reason), Testing with checkboxes and manual Windows verification, Performance, Risk with level and back-out plan, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist. It explains the before and after behavior with a table and states the mechanism. Minor gaps: the template's Testing section asks for the platforms tested, and the description covers Windows only, which is stated. The Visual Proof N/A is justified. Overall the description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #50975 requires Orca to read SSH config Include and IdentityFile values as OpenSSH does for single quotes and backslash-escaped spaces. At head, src/main/ssh/config/ssh-config-arguments.ts exports splitOpenSshArguments. It treats '...' and "..." as quotes, each literal inside the other. It treats ", ', \, and unquoted <space> as escapes, and keeps other backslashes literal. It also starts a comment at an unquoted # only when the current token is empty, so team#1 stays one argument. The previous assessment found that the Include expander and the parser both call this function. The incremental diff from the previous reviewed head could not be read, so the head file was checked directly. It confirms the tokenizer behavior described in the PR. The three forms in the issue table (single-quoted Include, escaped-space Include, single-quoted IdentityFile) are covered. The PR's ssh-config-loader.test.ts case was not opened, so its fail-on-revert claim rests on the PR description. The verdict does not depend on that claim. No coding requirement remains unmet.

Full details: Out of Scope Changes check

Explanation

The changed tokenizer in ssh-config-arguments.ts serves #50975. Its # boundary rule keeps values such as team#1 and ~/.ssh/t#1 intact, which keeps the shared tokenizer consistent with the values the PR claims to preserve. The Include expander and the parser now use this one tokenizer, which matches the issue's single-tokenizer scope. The PR keeps ProxyCommand as raw text and leaves ssh-g-config-resolution.ts unchanged. The issue does not require either change. The incremental diff could not be read, so the review of the newest changes relies on the head file and the summary. No unrelated change is evident.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 324f2679-553e-4fbc-84d2-d6d27b32f66f
Commits

Reviewing files that changed from the base of the PR and between e3cd23b and 8e85e48.

Files selected for processing: 2

  • src/main/ssh/config/ssh-config-arguments.ts
  • src/main/ssh/config/ssh-config-loader.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f69fea84-3a37-49b9-add2-29b9aacdc656
Commits

Reviewing files that changed from the base of the PR and between f38c580 and e3cd23b.

Files selected for processing: 4

  • src/main/ssh/config/ssh-config-arguments.ts
  • src/main/ssh/config/ssh-config-include-expander.ts
  • src/main/ssh/config/ssh-config-loader.test.ts
  • src/main/ssh/config/ssh-config-parser.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

}

// Inline comments must not become imported aliases.
if (!quote && char === '#') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Recognize comments only between arguments.

For Include ~/.ssh/my\ configs/team#1.conf, the tokenizer consumes the escaped space but truncates the pathname at #. The Include expander then checks ~/.ssh/my configs/team, so the included hosts do not load.

OpenSSH 9.5p1 recognizes a comment before starting an argument; it preserves # inside an argument. Track whether an argument has started before applying this condition. Keep whitespace-separated trailing comments excluded. (raw.githubusercontent.com)

…OpenSSH

OpenSSH tokenizes config lines with argv_split, where '...' quotes like
"..." and "\ " escapes a space. Orca's parser only knew double quotes,
and Include lines used a second tokenizer without escapes, so hosts from
`Include '~/.ssh/my configs/*'` or `Include ~/.ssh/my\ configs/*`
vanished and `IdentityFile '~/.ssh/my key'` became `'~/.ssh/my`.

Share one argv_split-compatible tokenizer between both, and treat # as a
comment only at a token boundary so `Host team#1` and
`Include ~/.ssh/t#1` keep the # literally, as ssh does.

Fixes stablyai#50975

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/ssh-config-single-quotes branch from e3cd23b to 8e85e48 Compare November 27, 2026 16:36
@nwparker
nwparker merged commit a312fe8 into stablyai:main Nov 27, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SSH config Include and IdentityFile paths in single quotes or with escaped spaces are misread

2 participants