Skip to content
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
15 changes: 15 additions & 0 deletions wifite/attack/portal/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@
try:
# Remove /static/ prefix and ensure a relative path
file_path = path[8:].lstrip('/\\') # Remove '/static/' and any leading separators
if not file_path:
self._send_error_response(404, 'Not Found')
return

filename = os.path.basename(file_path)

# Try to get cached static file from server instance
Expand All @@ -248,6 +252,17 @@
static_dir = os.path.realpath(os.path.join(portal_dir, 'static'))
# Build and normalize full path to requested file
full_path = os.path.realpath(os.path.join(static_dir, file_path))

# Enforce that the requested file stays under static_dir
Comment thread
kimocoder marked this conversation as resolved.
if os.path.commonpath([static_dir, full_path]) != static_dir:
log_warning('Portal', f'Blocked path traversal attempt: {path}')
self._send_error_response(403, 'Forbidden')
return

if not os.path.isfile(full_path):

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
self._send_error_response(404, 'Not Found')
return
full_path = os.path.realpath(os.path.join(static_dir, file_path))

# Security check: ensure file is within static directory
if os.path.commonpath([static_dir, full_path]) != static_dir:
Expand Down
Loading