Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
f36db28
FIX: Reject path parameters by default when building components from …
varunj-msft Oct 26, 2026
291c462
Leave out target types that require a path callers may not set
varunj-msft Oct 26, 2026
797831b
Test a target whose required path is the server upload folder
varunj-msft Oct 26, 2026
214a0fa
Merge origin/main
varunj-msft Nov 2, 2026
521ec7e
TEST: Cover saved converter copies in the server path check
varunj-msft Nov 2, 2026
66fd155
FEAT: Report the documents a storage listing cannot use
varunj-msft Nov 2, 2026
2d8c465
Report non-files and missing containers instead of skipping them
varunj-msft Nov 2, 2026
5dec828
Report an entry that can't be checked instead of failing the whole li…
varunj-msft Nov 2, 2026
bf662b7
FEAT: Read saved registry recipes
varunj-msft Nov 2, 2026
e8b0604
Merge the server path check for API input
varunj-msft Nov 2, 2026
9143ea6
FEAT: Rebuild saved registry entries in dependency order
varunj-msft Nov 2, 2026
cfa4fc0
Limit technique descriptions like the create request and export the r…
varunj-msft Nov 2, 2026
33735f1
Merge the recipe model limits and exports
varunj-msft Nov 2, 2026
11d0519
Keep restore failure messages safe and complete, and check technique …
varunj-msft Nov 2, 2026
e45865b
Test that a description at the limit is accepted
varunj-msft Nov 3, 2026
b6927a9
Merge the description limit test
varunj-msft Nov 3, 2026
c94ffbd
Show only the error type when a URL in it may carry credentials
varunj-msft Nov 3, 2026
8663852
Cut failure messages at any URL query or fragment and hide any with u…
varunj-msft Nov 3, 2026
9a419b4
Escape text that isn't UTF-8 in restore reports so they can be sent a…
varunj-msft Nov 3, 2026
8fb8095
Merge the report text escaping
varunj-msft Nov 3, 2026
9a67367
Read error text as plain normalized text and say when part of it is h…
varunj-msft Nov 3, 2026
274b4ce
Escape entry names in restore reports too
varunj-msft Nov 3, 2026
95f9492
Merge the entry name escaping
varunj-msft Nov 3, 2026
a60323a
Show error text with its original characters
varunj-msft Nov 3, 2026
e7558a4
Test that a reference name that isn't valid text can still be reported
varunj-msft Nov 3, 2026
c391b0d
Escape report text only when it is sent as JSON
varunj-msft Nov 3, 2026
0b44db6
Merge the JSON-only report escaping
varunj-msft Nov 3, 2026
f986da5
Check each character on its own so long error messages stay fast
varunj-msft Nov 3, 2026
c86bfe6
Check the exact message for every form of each mark and bound the wor…
varunj-msft Nov 3, 2026
a455494
Pass the look-alike check's arguments by keyword
varunj-msft Nov 3, 2026
ce8b684
Test that a technique waits for a saved converter in either list and …
varunj-msft Nov 3, 2026
507567b
Check the opened file before reading it and skip links deleted since …
varunj-msft Nov 3, 2026
9d37ba3
Merge the opened-file check
varunj-msft Nov 3, 2026
ff2c836
Merge the opened-file check
varunj-msft Nov 3, 2026
3afdcaa
Merge origin/main
varunj-msft Nov 3, 2026
de2f4e3
Let restore set the path parameters a target lets callers set, as the…
varunj-msft Nov 3, 2026
a45ac23
Close a file that isn't regular before reporting it and report entrie…
varunj-msft Nov 3, 2026
60477e8
Merge the file handle fix
varunj-msft Nov 3, 2026
28f2262
Merge the file handle fix
varunj-msft Nov 3, 2026
ad21f0c
Give only targets the path parameters their class lets callers set
varunj-msft Nov 3, 2026
db245dc
Test a file replaced just before it's opened and stop a blocked read …
varunj-msft Nov 4, 2026
5d3d2d0
Merge the opened-file tests
varunj-msft Nov 4, 2026
07a617f
Merge the opened-file tests
varunj-msft Nov 4, 2026
80754a2
Read saved recipes separately from building them
varunj-msft Nov 4, 2026
d1bdd82
List presets, suites, and initializers through the checked listing
varunj-msft Nov 5, 2026
f5ed760
Merge the shared document listing
varunj-msft Nov 5, 2026
4b55b17
Merge the shared document listing
varunj-msft Nov 5, 2026
76dbf9c
Report a preset, suite, or initializer folder that can't be read as u…
varunj-msft Nov 5, 2026
f823e4b
Merge the storage error mapping for unreadable folders
varunj-msft Nov 5, 2026
99da684
Merge the storage error mapping for unreadable folders
varunj-msft Nov 5, 2026
7d9ac2f
Log why storage is unavailable, without its path or URL
varunj-msft Nov 7, 2026
7b5bfeb
Merge the storage error logging
varunj-msft Nov 7, 2026
22806d8
Merge the storage error logging
varunj-msft Nov 7, 2026
34011c9
Hide a restore message with a percent escape, which can hide a creden…
varunj-msft Nov 7, 2026
031dc61
Merge origin/main
varunj-msft Nov 8, 2026
7f8ab0d
Merge origin/main
varunj-msft Nov 8, 2026
19205b1
Import the saved recipe models from their package, as main now requires
varunj-msft Nov 8, 2026
0348a0b
Merge origin/main
varunj-msft Nov 8, 2026
bba3afd
Import from public packages, as main now requires
varunj-msft Nov 8, 2026
622bbb8
Report storage failures with one error and answer them with 503
varunj-msft Nov 9, 2026
1cae0b9
Merge the single storage error
varunj-msft Nov 9, 2026
eba7bf2
Escape file names once and simplify the saved recipe models
varunj-msft Nov 9, 2026
9f24124
Merge the recipe model simplification
varunj-msft Nov 9, 2026
2bbfc8f
Report restore bugs as build errors and log each failure once
varunj-msft Nov 9, 2026
6ee84f0
Merge origin/main
varunj-msft Nov 10, 2026
d43a7e8
Merge origin/main
varunj-msft Nov 10, 2026
0664063
Merge origin/main
varunj-msft Nov 10, 2026
8614025
Use one recipe format version, keep the auth mode, and escape failure…
varunj-msft Nov 10, 2026
5a3f18b
Merge the recipe format changes
varunj-msft Nov 10, 2026
b3c7847
Build restored entries with a builder the caller supplies
varunj-msft Nov 10, 2026
986cc90
Test the parser's depth limit without depending on the stack size
varunj-msft Nov 10, 2026
1096925
Merge the parser depth test fix
varunj-msft Nov 10, 2026
f59306e
Read saved recipes off the event loop by default, and harden URL reda…
richlundeen Nov 10, 2026
f1ff143
Keep an "@" in a URL's path when redacting URLs in text
richlundeen Nov 10, 2026
374c620
Merge main
varunj-msft Nov 11, 2026
7ac059c
Answer suite readiness storage failures through the shared storage ha…
varunj-msft Nov 11, 2026
e08b67a
Merge main
varunj-msft Nov 11, 2026
7fa4ca4
Expect storage errors from main's version-checked delete tests the wa…
varunj-msft Nov 11, 2026
c506195
Merge main
varunj-msft Nov 11, 2026
1ba526f
Merge main
varunj-msft Nov 11, 2026
9cdf7e7
Merge main
varunj-msft Nov 11, 2026
0e7a21f
Exempt the storage error handler from the keyword-only check
varunj-msft Nov 11, 2026
c35fa01
Merge keyword-only fixes
varunj-msft Nov 11, 2026
953dcce
Merge keyword-only fixes
varunj-msft Nov 11, 2026
35199cc
Leave the error behind a storage failure out of the logs
varunj-msft Nov 12, 2026
efcdfa9
Test a blob upload that fails with a transport or authentication error
varunj-msft Nov 12, 2026
0fdebdc
Merge the storage log and restore report fixes
varunj-msft Nov 12, 2026
c413994
Merge the storage log and restore report fixes
varunj-msft Nov 12, 2026
c9b795a
Merge main
varunj-msft Nov 12, 2026
38c981c
Merge main
varunj-msft Nov 12, 2026
eb71448
Merge main
varunj-msft Nov 12, 2026
0acbe04
Merge main
varunj-msft Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions pyrit/common/azure_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

"""Lightweight Azure Storage URI helpers."""

import re
from urllib.parse import parse_qs, urlparse

# A scheme followed by "://" and everything up to whitespace, so a quote can't end a URL before its query.
# A scheme starts only where one can't continue from the character before it, such as after "_" or a
# space, so each run of scheme characters is scanned once and long text stays fast.
_URL_IN_TEXT = re.compile(r"(?<![A-Za-z0-9+.-])[A-Za-z][A-Za-z0-9+.-]*://\S+")
# The signature of a SAS token, which can also appear in text without a scheme.
_SAS_SIGNATURE = re.compile(r"(?i)\bsig=[^&\s]+")


def is_azure_blob_uri(value: str, *, min_path_segments: int = 1) -> bool:
"""
Expand Down Expand Up @@ -48,9 +56,30 @@ def has_sas_signature(value: str) -> bool:

def redact_url_credentials(value: str) -> str:
"""
Remove query parameters and fragments from a URL for display or logging.
Remove the user name and password, query parameters, and fragment from a URL for display or logging.

Returns:
str: The URL without them.
"""
parsed = urlparse(value)
return parsed._replace(netloc=parsed.netloc.rpartition("@")[2], query="", fragment="").geturl()


def redact_urls(text: str) -> str:
"""
Remove the user name and password, query parameters, and fragment from every URL in a text.

A query or user name can hold a credential, such as a SAS token. A URL that can't be parsed is
hidden entirely, and a SAS signature is hidden wherever it appears.

Returns:
str: The URL without query parameters or a fragment.
str: The text with each URL redacted.
"""
return urlparse(value)._replace(query="", fragment="").geturl()

def redact(match: re.Match[str]) -> str:
try:
return redact_url_credentials(match.group(0))
except ValueError:
return "<URL hidden>"

return _SAS_SIGNATURE.sub("sig=<hidden>", _URL_IN_TEXT.sub(redact, text))
2 changes: 2 additions & 0 deletions pyrit/models/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ComponentRecipe,
IgnoredRecipeFile,
RegistryRecipeKind,
RegistryRestoreReport,
RestoreFailure,
RestoreFailureReason,
SavedEntryRef,
Expand Down Expand Up @@ -76,6 +77,7 @@
"PresetIssue": "pyrit.models.catalog.scenario_preset",
"RegisteredInitializer": "pyrit.models.catalog.initializer",
"RegistryRecipeKind": "pyrit.models.catalog.registry_recipe",
"RegistryRestoreReport": "pyrit.models.catalog.registry_recipe",
"RestoreFailure": "pyrit.models.catalog.registry_recipe",
"RestoreFailureReason": "pyrit.models.catalog.registry_recipe",
"SavedEntryRef": "pyrit.models.catalog.registry_recipe",
Expand Down
8 changes: 8 additions & 0 deletions pyrit/models/catalog/registry_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,11 @@ class IgnoredRecipeFile(BaseModel):
kind: RegistryRecipeKind
file_name: str
message: str


class RegistryRestoreReport(BaseModel):
"""What a restore rebuilt, what it couldn't, and which files it skipped."""

restored: list[SavedEntryRef] = Field(default_factory=list)
failures: list[RestoreFailure] = Field(default_factory=list)
ignored: list[IgnoredRecipeFile] = Field(default_factory=list)
47 changes: 32 additions & 15 deletions pyrit/registry/components/attack_technique_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from pyrit.models import AttackIdentifier, ComponentType
from pyrit.models.component_spec import SourceInstanceSpec
from pyrit.registry.instance_registry import DefaultInstanceRegistry
from pyrit.registry.instance_registry import DefaultInstanceRegistry, RegistryNameTakenError
from pyrit.registry.registry import Registry
from pyrit.registry.registry_metadata import RegistryMetadata

Expand Down Expand Up @@ -132,6 +132,14 @@ class AttackTechniqueMetadata(RegistryMetadata):
"""Shared metadata type for the inherited, empty technique class catalog."""


class TechniqueSelectorConflictError(RegistryNameTakenError):
"""A technique's name or tag conflicts with the name or a tag of a registered technique."""


class TechniqueAdmissionError(ValueError):
"""A technique can't be registered for a reason of its own, such as a name a scenario can't use."""


class TechniqueInstanceRegistry(DefaultInstanceRegistry["AttackTechniqueFactory"]):
"""Factory storage with an atomic runtime-admission path."""

Expand All @@ -140,7 +148,9 @@ def register_runtime(self, factory: AttackTechniqueFactory) -> None:
Check selector collisions while holding the same lock as registration.

Raises:
ValueError: If the name or a tag conflicts with an existing selector.
TechniqueSelectorConflictError: If the name or a tag conflicts with another technique's name or tag.
TechniqueAdmissionError: If a tag repeats the technique's own name, a selector can't become a scenario
member, or the factory doesn't fit the scenarios it would join.
"""
from pyrit.registry.components.scenario_registry import ScenarioRegistry

Expand All @@ -152,23 +162,30 @@ def register_runtime(self, factory: AttackTechniqueFactory) -> None:
tags = {tag.casefold(): tag for entry in entries for tag in entry.instance.technique_tags}
folded_name = factory.name.casefold()
if folded_name in names:
raise ValueError(f"Technique '{factory.name}' already exists (names are case-insensitive)")
raise TechniqueSelectorConflictError(
f"Technique '{factory.name}' already exists (names are case-insensitive)"
)
if folded_name in tags:
raise ValueError(f"Technique name '{factory.name}' conflicts with an aggregate tag")
raise TechniqueSelectorConflictError(f"Technique name '{factory.name}' conflicts with an aggregate tag")
for tag in factory.technique_tags:
folded = tag.casefold()
if folded in names or folded == folded_name:
raise ValueError(f"Tag '{tag}' conflicts with a technique name")
if folded == folded_name:
raise TechniqueAdmissionError(f"Tag '{tag}' repeats the technique's name")
if folded in names:
raise TechniqueSelectorConflictError(f"Tag '{tag}' conflicts with a technique name")
if folded in tags and tags[folded] != tag:
raise ValueError(f"Tag '{tag}' conflicts with tag '{tags[folded]}'")
_validate_generated_member_collisions(
class_name="ScenarioTechnique",
factories=[factory],
aggregate_tags=set(factory.technique_tags) - {"all", "default"},
)
AttackTechniqueRegistry.get_registry_singleton().validate_scenario_pools(
{**{entry.name: entry.instance for entry in entries}, factory.name: factory}
)
raise TechniqueSelectorConflictError(f"Tag '{tag}' conflicts with tag '{tags[folded]}'")
try:
_validate_generated_member_collisions(
class_name="ScenarioTechnique",
factories=[factory],
aggregate_tags=set(factory.technique_tags) - {"all", "default"},
)
AttackTechniqueRegistry.get_registry_singleton().validate_scenario_pools(
{**{entry.name: entry.instance for entry in entries}, factory.name: factory}
)
except ValueError as error:
raise TechniqueAdmissionError(str(error)) from error
self.register(factory, name=factory.name, tags=factory.technique_tags)


Expand Down
13 changes: 9 additions & 4 deletions pyrit/registry/instance_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def get_identifier(self) -> ComponentIdentifier:
T = TypeVar("T", bound=SupportsIdentifier) # The type of items stored


class RegistryNameTakenError(ValueError):
"""A name is already registered, so another entry can't take it."""


@dataclass
class RegistryEntry(Generic[T]):
"""
Expand Down Expand Up @@ -286,8 +290,8 @@ def register(
Raises:
TypeError: If this registry was created with an ``instance_type`` and
``instance`` is not of that type.
ValueError: If the name is reserved or already registered and ``replace``
is False.
ValueError: If the name is reserved.
RegistryNameTakenError: If the name is already registered and ``replace`` is False.
"""
expected_type = self._resolve_instance_type()
if expected_type is not None and not isinstance(instance, expected_type):
Expand Down Expand Up @@ -334,13 +338,14 @@ def validate_name_available(self, name: str) -> None:
name (str): The proposed registry name.

Raises:
ValueError: If the name is reserved or already registered.
ValueError: If the name is reserved.
RegistryNameTakenError: If the name is already registered.
"""
with self._lock:
if name in self._reserved_names:
raise ValueError(f"Instance name '{name}' is reserved")
if name in self._registry_items:
raise ValueError(f"Instance '{name}' already exists")
raise RegistryNameTakenError(f"Instance '{name}' already exists")

def unregister(self, name: str, *, expected_entry: RegistryEntry[T] | None = None) -> T | None:
"""
Expand Down
Loading
Loading