Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Security issue fix for /static-files/{path} endpoint #1003

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion aim/web/api/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import os
from pathlib import Path

from aim.web.api.utils import APIRouter # wrapper for fastapi.APIRouter
from fastapi.responses import FileResponse
from fastapi import HTTPException

statics_router = APIRouter()


@statics_router.get('/static-files/{path:path}/')
async def serve_static_files(path):
from aim import web
static_file_name = os.path.join(os.path.dirname(web.__file__), 'ui', 'build', path)
static_files_root = os.path.join(os.path.dirname(web.__file__), 'ui', 'build')
static_file_name = '/'.join((static_files_root, path))

# check if path is leading inside ui/build directory
if not Path(static_files_root) in Path(static_file_name).resolve().parents:
raise HTTPException(404)

compressed_file_name = '{}.gz'.format(static_file_name)
if os.path.exists(compressed_file_name):
return FileResponse(compressed_file_name, headers={'Content-Encoding': 'gzip'})
Expand Down