Repository navigation
FIX: Apply the request limits to request fields added since the last limits PR - #3595
Open
varunj-msft wants to merge 7 commits into
Open
varunj-msft wants to merge 7 commits into
varunj-msft wants to merge 7 commits into
Conversation
…limits PR Operation and finding text, component source specs and target bindings, the paired-outcome group ids, preset and suite descriptions and authors, version preconditions, and technique edit descriptions and dependency identities now use the shared identifier, text, and item limits. Operations, findings, and target bindings are checked only on requests, so rows already saved keep loading. The paired-outcome group ids get an explicit Query max_length, because FastAPI drops the annotated limit on a required query parameter.
Assert the exact status for a dependency identity at the limit, and cover the binding limit on message sends, which inherit it from the add-message request.
The title search becomes a LIKE pattern, which SQL Server limits to 8,000 bytes, and escaping can double its length. It now has the same 1,000-character limit as the dataset search.
The preset and suite names, and the preset names a suite lists, came in after the last limits PR without a length limit. The registry-name check puts the name in its error message, so an invalid name was echoed in full in the 422 response. Cap them at the shared identifier limit, which rejects an over-limit name before that check runs.
Keep the limit on the preset resolve version, which main moved to pyrit.models.catalog.scenario_preset.
The suite launch request came in after the last limits PR. Give its suite version and each entry's preset name and version the shared identifier limit, like the other versions sent with a request. Also give this PR's suite route tests the one-line docstrings the rest of that file has.
The preset and suite routes came in after the last limits PR and read the name in the URL as a plain string, unlike the other routes' path identifiers. Use IdentifierStr, so an over-limit name gets a 422 before the route runs.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem. Request fields added after #3174 skip the shared limits. Main accepts 100,001-character operation, finding, preset, suite, and technique-edit text, echoes 300-character source, preset, and suite names back in error responses, and lets a 257-character paired-outcome group id reach the handler, because FastAPI drops an annotated limit on a required query parameter.
Change. These fields now use the shared identifier, text, and item limits:
OperationUpdateRequest, and the newOperationCreateRequestandFindingUpdateRequest(whichFindingCreateRequestnow extends).LIKEpattern, which SQL Server limits to 8,000 bytes, and escaping can double its length.TargetBindingInputthat still returns a plainTargetBinding, so request and saved bindings still compare equal.SourceInstanceSpec: names, hashes, and parameter keys (256), and at most 100 parameters.source_identity).Query(..., max_length=...), the fix FIX: Apply the request limits to the remaining request fields #3174 used forconversation_id.Limits go on the backend request models where one saved over-limit row would break a whole listing (operations, findings, and target bindings, which every attack summary re-reads), and on the shared models elsewhere, most of which already limit other fields.
MAX_TEXT_LENGTHmoves topyrit/models/request_limits.py, following Rich's comment on #2960;pyrit/backend/models/common.pyimports it from there.What stays the same. Values within the limits; saved operations, findings, and target bindings, which still load; building operations, findings, and target bindings in Python; and prompt content and free-form parameter values (still limited only by the body size). The shared preset, suite, suite-launch, technique-edit, and source-spec models apply their new limits to Python callers too, as #2960 did for scenario runs. So a saved preset or suite over a limit is skipped as invalid, a saved run whose technique edit is over a limit can't be resumed, and a saved target binding with an over-limit name can't be rebuilt. None of these models are in v1.1.0. Preset resolve and suite launch take their other fields from
ScenarioLaunchConfiguration, which already limits them. The author the routes fill in for the signed-in user is the Microsoft Graph display name or email, which fit the 256 limit.Tests and Documentation
pytest -n 8 --dist=loadfile tests/unit/backend tests/unit/models tests/unit/registry: 6,514 passed, 4 skipped.uv run --frozen --extra all --link-mode=copy ty check pyrit: all checks passed.pyrit/backend/README.md: the Request Limits list now names titles and descriptions.No JupyText changes.