CVE-2026-6863: Go Path Traversal Via Strings Hasprefix

Validating paths mapped into a directory using `strings.HasPrefix` is prone to partial directory traversal if the directory path does not end with a separator. An attacker can construct a path that traverses out of the target directory into a sibling directory with a similar name (e.g., `target` and `target_malicious`). Use `filepath.Rel` and check for ".."

Provally CuratedPublic repositoryMediumMedium confidenceVerifiedApache-2.0Go
greprules fetch cve-2026-6863-go-path-traversal-via-strings-hasprefix --engine opengrep

Description

Validating paths mapped into a directory using `strings.HasPrefix` is prone to partial directory traversal if the directory path does not end with a separator. An attacker can construct a path that traverses out of the target directory into a sibling directory with a similar name (e.g., `target` and `target_malicious`). Use `filepath.Rel` and check for ".."