Skip to content

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

Merged
Bryan-Roe merged 1 commit into
mainfrom
alert-autofix-2334
Jul 11, 2026
Merged

Potential fix for code scanning alert no. 2334: Uncontrolled data used in path expression#899
Bryan-Roe merged 1 commit into
mainfrom
alert-autofix-2334

Conversation

@Bryan-Roe

@Bryan-Roe Bryan-Roe commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/Bryan-Roe/Aria/security/code-scanning/2334

General fix: ensure any user-controlled filename is validated against a strict allowlist and converted to a canonical path under a trusted root, then only use that canonical path for file access.

Best targeted fix here (in scripts/gradio_demo.py, _safe_session_path and load_session region):

  1. Tighten filename validation to a strict regex allowlist (e.g., alphanumerics, _, -, ., plus required extension).
  2. Build the candidate path from Path(CONV_DIR).resolve() and Path(base, filename).resolve().
  3. Enforce containment with candidate.relative_to(base) (fails if outside).
  4. In load_session, add a final existence/type check (os.path.isfile(path)) before opening.

No new imports are needed because re, os, and Path are already imported.

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


Note

Low Risk
Localized security hardening in the demo’s session I/O helpers; behavior for legitimate dropdown filenames should be unchanged.

Overview
Addresses a code-scanning alert for uncontrolled data in path expressions when loading saved Gradio sessions.

_safe_session_path now rejects anything that isn’t a single safe basename with an allowed extension via re.fullmatch, builds paths with Path(CONV_DIR).resolve() and (base / filename).resolve(), and enforces stay-under-root with candidate.relative_to(base) instead of the previous mix of isabs, basename, and commonpath checks.

load_session refuses to open the path unless os.path.isfile(path) succeeds, so only real files under the conversation directory are read. The same helper still backs delete session, so both flows share the tighter validation.

Reviewed by Cursor Bugbot for commit 28b9a48. Bugbot is set up for automated code reviews on this repo. Configure here.

…d in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 11, 2026 07:14

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@Bryan-Roe Thanks for sending me some feedback. Unfortunately, I hit an error while trying to use the custom Copilot setup steps configured for this repository. The error I am seeing is:

no `copilot-setup-steps` job found in your `copilot-setup-steps.yml` workflow file. Please ensure you have a single job named `copilot-setup-steps`. For more details, see https://gh.io/copilot/actions-setup-steps

Once you or someone with the necessary access fixes the problem, please let me know in a comment and I'll try again. Thanks!

@Bryan-Roe Bryan-Roe marked this pull request as ready for review July 11, 2026 07:14
@cursor

cursor Bot commented Jul 11, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_6444e7ce-81d1-4d14-8958-dd86918de014)

@Bryan-Roe Bryan-Roe merged commit 2a560b4 into main Jul 11, 2026
66 of 138 checks passed
@Bryan-Roe Bryan-Roe deleted the alert-autofix-2334 branch July 11, 2026 07:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Hardens Gradio session file access against path traversal.

Changes:

  • Adds strict filename allowlisting.
  • Resolves and validates paths under the conversation directory.
  • Verifies files before loading.

Comment thread scripts/gradio_demo.py
Comment on lines +1543 to +1544
base = Path(CONV_DIR).resolve()
candidate = (base / filename).resolve()
Comment thread scripts/gradio_demo.py
return None
if os.path.isabs(filename):
# Only allow plain safe filenames with approved extensions.
if not re.fullmatch(r"[A-Za-z0-9_.-]+\.(json|md|txt)", filename):
@github-actions

Copy link
Copy Markdown
Contributor

🔐 CodeQL — Open Alerts on this PR

Severity Count
high 96
note 735
error 108
medium 59
warning 83

Copilot Autofix suggestions (if enabled) appear as inline review comments on the affected lines.
See the full list in the Security tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants