Skip to content

Commit

Permalink
prevent local file access (see security advisory GHSA-mwc7-64wg-pgvj)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Apr 12, 2024
1 parent 7c3e01a commit ed12eb1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nicegui/nicegui.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def _get_component(key: str) -> FileResponse:
def _get_resource(key: str, path: str) -> FileResponse:
if key in resources:
filepath = resources[key].path / path
try:
filepath.resolve().relative_to(resources[key].path.resolve()) # NOTE: use is_relative_to() in Python 3.9
except ValueError as e:
raise HTTPException(status_code=403, detail='forbidden') from e
if filepath.exists():
headers = {'Cache-Control': 'public, max-age=3600'}
media_type, _ = mimetypes.guess_type(filepath)
Expand Down

0 comments on commit ed12eb1

Please sign in to comment.