Skip to content

Potential fix for code scanning alert no. 2: Uncontrolled data used in path expression - #54

Open
ilesinge wants to merge 1 commit into
masterfrom
alert-autofix-uncontrolled-data
Open

Potential fix for code scanning alert no. 2: Uncontrolled data used in path expression#54
ilesinge wants to merge 1 commit into
masterfrom
alert-autofix-uncontrolled-data

Conversation

@ilesinge

@ilesinge ilesinge commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/ilesinge/shabda/security/code-scanning/2

Use a safe path construction and containment check before writing the file.

Best fix in this snippet:

  1. Build filename using sanitized components (word, language, gender) rather than raw word.
  2. Use os.path.join instead of string concatenation.
  3. Normalize to an absolute canonical path (os.path.realpath).
  4. Verify the resulting path stays under word_dir (also canonicalized) using os.path.commonpath.
  5. Raise an error if path escapes the base dir.

In shabda/dj.py, update speak() around lines 111–148:

  • add sanitization for word and gender similar to language.
  • replace current filepath = ... with safe join + realpath + containment guard.
  • keep existing behavior (still writes .wav in sample directory), only rejecting unsafe constructed paths.

No new imports are needed (os and re already exist).

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>
@ilesinge
ilesinge marked this pull request as ready for review July 5, 2026 12:39
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