Repository navigation
FEAT: Save converters from the Registry (part 13) - #4052
varunj-msft wants to merge 501 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Caught duplicate-name collisions can let launch proceed with an unintended saved component, while synchronous restoration can block health and management requests.
2 open issues
What changed in this PR
This PR adds persistent registry entries to PyRIT’s converter-creation workflow and distinguishes saved entries from configuration-provided and temporary instances. It also includes supporting persistence, restoration, and target-management changes from the preceding work.
Changes:
- Add saved-entry storage, validation, restoration, and protection against launch-script replacement.
- Expose persistence and origin information through the API and registry UI.
- Extend regression coverage, isolate test storage, and document saving and removal behavior.
| File | Description |
|---|---|
| tests/unit/setup/test_targets_initializer.py | Tests saved-target collision protection. |
| tests/unit/setup/test_scorer_initializer.py | Tests saved-scorer tagging protection. |
| tests/unit/setup/test_converter_initializer.py | Tests saved-converter replacement protection. |
| tests/unit/setup/test_configuration_loader.py | Tests recipe-storage configuration. |
| tests/unit/registry/test_instance_registry.py | Tests origins and recorded replacement refusals. |
| tests/unit/registry/test_attack_technique_registry.py | Tests saved-technique collision handling. |
| tests/unit/backend/test_scorer_routes.py | Tests scorer persistence and API errors. |
| tests/unit/backend/test_scenario_suite_routes.py | Tests sanitized storage failures. |
| tests/unit/backend/test_scenario_suite_execution_service.py | Tests saved-entry launch-conflict reporting. |
| tests/unit/backend/test_scenario_run_service.py | Tests launch-script replacement safeguards. |
| tests/unit/backend/test_scenario_preset_routes.py | Tests sanitized storage failures. |
| tests/unit/backend/test_saved_entries.py | Tests temporary-reference rejection. |
| tests/unit/backend/test_mappers.py | Tests target origin and ownership mapping. |
| tests/unit/backend/test_initializer_service.py | Tests local-storage failure responses. |
| tests/unit/backend/test_auth_middleware.py | Tests current-user ID lookup. |
| tests/unit/backend/test_analytics_benchmark.py | Tests benchmark recipe-storage isolation. |
| tests/unit/backend/conftest.py | Isolates saved entries for backend tests. |
| tests/end_to_end/conftest.py | Gives test backends isolated recipe storage. |
| test_support/analytics_benchmark.py | Configures isolated benchmark recipe storage. |
| pyrit/setup/initializers/tools.py | Rejects saved-entry name collisions. |
| pyrit/setup/initializers/targets.py | Protects saved targets during grouping. |
| pyrit/setup/initializers/scorers.py | Prevents saved scorers replacing initializer defaults. |
| pyrit/setup/configuration_loader.py | Adds recipe-storage configuration and validation. |
| pyrit/score/true_false/local_refusal_classifier_scorer.py | Declares model-related persistence restrictions. |
| pyrit/score/true_false/audio_true_false_scorer.py | Declares transcription-related persistence restrictions. |
| pyrit/score/scorer.py | Adds scorer saveability metadata. |
| pyrit/score/float_scale/azure_content_filter_scorer.py | Declares server-credential fallback behavior. |
| pyrit/score/float_scale/audio_float_scale_scorer.py | Declares transcription-related persistence restrictions. |
| pyrit/registry/registry_recipe_storage.py | Implements per-registry JSON recipe storage. |
| pyrit/registry/instance_registry.py | Tracks origins, ownership, and replacement refusals. |
| pyrit/registry/components/scorer_registry.py | Reserves the scorer types route name. |
| pyrit/registry/components/attack_technique_registry.py | Supports saved metadata and collision protection. |
| pyrit/prompt_target/websocket_copilot_target.py | Declares account-related persistence restrictions. |
| pyrit/prompt_target/prompt_shield_target.py | Declares credential and destination rules. |
| pyrit/prompt_target/openai/openai_target.py | Declares credential, header, and destination rules. |
| pyrit/prompt_target/litellm_chat_target.py | Declares API-key fallback behavior. |
| pyrit/prompt_target/hugging_face/hugging_face_chat_target.py | Declares token and model persistence restrictions. |
| pyrit/prompt_target/http_target/http_target.py | Disallows saving credential-bearing raw requests. |
| pyrit/prompt_target/hack_a_prompt_target.py | Declares session and cookie fallback behavior. |
| pyrit/prompt_target/github_copilot_target.py | Declares token fallback behavior. |
| pyrit/prompt_target/common/prompt_target.py | Defines target persistence-policy metadata. |
| pyrit/prompt_target/azure_ml_chat_target.py | Declares credential and endpoint rules. |
| pyrit/prompt_target/azure_blob_storage_target.py | Declares credential and container-address rules. |
| pyrit/prompt_target/a2a_target.py | Declares endpoint and agent-card destination rules. |
| pyrit/models/catalog/target.py | Adds target origin and saver fields. |
| pyrit/models/catalog/scorer.py | Adds scorer origin. |
| pyrit/models/catalog/registry_recipe.py | Defines saved recipes and restoration reports. |
| pyrit/models/catalog/__init__.py | Lazily exports recipe models. |
| pyrit/converter/converter.py | Adds credential-fallback metadata. |
| pyrit/converter/azure_speech_text_to_audio_converter.py | Declares speech credential fallback. |
| pyrit/converter/azure_speech_audio_to_text_converter.py | Declares speech credential fallback. |
| pyrit/backend/services/scorer_service.py | Saves scorers and reports their origins. |
| pyrit/backend/services/scenario_suite_execution_service.py | Exposes actionable saved-entry launch conflicts. |
| pyrit/backend/services/scenario_run_service.py | Detects launch-script replacement refusals. |
| pyrit/backend/services/saved_entries.py | Shares save validation and registration handling. |
| pyrit/backend/services/runtime_lifecycle.py | Restores saved entries and reports failures. |
| pyrit/backend/services/converter_service.py | Saves converters and exposes saveability rules. |
| pyrit/backend/routes/targets.py | Adds persistence errors and caller-aware responses. |
| pyrit/backend/routes/scorers.py | Handles scorer persistence requests and errors. |
| pyrit/backend/routes/scenarios.py | Documents saved-entry launch conflicts. |
| pyrit/backend/routes/scenario_suites.py | Sanitizes storage-error logging and responses. |
| pyrit/backend/routes/scenario_presets.py | Sanitizes storage-error logging and responses. |
| pyrit/backend/routes/initializers.py | Handles local-storage failures safely. |
| pyrit/backend/routes/converters.py | Handles persistence and saved-removal restrictions. |
| pyrit/backend/routes/common.py | Shares ownership and save-refusal response helpers. |
| pyrit/backend/README.md | Documents persistence APIs and restrictions. |
| pyrit/backend/models/targets.py | Adds persistence validation and saveability fields. |
| pyrit/backend/models/scorers.py | Adds scorer persistence validation. |
| pyrit/backend/models/converters.py | Adds persistence, origin, and saveability fields. |
| pyrit/backend/middleware/auth.py | Exposes the authenticated user’s object ID. |
| pyrit/backend/mappers/target_mappers.py | Maps target origin and saver information. |
| pyrit/backend/mappers/converter_mappers.py | Maps converter origin. |
| frontend/src/utils/registryOrigin.ts | Defines shared origin labels. |
| frontend/src/utils/registryName.ts | Generates valid, unused registry names. |
| frontend/src/utils/registryName.test.ts | Tests name validation and suggestions. |
| frontend/src/types/index.ts | Adds persistence and origin API types. |
| frontend/src/test-utils/targetFixtures.ts | Supports origin and saver test data. |
| frontend/src/services/errors.ts | Recognizes typed save refusals. |
| frontend/src/services/errors.test.ts | Tests save-refusal classification. |
| frontend/src/components/Techniques/TechniqueEditor.test.tsx | Updates converter save-button expectations. |
| frontend/src/components/Registry/ScorerRegistry.tsx | Displays scorer origin badges. |
| frontend/src/components/Registry/ScorerRegistry.test.tsx | Tests scorer origin labels. |
| frontend/src/components/Registry/OriginBadge.tsx | Provides shared origin badges. |
| frontend/src/components/Registry/ConverterRegistry.tsx | Shows origins and disables saved-entry removal. |
| frontend/src/components/Registry/ConverterRegistry.test.tsx | Tests origins and saved-removal guidance. |
| frontend/src/components/Converters/SaveConverterDialog.tsx | Clarifies that converter copies remain temporary. |
| frontend/src/components/Converters/SaveConverterDialog.test.tsx | Tests temporary-copy wording. |
| frontend/src/components/Config/TargetTable.tsx | Shows origins, savers, and an ownership filter. |
| frontend/src/components/Config/TargetTable.test.tsx | Tests target origins and ownership filtering. |
| frontend/src/components/Config/TargetTable.styles.ts | Styles saver text and visibility controls. |
| frontend/playwright.config.ts | Isolates seeded backend recipe storage. |
| frontend/e2e/fixtures/manual_send_backend.py | Isolates offline fixture recipe storage. |
| frontend/e2e/config.spec.ts | Tests target saving and ownership presentation. |
| frontend/e2e/_targets.ts | Adds origin and ownership mock fields. |
| doc/gui/0_gui.md | Explains saved entries and manual removal. |
| doc/getting_started/pyrit_conf.md | Documents recipe storage and restoration behavior. |
| .pyrit_conf_example | Adds recipe-storage configuration guidance. |
Review effort: Balanced
# Conflicts: # pyrit/prompt_target/common/prompt_target.py # pyrit/prompt_target/openai/openai_target.py
# Conflicts: # pyrit/backend/README.md # pyrit/backend/mappers/target_mappers.py # pyrit/backend/models/targets.py # pyrit/backend/routes/targets.py # pyrit/backend/services/target_service.py
# Conflicts: # frontend/src/components/Config/CreateTargetDialog.tsx # frontend/src/types/index.ts
# Conflicts: # frontend/src/components/Config/TargetTable.styles.ts # frontend/src/components/Config/TargetTable.tsx # frontend/src/types/index.ts # pyrit/backend/mappers/target_mappers.py # tests/unit/backend/test_mappers.py
# Conflicts: # pyrit/backend/routes/targets.py # pyrit/backend/services/scorer_service.py # pyrit/backend/services/target_service.py
Signed-in users may create shared converters and scorers that connect with this server's credentials, so a saved one isn't refused for that. This takes out the refusals of the Azure Speech converters and the Content Safety, audio and local refusal scorers. A saved entry still can't hold a typed key.
…t set LocalRefusalClassifierScorer.model_id now names a Hugging Face Hub repository only, checked when the scorer is built. A local checkpoint folder goes in the new Path-typed model_path, which the API refuses like other server paths, so a saved or Temporary scorer can't load a folder a caller chose. A scorer without model_path keeps its identity.
…credential The scorer now declares its endpoint as a destination. Saving refuses an endpoint URL with a user name, password, SAS token or other query, as for targets. An empty endpoint still takes this server's setting.
Converters answer a taken name with 409 whether or not the request saves the converter. Scorers answer 409 only when saving.
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
Two findings need fixing before approval: the converter dialog copies the backend's save rules, and optional upload parameters block saving after the user removes a file. The other inline comments are nonblocking.
The description says "The dialog keeps no copy of those rules". This is not correct while predictedTemporaryReason copies them. Correct the description, or fix the first inline comment.
This diff also contains #4051's LocalRefusalClassifierScorer [BREAKING] change. Merge #4051 first, or add [BREAKING] to this title and release note.
The local-folder test built the private encoder itself, so it passed even if the scorer stopped passing model_path on. It now builds the scorer with model_path or a Hub model_id and calls load_model_async.
Only registry_recipe_save and its tests use it, and it isn't exported, so it keeps the underscore it had before this change.
not_saveable_reason is the cause alone, and the GUI already shows that the converter can't be saved, so the reason no longer starts with "'X' can't be saved."
An optional file parameter sent as null or an empty string means no file, so saving leaves it out, as restore builds the converter, instead of refusing it as an uploaded file.
POST /api/converters/saveability runs the checks saving runs before the converter is built, through the same service function as saving, and the New Converter dialog asks it the way the New Target dialog does instead of keeping its own copy of those rules. The catalog's type-level reason and the refused-save fallback stay. An optional file parameter typed Path | None counts as an upload too, so a file the user removed is left out.
RegistryIdentityRow puts the name cell's badges in one wrapper under the name, the layout the Targets table had, so the Converters, Scorers, and Targets tables line them up however long a name is.
Saving a converter's changed settings under a new name makes a Temporary copy, while Save Converter now makes one that comes back after a restart. The menu item and dialog say Add to registry, with an Add button, so the two aren't confused.
Fluent let the dialog body grow past the surface's height less its padding, so with the Temporary warning shown a long form pushed Create as Temporary over the dialog's bottom edge. The body now has the surface's height and the form scrolls, as in the attack details dialog.


Description
This is one of the changes for saving Registry entries across restarts. It builds on #4051, which saves converters and scorers created through the API. Until the earlier PRs merge, the diff here also shows their changes.
The New Converter dialog only made converters that are gone after the backend restarts, wherever it opens: the Converters tab, the converter panel in chat, and New converter in the technique editor. It now saves them by default, and the Converters and Scorers tables say which entries come back.
base64_converter. Keeping the_converterending stays clear of the names the startup scripts register (base64,rot13), which would stop a saved converter of that name from restoring. The name field checks the backend's rule for saved names. A name the list already has, or one the backend says is taken (409), shows on the field, and focus moves there.POST /api/converters/saveabilitywhether the chosen type and values can be saved, as the New Target dialog asks for targets. When they can't, the button reads Create as Temporary and a warning gives the backend's reason, for example an uploaded file or a Temporary target. While the check is pending or if it fails, the button stays Save Converter, and a save the backend still refuses (typed 400) is offered as Temporary. Changing a refused value goes back to Save Converter. A file removed from a new converter, including an optionalPath | Noneone, is no longer sent. The warning sits above the buttons, outside the scrolling form, and gives the cause once. It usesrole="status"so screen readers read it out, and target options mark Temporary targets. With the warning shown, a long form scrolls and the buttons stay inside the dialog.GET /api/converters/typesaddsnot_saveable_reasonto each type that can't be saved at all, such as one that needs an uploaded file.POST /api/converters/saveabilityanswers for a type and its parameters with the same service function saving uses, without building or saving anything. The dialog keeps no copy of those rules.Config/TargetOriginBadge.tsxandutils/targetOrigin.tstoRegistry/OriginBadge.tsxandutils/registryOrigin.ts. The target files change imports only.Screenshots: a new converter saves by default, a converter that uses a Temporary target is offered as Temporary with the reason, and the Converters table before and after a restart.




Not covered: