Skip to content

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

Merged
PRATHAM777P merged 1 commit into
mainfrom
alert-autofix-8
Apr 27, 2026
Merged

Potential fix for code scanning alert no. 8: Uncontrolled data used in path expression#5
PRATHAM777P merged 1 commit into
mainfrom
alert-autofix-8

Conversation

@PRATHAM777P
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/PRATHAM777P/IPWatchdog/security/code-scanning/8

To fix this safely without changing intended behavior, canonicalize both the user-provided path and allowed roots with os.path.realpath, then enforce containment using os.path.commonpath (not startswith). This prevents traversal and prefix-bypass issues. Also ensure the provided path is absolute before validation to avoid ambiguous relative resolution.

In app.py, inside monitor_start() (around lines 258–267), replace the current allowlist check:

  • Build real_log_path = os.path.realpath(log_path).
  • Build canonical allowed roots list from MONITOR_ALLOWED_PATHS.
  • Check os.path.commonpath([real_log_path, allowed_root]) == allowed_root for at least one allowed root.
  • Use real_log_path for os.path.isfile(...), open(...), and response payload to keep path use consistent and validated.

No new imports are needed (os is already imported).

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

…n path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@PRATHAM777P PRATHAM777P marked this pull request as ready for review April 27, 2026 20:14
Comment thread app.py
return jsonify({"error": "Path not in allowed monitor paths"}), 403

if not os.path.isfile(log_path):
if not os.path.isfile(real_log_path):
@PRATHAM777P PRATHAM777P merged commit a5e1843 into main Apr 27, 2026
1 of 2 checks passed
@PRATHAM777P PRATHAM777P deleted the alert-autofix-8 branch April 27, 2026 20:15
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.

2 participants