Invitation, recommendation and Stripe webhook endpoints crash on malformed input

Open
#6,389 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api, backend, security

Research direction

Start with the three named entry points: contentcuration/contentcuration/views/users.py (send_invitation_email), contentcuration/contentcuration/viewsets/recommendation.py (RecommendationView.post), and contentcuration/contentcuration/views/subscription.py (stripe_webhook and its serializers). Follow the validation strategy in issue #6387 and add regression tests for every reproduced input listed here. Done means malformed invitation and recommendation requests return 400, while the two invalid Stripe events return 200 without changing the subscription.

Written by the indexing model from the issue text.

Description

DEV: backend

Overview

send_invitation_email and RecommendationView read request.data by key without a serializer, and the Stripe webhook's serializers accept two payload shapes that then crash. A body of the wrong shape, or a field of the wrong type, length or value, raises an exception and the request returns 500.

Complexity: Medium
Target branch: hotfixes

Context

All sites below fail with the inputs shown, and each input was reproduced:

  • send_invitation_email: a JSON list body, user_email: 5, a 120-character email, a 60-character share_mode, a user_email containing a newline (BadHeaderError), and a nonexistent channel_id (DoesNotExist, raised before the permission check). It also stores not an email as an invitation, and any share_mode other than VIEW_ACCESS grants edit access on accept.
  • RecommendationView.post: a JSON list body, a JSON string body, or a form-encoded body. request.data.pop runs before the schema check.
  • stripe_webhook, after the signature check passes: a customer.subscription.updated event with status active and empty items.data raises IndexError in save. A current_period_end of 10**15 raises ValueError in TimestampField.to_internal_value, which is_valid doesn't catch. Stripe retries a webhook that returns 500.
The Change
  • send_invitation_email and RecommendationView should validate their bodies with DRF serializers, following the strategy in #6387, and return 400 for malformed input.
  • send_invitation_email should accept only a valid email address and a share_mode of EDIT_ACCESS or VIEW_ACCESS.
  • stripe_webhook should handle these payloads like any other event its serializer rejects: log a warning and return 200 without changing the subscription.
Acceptance Criteria
General
  • Every input listed in Context for send_invitation_email and RecommendationView returns 400 instead of 500.
  • send_invitation_email returns 400 and creates no invitation for an invalid email address or a share_mode other than EDIT_ACCESS or VIEW_ACCESS.
  • The two Stripe payloads in Context return 200 and leave the user's subscription unchanged.
Testing
  • Each input in Context has a regression test.

AI usage

I scoped the audit and chose the validation strategy in #6387. Claude Code found and reproduced these failures and drafted this issue.

Dominant language
JavaScript
Stars
214
Forks
327
Avg merge
17h 5m
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from learningequality/studio

All issues in learningequality/studio

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.