Skip to content

fix: prevent path traversal in article download endpoints#397

Open
tranquac wants to merge 1 commit intocoaidev:mainfrom
tranquac:fix/path-traversal-article-download
Open

fix: prevent path traversal in article download endpoints#397
tranquac wants to merge 1 commit intocoaidev:mainfrom
tranquac:fix/path-traversal-article-download

Conversation

@tranquac
Copy link
Copy Markdown

Summary

Prevent path traversal in article download endpoints by validating the hash parameter.

Problem

Both ProjectTarDownloadAPI and ProjectZipDownloadAPI use the hash query parameter directly in file path construction:

hash := strings.TrimSpace(c.Query("hash"))
c.File(fmt.Sprintf("storage/article/%s.tar.gz", hash))

A crafted hash value with path traversal sequences can read arbitrary files:

  • ?hash=../../etc/passwd → reads storage/article/../../etc/passwd.tar.gz
  • With .. sequences, an attacker can escape the storage/article/ directory

Fix

  1. Validate hash doesn't contain path separators or .. sequences
  2. Use filepath.Join for safe path construction
  3. Return 400 error for invalid hash values

Impact

  • Type: Path Traversal / Arbitrary File Read (CWE-22)
  • Affected endpoints: /article/tar, /article/zip
  • Risk: Read arbitrary files on the server
  • OWASP: A01:2021 — Broken Access Control

Signed-off-by: tranquac <tranquac@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant