Skip to content

Return 400 instead of 500 when the avatar preview gets no email - #571

Open
PetrDlouhy wants to merge 1 commit into
danirus:v2from
PetrDlouhy:fix/preview-avatar-missing-email
Open

PetrDlouhy wants to merge 1 commit into
danirus:v2from
PetrDlouhy:fix/preview-avatar-missing-email

Conversation

@PetrDlouhy

@PetrDlouhy PetrDlouhy commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

A POST to the avatar preview endpoint without an email field (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_avatar view use it.

Tests added for both views.

🤖 Generated with Claude Code

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>
@PetrDlouhy PetrDlouhy changed the title Return 400 from the avatar preview API on a body without email [Suspicious comment spam alerts] Return 400 instead of 500 when the avatar preview gets no email Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant