Skip to content

Commit 84d2026

Browse files
authored
patch: sanitize file extension in HuggingFaceTextToSpeechModelInference (#101)
Sanitize the file extension to prevent path traversal attack for users that take untrusted inputs in the init.
1 parent 314f49f commit 84d2026

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

libs/community/langchain_community/tools/audio/huggingface_text_to_speech_inference.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def __init__(
6565
f"'{_HUGGINGFACE_API_KEY_ENV_NAME}' must be or set or passed"
6666
)
6767

68+
# Sanitize file extension to prevent path traversal attacks
69+
file_extension = os.path.basename(file_extension).lstrip(".")
70+
if not file_extension or "/" in file_extension or "\\" in file_extension:
71+
raise ValueError("Invalid file extension")
72+
6873
if file_naming_func == "uuid":
6974
file_namer = lambda: str(uuid.uuid4()) # noqa: E731
7075
elif file_naming_func == "timestamp":

0 commit comments

Comments
 (0)