Skip to content

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

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

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

Conversation

@PRATHAM777P
Copy link
Copy Markdown
Owner

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

Use a dedicated path-validation helper that:

  1. Canonicalizes both user path and configured allowlist roots.
  2. Rejects invalid/empty roots.
  3. Verifies containment with commonpath safely (with exception handling).
  4. Returns a validated canonical path used for all file operations.

Best single fix in app.py:

  • Add a small helper function above monitor_start (or near utilities) to validate monitor paths.
  • Replace inline validation logic in monitor_start with a call to that helper.
  • Keep existing behavior (absolute path required, allowlist enforced, then isfile check), but make it explicit and centralized.

No new dependency is required.

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 22:48
Comment thread app.py
log_path, app.config.get("MONITOR_ALLOWED_PATHS", [])
)
except ValueError as exc:
return jsonify({"error": str(exc)}), 400
Comment thread app.py
except ValueError as exc:
return jsonify({"error": str(exc)}), 400
except PermissionError as exc:
return jsonify({"error": str(exc)}), 403
@PRATHAM777P PRATHAM777P merged commit 309f3e6 into main Apr 27, 2026
2 checks passed
@PRATHAM777P PRATHAM777P deleted the alert-autofix-9 branch April 27, 2026 22:49
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