Skip to content

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

Draft
zsxh1990 wants to merge 1 commit into
mainfrom
alert-autofix-19
Draft

Potential fix for code scanning alert no. 19: Uncontrolled data used in path expression#28
zsxh1990 wants to merge 1 commit into
mainfrom
alert-autofix-19

Conversation

@zsxh1990

@zsxh1990 zsxh1990 commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/whitehat-bot/automatic-potato/security/code-scanning/19

To fix this safely, resolve the requested path against a trusted base directory and verify the resolved target remains inside that base before serving it.

Best fix in this file:

  • In new_ui/backend/main.py, inside serve_spa (lines ~167–175), replace the current file_path construction/check with:
    1. Resolve FRONTEND_DIST to an absolute canonical base.
    2. Build candidate path with (base / full_path).resolve().
    3. Reject/ignore the candidate if it is not under the base (using relative_to in a try/except ValueError).
    4. Only return FileResponse when the candidate is inside base and is an existing file.
    5. Otherwise return index.html as before.

No new dependency is needed. Path.resolve()/relative_to() are from existing pathlib.Path import.

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

…in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread new_ui/backend/main.py
file_path = FRONTEND_DIST / full_path
if full_path and file_path.exists() and file_path.is_file():
dist_root = FRONTEND_DIST.resolve()
file_path = (dist_root / full_path).resolve()
Comment thread new_ui/backend/main.py
except ValueError:
is_within_dist = False

if is_within_dist and file_path.exists() and file_path.is_file():
Comment thread new_ui/backend/main.py
except ValueError:
is_within_dist = False

if is_within_dist and file_path.exists() and file_path.is_file():
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