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

- Severity: High 8.7 (CVSS:4.0, scored by GitHub_M) `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`
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Likelihood of exploitation in the next 30 days (EPSS): 0.46%, higher than 41% of CVEs (2026-12-01)
- Public exploit code or proof of concept: one link below, marked "exploit"
- Published: 2026-04-14T22:28:17.000Z
- Modified: 2026-10-26T22:10:00.163Z
- Also known as: GHSA-5h6h-7rc9-3824, GO-2026-5146
- Weaknesses: CWE-22
- SSVC (CISA-ADP): exploitation poc, automatable no, technical impact total
- Assigned by: GitHub_M

## 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.

(As written by CVE List.)

## Affected

- patrickhener goshs: < 2.0.0-beta.6
- github.com/patrickhener/goshs (Go): up to 1.1.4; all versions
- github.com/patrickhener/goshs/v2 (Go): before 2.0.0
- goshs goshs: before 2.0.0; 2.0.0

## Every score

- GitHub_M: CVSS:4.0 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`
- GitHub: CVSS:3.1 8.8 High `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- GitHub: CVSS:4.0 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`
- NVD: CVSS:3.1 8.8 High `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`

## References

- <https://github.com/patrickhener/goshs/security/advisories/GHSA-5h6h-7rc9-3824> (exploit, advisory, vendor-advisory, web)
- <https://nvd.nist.gov/vuln/detail/CVE-2026-40876> (advisory)
- <https://github.com/patrickhener/goshs> (package)
- <https://github.com/patrickhener/goshs/releases/tag/v2.0.0> (web)

## Sources

- CVE List: [CVE-2026-40876](https://www.cve.org/CVERecord?id=CVE-2026-40876), CVE Terms of Use, modified 2026-04-22
- GitHub Advisory Database: [GHSA-5h6h-7rc9-3824](https://github.com/advisories/GHSA-5h6h-7rc9-3824), CC-BY-4.0, modified 2026-06-25
- Go Vulnerability Database: [GO-2026-5146](https://pkg.go.dev/vuln/GO-2026-5146), CC-BY-4.0, modified 2026-06-25
- NVD: [CVE-2026-40876](https://nvd.nist.gov/vuln/detail/CVE-2026-40876), Public domain, modified 2026-10-26

---

Page: https://cve.day/CVE-2026-40876 · Whole record: https://cve.day/CVE-2026-40876.json · Rebuilt by cve.day 2026-11-25T22:59:19.137Z
