Reject Model Target request bodies which are not valid UTF-8 - #3440
Merged
Conversation
Dataset creation decoded the request body through ``json.loads``, which raises ``UnicodeDecodeError`` rather than ``JSONDecodeError`` for a body which is not valid UTF-8, so the mock raised instead of returning the Vuforia-shaped ``Invalid Json`` error. The OAuth2 token route decoded its form body strictly and raised in the same way. Towards #3193. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Aug 13, 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.
Towards #3193.
What
POST /modeltargets/datasets,POST /modeltargets/advancedDatasetsandPOST /oauth2/tokenraised an uncaughtUnicodeDecodeErrorwhen given a request body which is not valid UTF-8.Dataset creation passed the raw body to
json.loads, which decodes internally and raisesUnicodeDecodeError— aValueErrorbut not aJSONDecodeError, so it fell through theexcept json.JSONDecodeErrorclause. The OAuth2 token route calledrequest.body.decode(encoding="utf-8")with no handling at all.This is the same category as #3391 and #3392: a body-parsing path which raises rather than returning an error response.
Changes
400/ERROR/Invalid Json: ...response for a body which is not valid UTF-8, as it already does for malformed JSON.TestInvalidJson::test_body_not_utf_8, which runs over every Model Target endpoint via themodel_target_endpointfixture: body-reading endpoints return the error, body-less endpoints ignore the body as before.TestMockOnlyErrors::test_oauth2_token_body_not_utf_8is mock-only because the real response to a form body which cannot be decoded has not been observed.docs/source/differences-to-vws.rstrecords both behaviours.Testing
tests/mock_vws/test_model_target_web_api.pypasses against the in-memory and Docker-in-memory backends. The real-Vuforia parametrisations need CI secrets and are not run locally.🤖 Generated with Claude Code