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

オープン
#6,390 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
django, python
領域
api, backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
JavaScript
スター
214
フォーク
327
平均マージ
17時間 5分
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

learningequality/studio のほかの issue

learningequality/studio の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。