Skip to content

Diary comments and docs describe a per-origin CA bundle, a keep-alive breaker, a region order and a password route the code does not have, and deploy.md undercounts DaData requests #150

Closed

Description

@lumenpearson

What is broken.

Several comments and documents describe diary and directory behaviour the code does not have. Nothing fails at runtime today. The problem is that each one tells the next reader, or the family on the page, something false:

  • A CA bundle nothing reads. Region.ca_bundle is documented as "a path to a CA file to trust for that origin only". Nothing reads the field, and no region sets it. build_client takes no verify or CA argument, yet its own comment tells the reader to put a CA bundle for the Russian Trusted Root "in regions.py". The netschool provider also uses one process-wide client for every region, so there is no per-origin client a bundle could go on.
  • A keep-alive breaker that does not exist. The AddressRefused docstring says "the keep-alive trips a per-origin breaker on it rather than pinging that origin's other sessions into the same wall". The keep-alive has no breaker and no idea of an origin. _Claim does not carry the region, and AddressRefused falls into a bare except Exception that marks the row "skip". The DiarySession.region comment, the 0015 revision and CLAUDE.md all say the column exists so sessions can be "grouped per origin for the keep-alive", and nothing does that.
  • A region order that does not match its source. _REGIONS is headed "Ordered as docs/diaries.md lists them". It is in alphabetical order by title, and docs/diaries.md lists republics, then krais, then oblasts.
  • A password route that skips our server. The diary_web module docstring and the DiaryLinkCode docstring both say the password goes "from the browser straight to the upstream". In fact the form posts to our own /diary/signin/{code} (CSP form-action 'self'), the handler reads the password and passes it to diary_service.sign_in, and for «Сетевой город» it is hashed in our process. POST /api/v1/diary/login takes it in the JSON body too. Three user-facing texts make the same claim:
    • the form: «Пароль уходит прямо в дневник и нигде не сохраняется»
    • the bot's offer: «оттуда пароль уходит прямо в дневник»
    • the bot's link card: «уходит прямо в дневник — ни бот, ни эта база его не видят»
  • "No passwords" on the phone-to-server wire. docs/build.md, "Why HTTP and not HTTPS", says what travels over the phone-to-server wire is "only a class code and a timetable: no passwords, no personal data". But the app's diary sign-in posts the diary password to /api/v1/diary/login over that same client and URL. network_security_config.xml already says the old wording stopped being true. build.md was never updated.
  • One DaData request per search. docs/deploy.md says "the bot makes one request per search". suggest_schools sends a second request, without the ОКВЭД filter, whenever the first one comes back empty.

The failure scenario.

  1. A region turns out to present the Russian Trusted Root. A maintainer follows http.py's comment and sets ca_bundle= on that Region. Nothing reads it, and the shared client still verifies against the default roots. Sign-in to that region goes on failing on TLS, and the code change looks like it should have fixed it.
  2. A regional server starts dropping the deployment's address. AddressRefused is raised on each ping, caught as a generic exception and marked "skip". Four minutes later (KEEPALIVE_MIN_INTERVAL), every session on that origin is pinged again, up to 200 per tick, which is exactly what the docstring says the breaker prevents. Anyone reading errors.py concludes the case is handled.
  3. Somebody reorders _REGIONS to "match docs/diaries.md" as the comment promises. The bot's region picker (listed()), which is alphabetical today, becomes Республика Бурятия … Алтайский край … Амурская область.
  4. A reviewer checking where the diary password goes reads the diary_web or DiaryLinkCode docstring. They conclude our server never handles it, so logging, request-body limits and error paths in sign_in_submit and /diary/login need no care for secrets. That conclusion is wrong. The family reads «уходит прямо в дневник» on the form, which is not true either.
  5. A school owner reads docs/build.md, runs the server on plain http:// on the school Wi-Fi, and believes no password crosses it. A parent then signs in to the diary from the app, and the login and password travel in clear text.
  6. An owner sizing the DaData free plan with docs/deploy.md counts one request per search. Every search that finds nothing under 85.12–85.14 costs two.

Where.

  • server/app/providers/netschool/regions.py:27-29 (docstring), :45 (ca_bundle: str | None = None, read nowhere)
  • server/app/providers/diary/http.py:76-82 (build_client takes no verify or CA), :95-97 (comment pointing to a CA bundle in regions.py)
  • server/app/providers/netschool/client.py:69-87 (one shared client for every region)
  • server/app/providers/diary/errors.py:77-79 (the per-origin breaker)
  • server/app/services/diary_keepalive.py:60-66 (_Claim has no region), :153-155 (except Exception → "skip")
  • server/app/models.py:812-814, server/migrations/versions/0015_diary_provider_columns.py:18, CLAUDE.md:366 ("grouped per origin for the keep-alive")
  • server/app/providers/netschool/regions.py:48 (the order comment); docs/diaries.md:152, :173, :182 (the actual order)
  • server/app/api/diary_web.py:10-11 (docstring), :191 (form posts to our own path), :298, :323-326 (password passed on), :200 (form text)
  • server/app/models.py:840-841 (DiaryLinkCode docstring)
  • server/app/bot/diary_render.py:172-173, server/app/bot/handlers/diary.py:207-208 (bot texts)
  • server/app/api/diary.py:248, :284 (/diary/login takes payload.password)
  • docs/build.md:652-653; contradicted by android/core/data/src/main/kotlin/com/lumenpearson/lessons/core/data/network/DiaryApi.kt:50 and android/app/src/main/res/xml/network_security_config.xml:13-21
  • docs/deploy.md:235-236; contradicted by server/app/providers/dadata/client.py:154-167

Also user-facing, found while fixing the rest. The same false promise is shown to people, in Russian: the bot's sign-in page (server/app/api/diary_web.py, around :206-208) and the bot's signed-out card (server/app/bot/diary_render.py, around :172-173) both say the password goes straight to the diary. The page posts it to our server, which relays it once.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions