Repository navigation
FIX: Accept only shipped template names in PersuasionConverter and ImagePromptStyleConverter - #4590
Conversation
…omptStyleConverter Both joined the name they're given onto a folder of shipped YAML files, so an absolute path or one with '..' read another YAML file on this machine: PersuasionConverter sent its value to the converter target as the system prompt. A name now has to be one of the shipped files, as load_assert_judge_preset requires. Custom style files still go in ImagePromptStyleConverter's filter_path.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the template-name path traversal hardening.
No open issues 🎉
What changed in this PR
Closes a template-name path traversal gap in PyRIT’s persuasion and image-style converters, including those created through the backend API.
Changes:
- Restricts persuasion techniques, image filters, and variation lookups to shipped template names before constructing file paths.
- Preserves explicit custom style loading through
filter_path. - Adds regression tests for invalid names, traversal paths, absolute paths, and failed API creation without registration.
| File | Description |
|---|---|
tests/unit/converter/test_persuasion_converter.py |
Tests rejection of unknown techniques and path-based selectors. |
tests/unit/converter/test_image_prompt_style_converter.py |
Tests rejection of paths and non-filter templates. |
tests/unit/backend/test_converter_service.py |
Verifies rejected selectors leave no registered converter. |
pyrit/converter/persuasion_converter.py |
Validates technique names against shipped YAML templates. |
pyrit/converter/image_prompt_style_converter.py |
Validates built-in filter names in construction and variation lookup. |
Review effort: Balanced
|
Non-blocking wording clarification: “the API refuses” in the description is too broad. The API rejects raw server filesystem paths for filter_path, but accepts uploaded file contents as a data URI and saves them to a managed local file. This behavior is unchanged by this PR. Suggested replacement: “Custom styles remain supported through filter_path: Python code and initializers can provide a local path, while API callers must upload the file contents rather than name a server path.” |
|
Thanks, good catch. I updated the description with your wording: API callers upload the file's contents for |
Description
PersuasionConverterandImagePromptStyleConverterjoin the name they're given onto their folder of shipped YAML files, so a name that's a full path or contains..reads another YAML file on the machine running PyRIT. ThroughPOST /api/convertersthat's a file on the server:PersuasionConvertersends the file'svalueas the system prompt to its converter target, which the caller chooses. It's the same kind of gap asLocalRefusalClassifierScorer.model_idon #4051, and saving converters (#4051) would keep such an entry across restarts.persuasion_technique,filter_name, andImagePromptStyleConverter.list_available_variationsnow accept only the names of the shipped files, checked before any path is built, asload_assert_judge_presetdoes. Any other name gets the sameValueErroran unknown name got before.ImagePromptStyleConverter.filter_path: Python code and initializers can give a local path, and API callers upload the file's contents instead of naming a server path, as before.Every documented technique and filter name works as before, and the converters' identifiers don't change.