SFTP root escape via prefix-based path validation in goshs
Date: 2026-04
Affected: go/github.com/patrickhener/goshs/v2, go/github.com/patrickhener/goshs
Attack vector: path-traversal
Category: vulnerability-disclosure
Severity: High
CVE: CVE-2026-40876
CWE: CWE-22
CVSS: 8.8 (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)

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


Mitigations:

Architectural layers (MAESTRO):