Skip to content

fix(server-core): only read with git in an untrusted folder - #385

Open
Exeloo wants to merge 4 commits into
mainfrom
fix/git-untrusted-config
Open

Exeloo wants to merge 4 commits into
mainfrom
fix/git-untrusted-config

Conversation

@Exeloo

@Exeloo Exeloo commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Closes #249

In a folder that is not trusted (restricted mode), git now only reads, and the folder's own git settings can no longer make it run commands. Everything is in GitService._exec, the one place every git command goes through, so it also covers callers of GitService other than the RPCs.

  • Reads only: an allow-list of read subcommands (status, log, show, ls-files, ls-tree, for-each-ref, rev-parse, stash list, config --get, remote get-url, symbolic-ref --short). Every other command (init, stage, commit, branches, stash changes, fetch, pull, push...) is refused with FORBIDDEN: "git needs a trusted folder: trust this folder to change its repository".
  • Reads run without the repository's commands: the hosted hardening, plus every filter, diff and merge driver turned off whatever config sets it, no lazy fetch or transport, and submodules skipped. A config that can't be listed in full refuses the command.
  • A repository that is not inside the folder is refused (a linked worktree, a submodule's folder, a .git file or link, core.worktree, a shared object store, a bare repository). A plain folder still gets git's usual "not a repository" answer.
  • A local trusted folder and the hosted editor are unchanged, apart from log.showSignature=false added to the hosted hardening.

Docs: AGENTS.md (restricted mode) and docs/docs/editor/git.mdx say what Git shows in restricted mode and that this check needs Git 2.31 or later.

How do you test this PR?

New describe('an untrusted folder') in packages/server-core/test/git/git-service.spec.ts, on real temporary repositories that record whether any of their commands ran:

Round Before (red) After
06d2df6 5 failed, 13 passed against the original git-service.ts: a repository command ran on read, on write and in a submodule, and a remote was reached 134/134
7cfa113 2 failed on 06d2df6 (drivers from the user's own config; a repository outside the folder) 136/136
8e6dfa9 2 failed on 7cfa113 (repository data stored outside the folder) 137/137
65d1b8f 1 failed on 8e6dfa9 (a bare repository) 138/138

The write test checks all 17 write and remote calls: each is refused, and the repository is left as it was. Tests that change the user's git config run with a temporary HOME.

Commands run from the worktree: server-core vitest (24 files, 138 passed, 0 skipped on 65d1b8f), pnpm lint, pnpm typecheck (41/41) on 65d1b8f; pnpm build in round 1. e2e not run (server-only change, covered by unit tests).

Integration: a scratch branch with every editor branch of this sweep merged passed pnpm build, lint, typecheck, pnpm test --force (1014 passed, 1 skipped) and the full e2e suite with the engine (141/141, Chromium only).

Merge danger

  • Two-way door (a revert restores the old behaviour).
  • Blast radius: @nanoforge-dev/editor-server-core has no runtime dependents outside the editor. Merging to main deploys the editor app.
  • Behaviour change (confirmed during the work): restricted mode is read-only git. In an untrusted folder the Git panel's write actions and the tutorial's "Initialize repository" step fail with FORBIDDEN until the folder is trusted. Git LFS files may show as modified, since no filter runs. A folder whose repository is not inside it shows no Git until trusted. Each command costs about 1.4 ms more (one extra git process).
  • Conflict with fix/server-core-fs-safety (fix(server-core): keep project file operations inside the project #384) in git-service.ts: both edit the hosted hardening. The integration branch kept both: in the hosted hardening's else branch, set SERVER_CONFIG. This is security code, so the owners of both PRs must confirm that resolution. The same pair also conflicts in git-service.spec.ts (the integration branch keeps both suites) and in the restricted-mode line of AGENTS.md (the integration branch keeps this branch's sentence and puts fs-safety's "(without core.symlinks=false: the user's own checkout keeps its links)" right after "the hosted hardening on").

Follow-up issues

Quality gate

Lane Result HEAD covered
Docs Updated: AGENTS.md, docs/docs/editor/git.mdx (shared object stores, Git 2.31 or later) 65d1b8f
Correctness Pass after 4 rounds (the last review's finding fixed in 65d1b8f) 8e6dfa9
Performance Pass (about 1.4 ms per extra git process, measured) round 1
Accessibility N/A: no UI -
Security Pass after 4 rounds (narrow check of the last fix) 65d1b8f
Style Pass (pnpm lint) round 1; lint on 65d1b8f

Last round 65d1b8f: producer red→green and a narrow security check, no correctness re-review.

@Exeloo
Exeloo requested a review from Tchips46 as a code owner November 29, 2026 11:18
@github-actions github-actions Bot added documentation Improvements or additions to documentation packages:server-core Related to Server core package labels Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation packages:server-core Related to Server core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git runs commands from the own .git/config of an untrusted folder

1 participant