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

Abierto
#6,390 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
django, python
Área
api, backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
JavaScript
Estrellas
214
Forks
327
Merge medio
17 h 5 min
PR fusionados (30 d)
25

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de learningequality/studio

Todos los issues de learningequality/studio

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.