Repository navigation
Conversation
DRF's JSONParser calls json.load and catches only ValueError. A request body that is a deeply nested array makes the C decoder raise RecursionError, so every JSON endpoint answered a 500. DojoJSONParser turns RecursionError into the same ParseError, and it is now the default JSON parser. The exception handler already maps that to a 400. RequestResponseSerializerField set an empty req_resp string to [] and then called json.loads([]), which raised TypeError and gave a 500. It now returns [] early, the same as TagListSerializerField.
|
This pull request contains a critical finding where the sensitive file 'dojo/api_v2/parsers.py' was modified by an unauthorized author, 'svader0'. Although the issue is flagged as failing, it is not currently set to block the merge.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in
|
| Vulnerability | Configured Sensitive Codepath Modified by Non-Allowed Author |
|---|---|
| Description | File 'dojo/api_v2/parsers.py' matches configured sensitive codepath pattern 'dojo/api_v2/*.py' and was modified by 'svader0' (commit b440617) who is not in the allowed authors list. |
We've notified @mtesauro.
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.
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
This PR fixes two API requests that returned a 500 instead of a 400.
{"tags":+"[" * 100000 + "]" * 100000+}. DRF'sJSONParsercallsjson.loadand catches onlyValueError. The C JSON decoder raisesRecursionErrorfor this body, so the error escaped on every JSON endpoint. The newDojoJSONParser(dojo/api_v2/parsers.py) turnsRecursionErrorinto the sameParseErrorthat DRF uses for bad JSON.REST_FRAMEWORK["DEFAULT_PARSER_CLASSES"]now lists it in place ofJSONParser, and keepsFormParserandMultiPartParser. The existing exception handler then answers a 400 with{"message": "JSON request content is malformed"}.req_respstring onPOST /api/v2/findings/<id>/request_response/.RequestResponseSerializerField.to_internal_valuesetdata = []and then calledjson.loads([]), which raisedTypeError. It now returns[]early, the same asTagListSerializerFielddoes for a blank string.This is the follow-up that #17115 names. The two PRs touch nearby lines but merge cleanly in either order.
Test results
Two new tests in
unittests/test_rest_framework.py,FindingRequestResponseTest:test_deeply_nested_json_body_is_parse_error: before the fix,400 != 500withRecursionErrorin the log. After the fix it passes, and the finding title stays unchanged.test_request_response_post_empty_string_is_empty_list: before the fix,200 != 500withTypeErrorin the log. After the fix it passes, and no pair is created.I also ran
unittests.test_tagsand theFindingsTest,FindingRequestResponseTest,ImportScanTest,ReimportScanTest,ProductTestandJiraProjectTestclasses with and without the fix. The fix changes no other result.ruff checkwithruff==0.16.10passes.Documentation
No documentation change. The API uses the error message it already uses for bad JSON.
Checklist
dev.devbranch.