Skip to content

fix(link): refuse an identity file in a directory others can write, and correct the missing-key docs - #8718

Merged
lidge-jun merged 6 commits into
devfrom
fix/link-identity-file-nits
Nov 13, 2026
Merged

lidge-jun merged 6 commits into
devfrom
fix/link-identity-file-nits

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Three review follow-ups to #8714 (link.route/2, --ssh-identity-file).

  • The key's directories are checked too. The request-time check looked only at the key file, so another user who could write to its directory, or to any directory above it, could rename a file or directory of their own into the key's path after the check, and ssh would then offer that key. The path is now resolved one entry at a time, as the kernel does. Every directory it passes through must be owned by this user or root and not writable by group or others unless it has the sticky bit, as /tmp does. That covers each directory on the way, each directory holding a symlink, and each symlink's target. The key's own directory is stricter: group and others cannot write it, sticky or not. Every symlink on the path must also be owned by this user or root, because another user's link can be repointed even in a sticky directory. A failure answers 400 invalid_identity_file before any SSH, with hint identity_file_directory for the key's own directory or identity_file_ancestor for a directory or symlink above it. The message is fixed text per hint (IDENTITY_FILE_GUIDANCE) that says what to fix and names no part of the path; ocx link probe|add prints the same text with the code and hint (before, it printed only "Management request failed (400)"). The rule stays: a group-writable directory is refused even when the group is the user's own, as sshd's StrictModes does. So a home or state folder created under umask 002 (per-user groups on Ubuntu or Fedora) is refused until chmod g-w, and OpenCodex does not look up group membership. GOAT will make its own directories meet this rule before passing a key. The guides, capability text, skill reference and structure state the rule in full, including the owner rule. I chose refusal over a docs-only rule because the usual places for a key pass: ~/.ssh (0700), any directory the user owns that others can only read (0755), and a private directory under /tmp. A key placed directly in /tmp, or in a shared group-writable directory, is refused, and the guides say to keep the key in a private directory like ~/.ssh. This is a metadata check at request time. ssh opens the path later, so a change this user or root makes in between is not caught, and nothing binds ssh to the file that was checked; structure/remote-link.md says so. - confirm-host's own key check has a test. A key removed between probe and confirm-host answers 400 invalid_identity_file (identity_file_missing) with no new SSH and no confirmed host. This is coverage: the check already existed and the test passed when added.
  • Docs. For a missing key, recover answers 502 remote_recover_failed with hint ssh_failed (src/link/link-recover.ts), and structure/remote-link.md and both guides now say so. The missing-key remedy now adds that a forced revoke of a disposable Child leaves a tombstone that keeps this route and its missing key. Once the alias is enrolled again, recover answers alias_linked for it, and while that new link exists only a person can clear it, with ocx link recover --forget --link-id <id> --yes; after the new link is revoked and the old key is back, ocx link recover --link-id <id> can clean the machine and settle it. The guides (en and es, identical code spans), structure and the ocx link probe|add capability text also describe the directory rule, and the skill reference is regenerated.

Note, no change: a Windows Home still declares link.route/2 in ocx capabilities --contracts (the flag and body key exist on every platform) and refuses the identity file at probe with identity_file_unsupported_platform. A caller that sees link.route/2 on a Windows Home therefore gets a 400 before any SSH, never a link that silently ignores the key.

Commits:

bb71b4e45 fix(link): an identity file in a directory others can write is refused
b85454deb test(link): confirm-host checks the identity file again before its SSH
1dbd05f26 docs(link): the key's directory rule, recover's answer for a missing key, and the tombstone a forced revoke leaves
72a0f610c fix(link): every directory an identity file's path passes through must be safe
a5f859be8 docs(link): a person forgets the missing key's tombstone only while the new link stays
5f347d46a fix(link): an identity-file refusal says what to fix, and a symlink on the key's path must be this user's or root's

Platforms and temp directories: the accepted cases build their keys under mkdtempSync(tmpdir()), so they pass only where the runner's temp directory chain passes the walk. That holds for Linux /tmp (root 1777, sticky) and for macOS /var/folders/… (checked on this Mac). CI's test changed at a5f859b ran both identity-file test files green on the self-hosted Linux runner lidge-ocx-03. The Windows shards of a lane=all run execute the whole suite. A Windows Home refuses every identity file before these checks, so the keyed server cases (this PR's and #8714's) now skip on Windows, a Windows-only case asserts that refusal, and the symlink-owner unit test skips there too. No lane=all run has included #8714 yet.

Verification

  • Test-first: the two new rows "a probe whose identity file is in a directory its group can write" and "... others can write" failed before bb71b4e (the probe answered 200) and pass after it. A companion test shows a key in a 0700 or 0755 directory this user owns is still accepted.
  • Review round (gpt-6.1-terra xhigh): P2, a writable directory above a private key directory let another user swap it (fixed in 72a0f61); P3, the docs said only a person could clear the tombstone, although recover can settle it once the new link is gone and the key is back (fixed in a5f859b). The new tests for a key under a directory others or its group can write, and for a key reached through a symlink kept in a writable directory, failed before 72a0f61; a key in a private directory under a sticky one is accepted.
  • Final-review round, test-first: the 0775-ancestor case, the message case, the CLI refusal cases for probe and add, and the symlink-owner case failed before 5f347d4. The symlink owner cannot be changed without chown, so that test passes lstat as a parameter to give the link another owner. The stat reset after an absolute symlink target has no test of its own.
  • bun test on the explicit-route suites (server, clients, paths, no-ssh-config, CLI, route edit), link-recover, cli-link-recover, skill-ocx and the Spanish docs test (temporary OPENCODEX_HOME): plus cli-link-enrollment: 356 pass, 1 skip (the Windows-only case), 0 fail. The Spanish docs test passes 30/30.
  • bun run typecheck, structure:check, skill:surface:check, privacy:scan: pass.

NOT RUN: full bun run test; Windows; a real enrollment.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

The request-time check looked at the key file alone. Another user who can
write to its directory could rename a file of their own into the key's name
after the check, and ssh would then offer it. The directory that holds the key
(after symlinks in its path resolve) must now be owned by this user or root
and not writable by group or others; otherwise the request answers
400 invalid_identity_file with hint identity_file_directory before any SSH.
A world-writable sticky directory such as /tmp is refused too.
No test covered confirm-host's own key check: a key removed between probe and confirm-host now has a case asserting 400 invalid_identity_file (identity_file_missing), no new SSH and no confirmed host.
…key, and the tombstone a forced revoke leaves
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

@github-actions github-actions Bot added the bug Something isn't working label Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

…t be safe

Checking only the directory that holds the key left a gap: with /shared
writable by another user and /shared/keys a private directory of this user,
the other user could rename keys away and put a directory or symlink with
another key in its place after the check. The path is now resolved entry by
entry, as the kernel does, and every directory it passes through (each one on
the way, each directory holding a symlink and each symlink's target) must be
owned by this user or root and not writable by group or others unless it is
sticky, as /tmp is. The key's own directory stays strict: not writable by group
or others, sticky or not. The docs also say the check is a metadata check at
request time that cannot bind ssh to the file it checked.
…he new link stays

alias_linked lasts while the new link for the alias exists. Once that link is revoked and the old key is back, ocx link recover --link-id <id> can clean the machine and settle the tombstone, so --forget is the way out only for someone keeping the new link.
…n the key's path must be this user's or root's

- A refusal now tells the operator what to fix without naming the path:
  identity_file_directory for the key's own directory, identity_file_ancestor
  for a directory or symlink above it, each with fixed text
  (IDENTITY_FILE_GUIDANCE) that the Home answers as its message and that
  ocx link probe|add prints with the code and hint (the CLI printed only
  "Management request failed (400)" before). The rule stays: a group-writable
  directory is refused even when the group is the user's own, as sshd's
  StrictModes does, so a folder created under umask 002 needs chmod g-w; the
  guides (en, es), capability text, skill reference and structure state it in
  full with the owner rule. New test: a 0775 ancestor owned by this user.
- A symlink on the path must be owned by this user or root: another user's link
  in a sticky directory can be repointed. The walk takes lstat as a parameter
  so a test can give a link another owner.
- After an absolute symlink target the walk also reads "/" again, so the final
  directory's metadata is never the link's containing directory.
- The keyed server cases skip on Windows, where every identity file is refused
  before these checks; a Windows-only case asserts that refusal.
@lidge-jun
lidge-jun marked this pull request as ready for review November 13, 2026 22:28
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 22:28
@lidge-jun
lidge-jun merged commit 450abd0 into dev Nov 13, 2026
36 of 38 checks passed
@lidge-jun
lidge-jun deleted the fix/link-identity-file-nits branch November 13, 2026 22:28
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T22:30:04.545698Z 5f347d4 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant