Skip to content

Conversation

@ilesinge
Copy link
Owner

@ilesinge ilesinge commented Dec 3, 2025

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

To fix the problem, sanitize and validate the language argument before using it in the file path. The best approach, given its use as part of a filename, is either to restrict it to a safe set of values or ensure only safe characters are included. For this use-case, we can eliminate any directory traversal (/, \, or ..) and restrict to a simple whitelist (e.g., letters, digits, underscore, dash), or use werkzeug.utils.secure_filename or a similar utility for ensuring the segment is safe for file use.

Specifically, edit the speak method in shabda/dj.py to sanitize language (and potentially word and gender similarly). You can do this using a regular expression or by filtering out unwanted characters. Since only language is tainted in the trace, we must at least sanitize it before constructing the file path. Add the necessary imports.


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>
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