Skip to content

Potential fix for code scanning alert no. 16: Uncontrolled data used in path expression#538

Merged
kimocoder merged 1 commit into
masterfrom
alert-autofix-16
Jun 22, 2026
Merged

Potential fix for code scanning alert no. 16: Uncontrolled data used in path expression#538
kimocoder merged 1 commit into
masterfrom
alert-autofix-16

Conversation

@kimocoder

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/kimocoder/wifite2/security/code-scanning/16

To fix this safely without changing intended functionality, validate the resolved static file path against a trusted static root directory before serving content. In _serve_static_file (wifite/attack/portal/server.py), after deriving request-relative file_path, build full_path with os.path.realpath(os.path.join(static_dir, file_path)) and then verify containment using os.path.commonpath([static_dir, full_path]) == static_dir. If validation fails, return 403 (or 404) and stop. Also reject empty paths and directories, and only read files if os.path.isfile(full_path).

Best single approach: keep current behavior (cache first, filesystem fallback) but harden fallback with canonicalization + containment check. No new dependency is needed; use Python stdlib os.path only.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@kimocoder kimocoder marked this pull request as ready for review June 22, 2026 00:12
Copilot AI review requested due to automatic review settings June 22, 2026 00:12
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

self._send_error_response(403, 'Forbidden')
return

if not os.path.isfile(full_path):

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to address code scanning alert #16 (“Uncontrolled data used in path expression”) by hardening _serve_static_file in the captive portal HTTP server so request-controlled paths can’t escape the trusted static/ directory.

Changes:

  • Rejects empty /static/ requests early (404).
  • Adds canonicalization (realpath) + containment enforcement (commonpath) for filesystem fallback paths.
  • Adds a regular-file check (os.path.isfile) before serving from disk.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wifite/attack/portal/server.py
@kimocoder kimocoder merged commit 0306906 into master Jun 22, 2026
14 of 15 checks passed
@kimocoder kimocoder deleted the alert-autofix-16 branch June 22, 2026 00:46
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.

3 participants