Skip to content

A diary session registered from a phone names its own login, unchecked, and that login is the key to another family's corrections #165

Closed

Description

@lumenpearson

What is broken. On PR #140's branch, POST /api/v1/diary/session (server/app/api/diary.py, register_session) takes login from the request body and stores it on the session row (services/diary._open_row). The server validates the credential with its own upstream read, but nothing compares the login with the account behind that credential: Petersburg's adopt only lists the children, and «Сетевой город»'s only runs the bootstrap.

The corrections a family lays over the diary are filed under that login (services/diary.owner_key). All the corrections routes key on row.login: the schedule and homework reads, GET/PUT .../overrides, POST .../overrides/reset and DELETE .../overrides/all. Their only other check is _student, which asks whether this session's account can see the pupil.

Before this branch the only way to open a row was /diary/login, where the upstream had just accepted a password for the login. So this gap is new with /session, and it is not on main.

The failure scenario (reproduced end to end against a fake upstream by two independent verifiers):

  1. Parent A signs in with /login as a@x.ru and corrects the room of child 4021 to «204».
  2. Parent B has their own Petersburg account, which also lists child 4021 (the other parent, for example). B sends POST /api/v1/diary/session {"provider":"petersburg","login":"a@x.ru","credential":{"token":<B's own JWT>}} and gets 200.
  3. B's GET /students/4021/schedule shows A's «204», and GET .../overrides lists A's row.
  4. B's PUT changes what A sees, and B's POST .../overrides/reset removes A's correction.

Severity: low. The attacker must already see the child through a diary account of their own and must know the other adult's login. What they reach is one family's own corrections to lessons they can already read. adopt's docstring, the schema comment and docs/api.md all say the login is not vouched for. None of them says that another adult who sees the same child can read and rewrite these corrections, and the code's own comments still say «every correction this account has made».

Why no test sees it. test_the_login_finds_the_corrections_a_password_sign_in_left has one account sign in both ways and pins the shared key as a feature. No test has two accounts on one child.

Why it is not fixed yet. Every correct fix is a product decision, so it went to the owner (26 September 2026):

  • (a) Share the corrections per child: diary, region, pupil. Both parents see and edit them, and the login plays no part.
  • (b) Key them on the account the diary vouches for: «Сетевой город»'s user id, or a claim inside Petersburg's JWT. No live answer has ever been seen, so this rests on fields nobody has confirmed. It also breaks owner_key's promise that a Petersburg key is the bare case-folded login.
  • (c) Keep the behaviour, and document the trade-off in docs/api.md and the comments.

The first answer chose (b), and the owner then stopped that implementation before it changed any file. This issue holds the finding until the decision is final. Neither 0015 nor 0016 depends on it: (a) and (c) need no schema change, and (b) would be an additive revision after 0016.

Activity

  1. added a commit that references this issue on Sep 26, 2026
  2. lumenpearson commented on Sep 26, 2026

    @lumenpearson
    OwnerAuthor

    Decided by the owner, 26 September 2026: (a), shared per child. This replaces the first answer, (b), which was withdrawn before it touched a file.

    What that means in the code:

    • Key. A correction is keyed by the child on its diary server, not by the login. The key is CHILD:petersburg, or CHILD:netschool:<the region's diary host>, together with the pupil id. The host is used rather than the region's name because pupil ids are numbered per server. If a region ever moves to another server, its corrections are lost rather than attached to a different child who happens to have the same number.
    • Who can reach them. Anyone whose own diary lists the child sees and edits them: the other parent, and the pupil's own account. The login a phone names at /session is shown on «вы вошли как» and nothing else. It decides no access, so naming someone else's login gains nothing. A reset removes a correction for everyone who sees the child, and the last writer wins.
    • The upper-case CHILD prefix. Every old key is a lowercased login, so no per-child key can equal one. Code reverted to main can neither read these rows nor write into them.
    • Two id spaces kept apart. Two children whose ids come from different id spaces can never share a key. This covers Petersburg's plain-id fallback, and a JSON true read as pupil 1 in «Сетевой город».
    • Revision 0017, data only. It folds old login-keyed rows into the per-child key; where two collide, the newest wins. It deletes the branch-only «Сетевой город» hash-keyed rows, which can no longer be read. On production it rewrites nothing, because diary_overrides held 0 rows when read on 26 September.
    • Texts. The privacy policy, the terms, the phone's correction note, docs/api.md and docs/guide.md change in the same batch so that they say this.

    Still unverified, and it will stay written down: that a «Сетевой город» pupil id is unique per server rather than per school, and that two parents' accounts see the same id for one child. No live answer has been seen.

    The fix lands on #140's branch and closes this issue.


    Generated by Claude Code

  3. moved this from Now to In progress in lessonson Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions