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

Aperta
#6,390 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
django, python
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
JavaScript
Stelle
214
Fork
327
Merge medio
17h 5m
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di learningequality/studio

Tutte le issue di learningequality/studio

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.