Skip to content

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

Merged
kelsoncm merged 2 commits intomainfrom
alert-autofix-3
Apr 8, 2026
Merged

Potential fix for code scanning alert no. 1: Uncontrolled data used in path expression#15
kelsoncm merged 2 commits intomainfrom
alert-autofix-3

Conversation

@kelsoncm
Copy link
Copy Markdown
Owner

@kelsoncm kelsoncm commented Apr 8, 2026

Potential fix for https://github.com/kelsoncm/sc4/security/code-scanning/1

To fix this robustly without changing intended functionality, enforce a strict filename allowlist before building the file path (only plain filenames with safe characters, no separators), and continue using the existing canonicalization + containment check. This removes ambiguity and makes the sanitization explicit to both humans and static analyzers.

In sc4net/tests/mocks.py, update do_GET:

  • after extracting filepath, derive safe_filepath with os.path.basename(filepath) (single-file semantics),
  • reject invalid names via a regex allowlist (e.g., ^[A-Za-z0-9._-]+$),
  • keep the existing realpath(join(...)) and commonpath checks,
  • then proceed with exists/open.

Also add import re at the top for validation.

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

kelsoncm and others added 2 commits April 8, 2026 14:35
…n path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@kelsoncm kelsoncm marked this pull request as ready for review April 8, 2026 17:43
@kelsoncm kelsoncm merged commit 3922345 into main Apr 8, 2026
1 check passed
@kelsoncm kelsoncm deleted the alert-autofix-3 branch April 8, 2026 17:43
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.

1 participant