Skip to content

Conversation

@AmirGhMohseni
Copy link

@AmirGhMohseni AmirGhMohseni commented Nov 29, 2025

This PR fixes the critical Path Traversal vulnerability reported in issue https://github.com/AIxBlock-2023/awesome-ai-dev-platform-opensource/issues/381#issue-3676632156.

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 <98203210+AmirGhMohseni@users.noreply.github.com>
Signed-off-by: Amir <98203210+AmirGhMohseni@users.noreply.github.com>
Issue 383 Signed-off-by: Amir <98203210+AmirGhMohseni@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

1 participant