Skip to content

Don't crash JsonWebsocketConsumer on garbage JSON - #2231

Closed
gyanu2507 wants to merge 1 commit into
django:mainfrom
gyanu2507:json-ws-malformed-close
Closed

gyanu2507 wants to merge 1 commit into
django:mainfrom
gyanu2507:json-ws-malformed-close

Conversation

@gyanu2507

Copy link
Copy Markdown

A client sending {not json used to raise JSONDecodeError out of receive() and take the worker with it. That's a cheap way to fill the admin inbox if you're using AdminEmailHandler.

Malformed frames now close the socket with 1007. Override handle_invalid_json if you want to send an error payload first.

Fixes #2219

A garbage payload used to raise JSONDecodeError out of receive() and take
the worker down. Close with 1007 instead; override handle_invalid_json if
you want to send an error body first.
@gyanu2507

Copy link
Copy Markdown
Author

Closing this to narrow my open-source work to fewer projects. Anyone is welcome to pick the change up if it's useful.

@gyanu2507 gyanu2507 closed this Nov 9, 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.

Invalid JSON messages triggers an unhandled exception in JsonWebsocketConsumer and AsyncJsonWebsocketConsumer

1 participant