Skip to content

«Сетевой город» school search keeps a result whose id is JSON true or false, and binds the class to school 1 or 0 #149

Closed

Description

@lumenpearson

What is broken.
NetSchoolClient.schools_search keeps a search result only if its id is an integer, and it checks this with isinstance(row.get("id"), int). In Python bool is a subclass of int, so a row whose id is the JSON true or false passes the check. It is shown as a school button in the bot. Picking it binds the class to school id 1 (or 0) under the name the upstream sent with that row. The Petersburg mapper already excludes bool before int for exactly this reason (providers/petersburg/mapper.py, text and number). The netschool client has no such guard.

The failure scenario.

  1. An admin opens «⚙️ Класс», chooses to bind «Сетевой город», picks a region and types a school name.
  2. The region's /webapi/schools/search answers with a row such as {"id": true, "name": "Школа № 5"}. The row can be malformed, from a different API version, or have a boolean placeholder in place of the number.
  3. schools_search keeps it as {"id": True, "name": "Школа № 5"}. The bot stores the list in FSM data, which goes through JSON, so true comes back as True. «Школа № 5» is drawn as a button under «Выберите школу:».
  4. The admin presses it. class_diary_school runs int(school["id"]), which gives 1. The class is saved with diary_school_id = 1 and diary_school_name = "Школа № 5". The audit records «привязан «Сетевой город»: …, Школа № 5», and the bot answers «Дневник привязан».
  5. providers/diary/registry.py only checks that diary_school_id is not None, so the binding counts as valid. Every family sign-in for that class is then sent upstream with school id 1, which is a different school or none at all. The class card still shows the name the admin picked, so nothing shows the id is wrong. A row with "id": false does the same with school id 0.

Where.

  • server/app/providers/netschool/client.py:446: the filter isinstance(row.get("id"), int), which accepts a bool
  • server/app/providers/netschool/client.py:447: the kept row carries row["id"] through unchanged
  • server/app/bot/handlers/manage.py:2522: the only caller; :2530 puts the list in FSM data
  • server/app/bot/handlers/manage.py:2584: school_class.diary_school_id = int(school["id"]) turns True into 1
  • server/app/providers/diary/registry.py:81-87: the binding is accepted because the id is not None
  • server/app/providers/petersburg/mapper.py:152-165: the existing rule («bool is an int in Python») that this client does not follow

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions