Repository navigation
Return 400 instead of 500 when the avatar preview gets no email - #571
Open
PetrDlouhy wants to merge 1 commit into
Open
PetrDlouhy wants to merge 1 commit into
PetrDlouhy wants to merge 1 commit into
Conversation
PreviewUserAvatar (and the legacy preview_user_avatar view) read request.data["email"] unchecked, so a POST without an email field, or with a JSON body that is not an object, raised KeyError/TypeError and answered 500. The bundled JS always sends the field, so only other clients (scripts, scanners) hit it, but every hit is a server error. The email now goes through a small serializer: a missing field or a malformed body answers 400 with DRF's usual error body. A blank email stays valid, as the JS sends one for authenticated users. Both views share one implementation instead of two copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A POST to the avatar preview endpoint without an
emailfield (e.g.{}or a JSON list) crashes with a 500. Only the bundled JS always sends it.The body is now validated by a small serializer, so a missing email returns 400. A blank email still works (the JS sends it for logged-in users). Both the API view and the legacy
preview_user_avatarview use it.Tests added for both views.
🤖 Generated with Claude Code