/

CVE-2026-35393

Severity:

CRITICAL RISK

(9.8)

Path Traversal in goshs Multipart File Upload Handling

CVE-2026-35393

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write via Directory Traversal

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.0

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

goshs, a SimpleHTTPServer written in Go, contained a path traversal flaw in its handling of POST multipart uploads where the target upload directory was not properly sanitized.

Under certain conditions, an attacker could use crafted upload paths to write files outside the intended directory, potentially overwriting or planting files in arbitrary locations reachable by the server process.

Affected context

This vulnerability affects goshs deployments that expose the POST multipart upload functionality and rely on the server to constrain uploads to a specific directory.

It is most relevant when:

  • The server runs with filesystem write permissions beyond the intended upload directory, and
  • Uploaded files are later served, executed, or otherwise trusted based on their location or name.

The issue is tied to how the upload directory or path is derived from client-supplied data without robust normalization and validation.

Exploit preconditions

  • Attack surface: HTTP interface exposing POST multipart file upload.
  • Required access: Ability to send HTTP requests to the goshs instance (network access; authentication requirements depend on deployment).
  • Trigger point: Submission of a crafted multipart/form-data request with upload paths containing traversal sequences or unexpected directory components.
  • Why exploitation is possible: The server logic failed to sanitize and normalize the upload directory correctly, allowing user-controlled path components to influence the final filesystem location beyond the intended upload root.

Why this happens

The underlying bug is a classic path traversal issue where user-controlled path information influences filesystem operations without proper validation.

Instead of enforcing a fixed, canonical upload root and stripping or rejecting any directory components such as .., absolute paths, or path separators, the code trusted the incoming directory value.

This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where insufficient normalization and enforcement allow an attacker to escape the designated directory tree.

Potential impact

  • Upload of files outside the intended upload directory.
  • Overwriting of existing files accessible to the goshs process.
  • Planting of malicious content in directories that are later served by the HTTP server.
  • Potential facilitation of remote code execution if written files can be interpreted as scripts or configuration by other components.
  • Facilitation of data tampering or denial-of-service by corrupting critical application or log files.

General mitigation guidance

Effective mitigation focuses on strictly confining file writes to a known safe directory and eliminating any trust in client-supplied path components.

Recommended defensive patterns include:

  • Always derive the upload root directory from server-side configuration, not from client input.
  • Normalize and canonicalize target paths before writing, then enforce that the final path is a descendant of the intended upload root (e.g., compare canonical paths or use a chroot-like mechanism).
  • Reject any upload that attempts to include directory traversal sequences (..), absolute paths, or unexpected path separators.
  • Use randomized, server-generated filenames instead of honoring client-provided names when possible.
  • Run the server under a dedicated, least-privileged account with write access restricted to the upload directory only.
  • Separate upload storage from directories that are interpreted as executable code or configuration by other services.

How teams detect issues like this

Detection generally combines code-level inspection with runtime monitoring:

  • Static analysis and code review:
  • Look for file operations where user input contributes to filesystem paths (e.g., os.OpenFile, os.Create, os.MkdirAll in Go).
  • Flag any concatenation of request parameters or multipart metadata directly into filesystem paths without canonicalization.
  • Verify that path-joining helpers are followed by checks ensuring the result stays under a configured base directory.
  • Policy and tooling:
  • Use static analysis tools or linters configured with rules for path traversal sinks and tainted data flows.
  • Incorporate security-focused code review checklists for file upload handlers and HTTP routing code.
  • Runtime monitoring:
  • Log upload paths and detect anomalous patterns (e.g., ../, starting with /, or references to sensitive directories).
  • Use file integrity monitoring around sensitive directories to detect unexpected writes by the goshs process.

Sources

SourceLink
github.comgithub.com/patrickhener/goshs/security/advisories/GHSA-jg56-wf8x-qrv5

Frequently asked

questions

If the upload endpoint is reachable and the server has write access beyond the upload directory, exploitation can be straightforward—an attacker only needs to craft multipart requests with malicious path components. The overall impact depends on what files or directories are writable and how those files are later used.

An attacker needs the ability to send POST multipart/form-data requests to the goshs instance. Whether this is internet-accessible or internal-only depends on how the service is deployed; no local shell access is required.

The robust fix is to decouple file paths from user input: enforce a fixed server-side upload root, generate filenames on the server, canonicalize all paths, and verify that the final resolved path never escapes the designated directory before performing any filesystem operations.

Adopt a secure design pattern for all file operations: treat any path information derived from requests as untrusted, always normalize and validate against a strict allowlist of directories, use least-privilege filesystem permissions, and include dedicated checks for path traversal in code review and automated security testing pipelines.

Find out what's already
exploitable in your codebase.