Skip to content

FEAT: Show who saved each target and list only your own (part 10) - #4028

Open
varunj-msft wants to merge 175 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Show-Who-Saved
Open

varunj-msft wants to merge 175 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Show-Who-Saved

Conversation

@varunj-msft

@varunj-msft varunj-msft commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part 10 of saving Registry entries across restarts. Stacked on part 9 (#4027); part 11 (#4050) builds on it. This PR's own changes: varunj-msft/PyRIT@varunj-msft/13178-Save-From-Registry...varunj-msft/13178-Show-Who-Saved

Design: 4.4 Credentials (Owners). Where every part fits: PR map.

This is one of the changes for saving Registry entries across restarts. It builds on #4027, which saves targets from the Registry. Until the earlier PRs merge, the diff here also shows their changes.

Problem. With sign-in on, everyone's saved targets land in one Targets list, and nothing says who saved which, so users can't find their own. Frederic raised this on the design gist and suggested Mine, Official and All views.

Change.

  • The server already records who saved a target in its saved file. It now keeps that on the running target, both when the target is saved and when it's restored at startup or apply. Restore does the same for converters and scorers, for when they can be saved.
  • Each listed target says who saved it (saved_by, the name) and whether that's the signed-in user asking (saved_by_me). The server compares the object IDs, so no ID leaves it.
  • The Targets table shows "Saved by you" or "Saved by " under the Saved label. An "Only targets I saved" checkbox sits beside "Show hidden targets". It shows only while you have a saved target, so with sign-in off nothing new appears, and like "Show hidden targets" it isn't kept across reloads.

What stays the same. Anyone can still save and use every target, and nothing here decides who can change or delete one. The saved file format doesn't change. Targets from configuration and Temporary targets have no owner. The round robin member list and the other target pickers are unchanged.

Not covered.

  • Who can change or delete a saved target (its owner or an admin). That comes with editing and deleting.
  • Saving converters and scorers. Those PRs set the owner the same way.
  • An Official view. Targets from configuration already have their own label; marking a saved target as official can come later.

Tests and Documentation

  • tests/unit/registry/test_registry_recipe_restore.py: restore keeps who saved each target, converter and scorer; an entry saved without sign-in has nobody.
  • tests/unit/backend/test_target_service.py: a saved target says who saved it and whether it was the caller, for the saver, another user and nobody signed in, the same before and after a restart; a target saved with sign-in off and a Temporary one name nobody, including the create response.
  • tests/unit/backend/test_mappers.py: the name and the flag for each owner and caller, a blank name, no object ID in the response, and inner targets of a saved round robin naming nobody.
  • tests/unit/backend/test_api_routes.py and test_auth_middleware.py: list and get pass the caller's object ID, and none with sign-in off.
  • TargetTable.test.tsx: the captions; the checkbox narrowing the list, together with the column filters and with hidden targets; no checkbox when nothing is yours; turning off when your last saved target is gone.
  • frontend/e2e/config.spec.ts (mock): the captions, the checkbox, and a fresh load listing everyone again. frontend/e2e/registry.spec.ts (seeded, sign-in off): nobody is named and there's no checkbox.
  • Each of the 18 ways I tried to break this fails at least one of these tests.
  • uv run --frozen --extra all python -m pytest -n 8 --dist=loadfile tests/unit/registry tests/unit/backend tests/unit/prompt_target tests/unit/models tests/unit/setup tests/unit/converter tests/unit/score: 19,612 passed, 9 skipped, 4 xfailed
  • cd frontend && npm run test:coverage: 184 suites, 4,563 tests passed
  • cd frontend && npx playwright test --project=mock e2e/config.spec.ts e2e/registry.spec.ts: 29 passed
  • cd frontend && E2E_SEEDED_MODE=true npx playwright test --project=seeded: 109 passed
  • npx tsc --noEmit, npx eslint on the changed files, and pre-commit (ruff, ty, docs checks): passed
  • doc/gui/0_gui.md (Registry): the "Saved by" caption and the checkbox. pyrit/backend/README.md: the two new fields.

No JupyText changes.

…API input

External construction now rejects a parameter whose type includes Path unless the
calling service passes the name in allowed_path_params after making the value safe.
The converter service allows its upload parameters once they are stored, and the
target service allows the server-set upload folder and the GitHubCopilotTarget
working directory. The scorer-only check is removed, and the "Valid parameters"
list leaves out path parameters callers cannot set.
The target catalog now applies the path rule to required parameters too, so a
target that needs a disallowed path is left out instead of listed without the
field, matching the scorer catalog. allowed_path_params is typed frozenset[str]
so a bare string cannot turn the allow-list into a substring match.
The target catalog still lists a target whose required path parameter is its
server-set upload folder when the server has one, and leaves it out otherwise.
# Conflicts:
#	tests/unit/backend/test_converter_service.py
@varunj-msft varunj-msft changed the title FEAT: Show who saved each target and list only your own FEAT: Show who saved each target and list only your own (part 10) Nov 9, 2026
FileDocumentStorage now raises DocumentStorageUnavailableError when the
folder or container can't be used, and DocumentUnreadableError when one
document exists but can't be read. The message names the location, with
any SAS token hidden, and a short reason. One backend handler maps both to
503 and logs the location and reason, with the traceback at debug level,
so the per-route storage helpers are gone.

A single read, a conditional save and a delete now follow the listing's
rules: a folder, pipe or broken link named like a document is unreadable
rather than missing, and on Blob only a deleted blob counts as missing.
Blob sign-in, permission, network and missing-container errors stop the
listing instead of marking every file unreadable. Each unreadable report
keeps the real file name and the original error, and the listing's
documents are read-only.

Initializer delete removes a script that can't be read or decoded, and
registering one no longer turns a storage write failure into a 400.
Tests patch module-level aliases instead of os.
List recipes escapes the OS text it reports, such as a file name that
isn't UTF-8, and a recipe whose JSON holds an unpaired surrogate escape
is reported as invalid, so the models no longer need a JSON-only
serializer. Recipes may start with a byte-order mark. A document without
schema_version reads as version 1, and each file is checked against the
format version of the model that reads it. Validation summaries shorten
each location part and the whole message, since a location can repeat a
stored key.

Recipes and StoredRecipe are no longer frozen, since their params and
tags never were, and StoredRecipe checks that its recipe type matches its
registry. The listing's recipes are read-only, and it keeps the error
behind each recipe that couldn't be read, for the log.
Listing catches only storage errors, so a bug is raised instead of being
reported as unreadable storage, and a bug while planning is a build
error rather than an invalid recipe. Each failure is logged once, with
the error behind it and URL credentials removed. The report shows the
error's text with each URL's user name, query and fragment removed, any
SAS signature hidden, and the length capped.

A class that moved within PyRIT is restored; one now registered from
outside PyRIT still fails. A technique whose name or tag clashes is a
name clash, and anything else registration refuses is an invalid
recipe. A recipe that sets a server file or folder is refused before it
is built. Class metadata comes from the registry's cache. The class
docstring lists the steps the API's create runs that restore skips.
The runtime becomes ready even when some saved entries fail; the
failures stay in the runtime status. Each failed entry keeps its name in
its registry: looking it up, or taking the name, raises
SavedEntryUnavailableError, which the backend answers with 409, so
nothing else stands in for it. Administrators see the full message and
everyone else a fixed explanation of the reason. A folder that can't be
listed holds every unregistered name of its kind, and each entry it left
unbuilt is reported.

While a saved technique is held, a launch or estimate that picks
techniques by all, default or a tag is refused with 409 for scenarios
whose techniques come from the registry, since the broken technique's
tags may be unknown. Naming techniques still works; naming the held one
fails with its reason. Route catch-alls let the error through instead of
turning it into a 500.
A launch script that registers a name held for a saved entry that
couldn't be restored is refused, and the refusal is recorded even when
the script catches it, so the launch stops instead of running with the
script's entry in the saved one's place. A suite entry that fails on a
held entry, or on a broad technique selection, shows the reason without
the error's details.
The OpenAI SDK adds that variable's headers to every request, so a saved
OpenAI target would send whatever the server puts there, which can be a
credential. While it's set, saving an OpenAI target is refused and a
saved one isn't restored; the message names the variable, never its
value. Targets declare such variables in server_header_variables.

This branch has not been deployed

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