Skip to content

Conversation

@AmirGhMohseni
Copy link

@AmirGhMohseni AmirGhMohseni commented Nov 29, 2025

This PR fixes the critical Path Traversal vulnerability reported in issue #381 (comment).

Changes

  • Validates and canonicalizes file paths using path.resolve()
  • Restricts file access to a safe base directory (SAFE_PREVIEW_DIR)
  • Rejects any path containing .. or absolute paths
  • Allows only safe file extensions (e.g., .png, .pdf)
  • Returns appropriate HTTP errors for invalid requests

Testing

  • Added unit tests covering:
    • Valid file access
    • Path traversal attempts (../../../etc/passwd)
    • Invalid extensions
    • Missing parameters

This patch ensures attackers cannot read arbitrary files like .env or internal configs via the preview endpoint.

Added validation and security features for serving preview files.

Signed-off-by: Amir <[email protected]>
Issue 383

Signed-off-by: Amir <[email protected]>
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