`/api/sync/` accepts malformed changes and rev cursors

Open
#6,390 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
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
django, python
Domain
api, backend

Research direction

Read contentcuration/contentcuration/viewsets/sync/endpoint.py and contentcuration/contentcuration/models.py, then follow the DRF serializer strategy in issue #6387. Add regression tests for each malformed input listed in the Context; done means malformed changes appear in disallowed, malformed bodies and cursors return 400, and valid changes in the same batch are still accepted. The issue states that it is not open for contribution.

Written by the indexing model from the issue text.

Description

DEV: backend

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

/api/sync/ passes the changes and rev cursors in the request body to the database without validating them. A body that isn't a JSON object, a change with a missing or unknown field, or a rev of the wrong type raises an exception and the request returns 500. Any logged-in user can send these.

Complexity: Medium
Target branch: hotfixes

Context

All inputs below were reproduced:

  • SyncView.handle_changes and Change._create_from_change fail on:
    • a body that is a JSON list
    • changes of null or 5
    • a change missing type, with table: "nope", or with type: 999. _create_from_change raises TypeError for the last two, which DRF doesn't convert.
    • rev: "abc" or rev: 2**40
    • a change containing a created_by_id, session_key, applied or unpublishable key
    • channel_id: [1], or a channel create change with a 40-character channel_id
  • get_channel_revs and return_changes fail on channel_revs: ["a"], channel_revs: {"<id>": "abc"} or {"<id>": {}}, user_rev: "abc", and unapplied_revs: ["abc"] or 5.
The Change
  • The sync request body, each change in it, and the rev cursors should be validated with DRF serializers, following the strategy in #6387.
  • A malformed change should be rejected on its own, in the response's disallowed list with its errors, so one bad change doesn't block the rest of the batch.
  • A malformed top-level body or rev cursor should return 400.
Acceptance Criteria
General
  • Every input in Context either returns 400 or is listed in disallowed, instead of returning 500.
  • Valid changes sent in the same batch as a malformed change are still accepted.
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.