Potential fix for code scanning alert no. 16: Uncontrolled data used in path expression#538
Merged
Conversation
…in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
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): |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-relativefile_path, buildfull_pathwithos.path.realpath(os.path.join(static_dir, file_path))and then verify containment usingos.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 ifos.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.pathonly.Suggested fixes powered by Copilot Autofix. Review carefully before merging.