fix(api): return a clear 400 when a scan import exceeds upload limits - #15993
Merged
Merged
Conversation
The import, reimport, and metadata-import permission checks parse request.data to resolve the target product/engagement/test before the serializer runs. When a scan import submits more form fields than DATA_UPLOAD_MAX_NUMBER_FIELDS (or a body larger than DATA_UPLOAD_MAX_MEMORY_SIZE), Django's multipart parser raises a SuspiciousOperation (TooManyFieldsSent / RequestDataTooBig) while request.data is evaluated. That exception escaped the permission check as an opaque error and generated error-reporting noise. Catch those exceptions in the three import/reimport permission classes and raise a DRF ValidationError with an actionable message instead. Also make DATA_UPLOAD_MAX_NUMBER_FIELDS configurable via DD_DATA_UPLOAD_MAX_NUMBER_FIELDS (default 10240), mirroring DD_DATA_UPLOAD_MAX_MEMORY_SIZE, so operators can raise the limit for instances that legitimately submit very large imports. Adds unit tests covering all three permission classes and the setting default. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EWbcF7wUybs9Z2bFCpEi49
|
This pull request modifies a sensitive authorization file (
Configured Sensitive Codepath Modified by Non-Allowed Author in
|
| Vulnerability | Configured Sensitive Codepath Modified by Non-Allowed Author |
|---|---|
| Description | File 'dojo/authorization/api_permissions.py' matches configured sensitive codepath pattern 'dojo/authorization/*.py' and was modified by 'claude' (commit 255ccc8) who is not in the allowed authors list. |
Comment to provide feedback on these findings.
Report false positive: @dryrunsecurity fp [FINDING ID] [FEEDBACK]
Report low-impact: @dryrunsecurity nit [FINDING ID] [FEEDBACK]
Example: @dryrunsecurity fp drs_90eda195 This code is not user-facing
All finding details can be found in the DryRun Security Dashboard.
blakeaowens
approved these changes
Sep 17, 2026
devGregA
approved these changes
Sep 17, 2026
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
The
import-scan,reimport-scan, and endpoint/generic meta-import API permission checks parserequest.datainsidehas_permissionto resolve the target product / engagement / test before the serializer runs.When a scan import submits more form fields than
DATA_UPLOAD_MAX_NUMBER_FIELDS(or a body larger thanDATA_UPLOAD_MAX_MEMORY_SIZE), Django's multipart parser raises aSuspiciousOperation(TooManyFieldsSent/RequestDataTooBig) whilerequest.datais evaluated. The surroundingtryonly caught(ValueError, TypeError), so the exception escaped the permission check as an opaque error and generated error-reporting/on-call noise, giving the caller no actionable feedback.This was observed in production on a
POST /api/v2/reimport-scan/request that exceeded the field limit.Changes
UserHasImportPermission,UserHasMetaImportPermission,UserHasReimportPermission) now catchTooManyFieldsSent/RequestDataTooBigand raise a DRFValidationError(HTTP 400) with an actionable message, instead of letting theSuspiciousOperationescape.DATA_UPLOAD_MAX_NUMBER_FIELDSis now read fromDD_DATA_UPLOAD_MAX_NUMBER_FIELDS(default10240), mirroring the existingDD_DATA_UPLOAD_MAX_MEMORY_SIZE, so operators can raise the limit for instances that legitimately submit very large imports.Pro impact
The Pro plugin does not override these permission classes or this setting, so it inherits the behavior unchanged; no companion Pro change is required.
Test results
Adds
unittests/test_import_permission_upload_limits.py:test_too_many_fields_raises_validation_error— with the field limit lowered viaoverride_settings, an oversized multipart request to each of the three permission classes raises a DRFValidationError(this fails before the fix, whereTooManyFieldsSentescapes the permission check).test_request_within_limit_parses_without_size_error— a request under the limit parses normally.test_default_value— the setting default remains10240.Ruff clean on all changed files. The core parser behavior (field-count →
TooManyFieldsSent→ converted toValidationError) was additionally verified against Django 5.2 / DRF 3.18 in isolation.Documentation
No user-facing documentation change: this adds an admin/ops environment variable following the existing
DD_DATA_UPLOAD_MAX_MEMORY_SIZEpattern and improves an error response.Checklist
bugfixbranch.bugfix,settings_changes.🤖 Generated with Claude Code
https://claude.ai/code/session_01EWbcF7wUybs9Z2bFCpEi49
Generated by Claude Code