Repository navigation
FEAT: Gather selected findings in pyrit.output and publish them to Azure DevOps - #4839
hannahwestra25 wants to merge 23 commits into
Conversation
Move reading a finding selection from the backend into pyrit/output/finding_report/selection.py, so export, the planned findings publisher, and notebooks share one builder (step 2b of the Azure DevOps findings publisher design). - build_finding_selection_async follows export's existing steps in the same order, with an optional max_findings cap and a link_for callback. resolve_finding_evidence_async returns domain types and reads evidence in batches of 500. - report.py adds FindingSelection and FindingReportEntry.finding_id. - Export passes its dashboard link builder as link_for. The export route maps FindingSelectionNotFoundError to 404 and keeps its 422 text. The evidence page maps resolved evidence with ScoreView.from_domain, so neither changes. - Remove the OperationService methods that only export used, and move their tests to the library. - Document building a report from a selection in the output guide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A notebook report built without link_for showed intact evidence as "Evidence unavailable", because availability was derived from the link. Its opening note also promised dashboard links that the report didn't have. - FindingReportEvidence gains a required available flag, which selection sets from the resolved evidence. unavailable now reads that flag. - The opening note leaves out the dashboard clause when available evidence is listed without links. Every export links its available evidence, so export output is unchanged. - build_finding_report treats a finding without an evidence entry as having none, so a FindingSelection built from findings alone works. - Keep resolve_finding_evidence_async and ResolvedFindingEvidence module-level. Only the backend evidence page uses them. - Correct the output guide's sentence about reports without links. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…zure DevOps adapter Add a destination-neutral FindingPublisher in pyrit.output: preview_async shows where every selected finding would go, and publish_async creates the items, parents first, and reports every finding's outcome exactly once. The pure planner orders findings as the reports do, skips findings that weren't demonstrated and decides nesting; the plan digest lets a publish create only what its preview showed. Errors propagate until the first create; after that, only cancellation escapes. Add the generic, opt-in AzureDevOpsFindingPublisher: REST API 7.1 with a 30-second timeout per request, destinations parsed (never fetched) within the configured organization, JSON Patch creates with a parent link, the requester assigned, and a History note with the run and finding IDs. A 4xx or a connection that never opened is a known failure; a 5xx, a timeout after sending or an unreadable response marks the item as possibly created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Raw exception logging in both handlers can expose private finding values or credentials, and tests need to verify that formatted logs exclude sensitive exception text.
1 open issue
What changed in this PR
Adds a destination-neutral finding publisher to pyrit.output, with an opt-in Azure DevOps adapter. Includes the shared finding-selection work from #4836.
Changes:
- Adds publication models, planning, previews, and per-finding outcome tracking.
- Implements Azure DevOps mapping, validation, deadlines, and failure handling.
- Reuses finding selection across exports and publishing, with tests and documentation.
| File | Description |
|---|---|
| tests/unit/output/finding_report/test_selection.py | Tests selection and evidence resolution. |
| tests/unit/output/finding_report/test_report.py | Tests finding IDs and evidence notes. |
| tests/unit/output/finding_report/test_markdown.py | Updates evidence availability fixtures. |
| tests/unit/output/finding_publisher/test_plan.py | Tests hierarchy planning and digests. |
| tests/unit/output/finding_publisher/test_base.py | Tests publishing outcomes and deadlines. |
| tests/unit/output/finding_publisher/test_azure_devops.py | Tests adapter requests and failures. |
| tests/unit/backend/test_operations.py | Moves shared selection tests out. |
| tests/unit/backend/test_finding_export.py | Updates export regression coverage. |
| pyrit/output/finding_report/selection.py | Adds shared selection and evidence resolution. |
| pyrit/output/finding_report/report.py | Adds selections, IDs, and availability. |
| pyrit/output/finding_report/markdown.py | Uses availability-aware evidence notes. |
| pyrit/output/finding_publisher/plan.py | Plans publication order and hierarchy. |
| pyrit/output/finding_publisher/errors.py | Defines publication errors. |
| pyrit/output/finding_publisher/base.py | Implements the publisher contract. |
| pyrit/output/finding_publisher/azure_devops.py | Implements Azure DevOps publishing. |
| pyrit/output/finding_publisher/__init__.py | Introduces the publisher package. |
| pyrit/output/__init__.py | Exports selection and publishing APIs. |
| pyrit/models/finding_publication.py | Defines preview and result models. |
| pyrit/models/__init__.py | Exports publication models. |
| pyrit/backend/services/operation_service.py | Reuses shared evidence resolution. |
| pyrit/backend/services/finding_export.py | Builds exports from shared selections. |
| pyrit/backend/routes/operations.py | Maps selection errors to HTTP responses. |
| doc/code/output/0_output.py | Documents reports and publishing. |
| doc/code/output/0_output.ipynb | Adds matching notebook documentation. |
| .github/instructions/output.instructions.md | Defines publisher responsibilities and safeguards. |
Review effort: Balanced
| run.fail(item=item, message=str(exc), outcome_unknown=exc.outcome_unknown, diagnostics=exc.diagnostics) | ||
| return False | ||
| except Exception: | ||
| logger.warning("Finding publish run %s stopped on an unexpected error.", run.run_id, exc_info=True) |
There was a problem hiding this comment.
Keep exc_info on both handlers; this adapter does not log the reported values
I checked both paths at 6714788. At base.py:325, AzureDevOpsFindingPublisher wraps every HTTP status, httpx.RequestError and timeout into FindingPublishCreateError, and the base records that error by its message only, with no log. Only errors that the adapter does not expect reach this handler: a programming error (including the new TypeError for an invalid hook result, whose text is only a type name), httpx.InvalidURL from the configuration, a raw ssl.SSLError, or UnicodeEncodeError from a non-ASCII token. Their text holds no token, name, email, title or field value; a scratch run that forces the UnicodeEncodeError on a create logs a traceback with none of them. At azure_devops.py:658, the token provider takes no arguments, so no finding value can reach its error, and azure-identity errors give each credential's failure reason, not a token. A test that makes the provider's error quote its token tests a provider bug that no shipped provider has. A third-party adapter whose unexpected error quotes a field value would put it in this log, but that value is operator data, which the framework says not to redact; only PyRIT's credentials must stay out. To make the rule match, say at output.instructions.md:79 that the traceback of an unexpected error is kept. The traceback is the only logged diagnostic for the unexpected-failure result and for the token message, which tells the user to ask an administrator, so removing it makes these failures hard to fix. The one credential path I found is the exception chain, not the log: see the comment at azure_devops.py:660.
A cancelled publish logged the item whose create was in flight as not attempted, although its request may have reached the destination. The run now tracks that item and the summary reports it as "in flight 1 (outcome unknown)". Problems are now listed in plan order, as the validation error documents. Tests now fail if the History or other HTML fields go unescaped, another visualstudio.com organization is accepted, a 3xx counts as a known outcome, the project or type comparison becomes case-sensitive, a lone surrogate is allowed in a title, or a request starts with less than a full timeout left. The two real-timeout tests shorten only the hanging request's timeout. The output guide's in-memory publisher is now a runnable cell, and the guide notes that PyRIT's default severity and harm_type fields must be unmapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assert the exact summary line of a run that creates every item, so a run that forgets to clear its in-flight item fails the tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address review of the finding selection: - FindingSelection holds data only: operation_id, operation_name, the findings, their resolved evidence, and part_of, with no defaults. - build_finding_report(*, selection, fields, link_for=None) projects the evidence. _project_evidence and _score_text move into report.py, and link_for moves from the selection to the report. build_finding_report is exported from pyrit.output. - The report's opening note mentions dashboard links only when a link builder is given, instead of walking the entries. - ResolvedFindingEvidence moves to pyrit.models, and the resolver becomes MemoryInterface.get_resolved_finding_evidence_async, still batched by 500. The selection builder and the backend evidence page both call it, so report.py and selection.py don't import each other. - Remove FindingReportEntry.finding_id until the publish planner reads it. Export output is byte-identical to main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Link two pieces of evidence to one finding at different times, and assert the selection and the report list them newest first. - Project a score with no scorer identifier, and one with an empty class name, through build_finding_report and expect "<value> (Unknown)". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turn the fenced example into a code cell that records an Operation with one finding in the guide's in-memory database, then reads, builds, and prints its report. The stored output comes from executing the cell. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR microsoft#4836 now keeps FindingSelection as data only, builds reports with build_finding_report(selection=..., fields=..., link_for=...), resolves evidence in memory, and no longer adds FindingReportEntry.finding_id. The only conflict, in pyrit/output/__init__.py, keeps both sides: microsoft#4836's report exports and the publisher exports. The publishers are adapted in the following commits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
build_finding_report sets each entry's saved finding ID, so a publish plan can join a report entry to its finding. No report format shows the field, so the Word and Markdown exports don't change. microsoft#4836 dropped the field to land it with its consumer, the planner in this branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The planner now lays a selection out with build_finding_report, like the exports do. preview_async and publish_async take a keyword-only link_for and pass it through, so evidence in published items can link back, for example to a public dashboard route. Links stay out of the publisher's identifier and out of the plan digest: they change what an item says, not which items are created or where. The output guide, its runnable in-memory publisher and the output instructions use the new selection and link_for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t availability Make FindingReportEvidence.available optional. None infers availability from link_url, as in PyRIT 1.2, so evidence built by hand keeps its old behavior. build_finding_report still sets it explicitly, so intact evidence without a link is not shown as unavailable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing a preview returns depends on evidence links: the plan digest leaves them out, and the problem checks read only titles and values. So preview_async no longer takes link_for, and publish_async keeps it. The digest test now publishes with links against the digest of a preview without them, so it fails if links ever enter the digest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
microsoft#4836 makes FindingReportEvidence.available optional, so evidence built without it infers availability from its link again. The only conflict, in tests/unit/output/finding_report/test_report.py, keeps both added tests: this branch's finding_id test and microsoft#4836's availability test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The base recorded a created item after the guarded call to _create_item_async. If a publisher returned something other than a FindingPublishedItem, the exception escaped after the item may already have existed, which broke the rule that only cancellation escapes after the first create. The run now checks and records the returned item inside the guard. An invalid result becomes the run's failure with an unknown outcome, the rest are not attempted, and the summary still logs. Recording reads the item before changing the run, so a bad value can't leave it half updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ty doesn't read mypy-style error codes in type-ignore comments, so the fake publisher's deliberately invalid return value now uses cast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
None, a string and a dict all fail when the run reads external_id, so the type check on a create's result went untested. A look-alike object with external_id now has to be reported as a possibly-created failure too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| # ``` | ||
| # | ||
| # This example assumes a deployment's configured finding fields. PyRIT's default fields let `severity` | ||
| # and `harm_type` take Other text, so with the defaults, list both in `unmapped_keys`. |
There was a problem hiding this comment.
[P3] Tell readers to remove severity from field_map with the default fields
This text says that with PyRIT's default fields you list severity and harm_type in unmapped_keys. The example above still maps severity in field_map, so a reader who follows the advice gets FindingPublisherConfigurationError: 'severity' is in both field_map and unmapped_keys. Say to move severity from field_map to unmapped_keys with harm_type, or show a configuration that passes with DEFAULT_FINDING_FIELDS: map only description (HTML) and list severity and harm_type in unmapped_keys. The constructor and check_fields do no I/O, so you can make it a code cell that runs offline.
| "unexpected error", | ||
| ], | ||
| ) | ||
| async def test_publish_accounts_for_every_planned_finding_exactly_once( |
There was a problem hiding this comment.
[P3] Assert that a failed create is sent once
The contract says that a create is never retried, because a retry can make a duplicate item. No test counts create calls after a failure. A mutant that retries an unknown-outcome create in _create_next_async passes every test in test_base.py and test_plan.py. In test_azure_devops.py, only test_publish_classifies_a_failed_create[500] catches it, and only because its one-item side_effect list is used up, which gives a misleading failure. In this test, assert that publisher.calls holds one create for the failing item. In test_publish_classifies_a_failed_create, let the route answer on every call and assert call_count == 1.
| assert relation["url"] == f"{ORG}/_apis/wit/workItems/501" | ||
|
|
||
|
|
||
| async def test_publish_appends_part_of_paths_and_retired_fields_to_the_description( |
There was a problem hiding this comment.
[P3] Test HTML escaping of path text and the link-scheme rule
_paths_html escapes path names, path descriptions and step titles, but this test uses only plain words ("Chain", "Two steps", "Step"), so a change that removes that escaping passes every publisher test. A step title with <img onerror=...> would then reach the Description as live HTML. No HTML-field value has a control character, so removing plain_text from _html also passes. The link test tries only javascript:, so allowing ftp: or a link with a space or tab also passes. Put <b> and & in the path name, description and step title and assert the escaped output. Add one value with a control character and a CRLF, and add ftp://host/x, https://a b and a link with a tab to the evidence link test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The library wrote CoPyRIT and server wording for every caller, including
notebooks: the History note said "Published from CoPyRIT by a CoPyRIT user",
the token error named a server and an administrator, and the plan-changed
error named the GUI's Check button and blamed only the findings, although the
digest also covers the destination and the publisher.
- History note: "Published from PyRIT by {who}", with "an unknown requester"
when the requester isn't known.
- Token error: names the token provider and its Azure credential.
- Plan-changed error: the findings, the destination or the publisher changed
since the preview; preview again.
- A create that might have succeeded says to look for the work item in Azure
DevOps rather than "Check Azure DevOps".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A token provider that returned a token with a line break, surrounding whitespace or a control character made h11 raise an error that quotes the Authorization header, so the token reached the exception chain of FindingPublisherUnavailableError. A non-ASCII token escaped as a raw UnicodeEncodeError. The adapter now treats a token that isn't printable ASCII without surrounding whitespace as a token failure before it builds a request: it logs a fixed warning and raises the token error without the value or a chained cause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A request that failed on a transport error, such as a dropped connection or a write error, left no diagnostics, so the run summary and a destination error didn't say what happened. Each transport branch now records the error's type name, never its message, which can quote the request's headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A failed create, including one whose outcome is unknown, is sent once. - Path names, path descriptions and step titles are escaped, and HTML values go through plain_text, so a CRLF becomes one line break and a control character is marked. - Evidence gets a link only for an absolute http or https URL: ftp, relative, whitespace and control-character links are written without one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- framework.md: Output also publishes selected findings to another system; a publisher returns what it created and every outcome, so it isn't a sink; the builders and sources that gather a report's input may read memory. The maintainers agreed to this responsibility in the design's step 0. - output.instructions.md: the three-layer rule covers printers only, list all four FindingPublisher hooks with the identifier rule, and say that an unexpected error keeps its traceback while PyRIT's own credentials never reach a log or an error. - Output guide (.py and paired .ipynb): name the four hooks, give a default-field configuration that passes check_fields, and say the plan digest also covers the destination and the publisher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Description
Lets the library gather an Operation's selected findings and publish them to another system, starting with Azure DevOps, so notebooks and CoPyRIT share one path. This is steps 1, 2 and 2b of the publishing design. It depends on step 0, the maintainers agreeing that Output's responsibility grows to cover publishing, so
doc/code/framework.mdis unchanged.build_finding_selection_asyncreads findings and evidence into a data-onlyFindingSelection.MemoryInterface.get_resolved_finding_evidence_asyncreturnspyrit.models.ResolvedFindingEvidence.build_finding_report(selection=..., fields=..., link_for=...)lays it out. Export uses these, and its output is unchanged.FindingPublisher.preview_asyncshows where each finding goes, with a plan digest.publish_asyncchecks the digest, creates items parents first, and reports each finding once: created, skipped, failed (outcome_unknownif it might exist) or not attempted. It takeslink_forso evidence links back. Subclasses implement two hooks.nest_sub_findings=Falseturns nesting off, so AIRT can turn it off if Q14 says no.AzureDevOpsFindingPublishercreates work items through REST 7.1 under a pasted work item ID or URL, which is parsed, never fetched. Requests time out after 30 seconds, creates aren't retried, andbypassRulesis never set. Titles and text values must be one line of at most 255 characters as Azure DevOps counts them (emoji count as two), and are never cut.infosupplies the label and hint that the step-3 dialog will show.severityandharm_typeinunmapped_keys.🤖 Generated with Claude Code