Skip to content

Malformed «Сетевой город» sign-in answers escape the diary errors and answer 500 #148

Closed

Description

@lumenpearson

What is broken.

The «Сетевой город» client does not check the shape of the sign-in answers it reads. _decode guarantees only that a body parses as JSON, not that it is an object. After that:

  • the logindata, getdata and login steps each call .get on the body;
  • _hash_password encodes the upstream's salt to ASCII outside the only try it has;
  • the login's timeOut goes through a bare int().

Each of these raises a plain Python exception (AttributeError, UnicodeEncodeError, ValueError/TypeError), not a member of the DiaryError family. Nothing between the client and the edge catches them. api/diary._guard maps only that family, and errors.py says in so many words that «anything outside it is a 500». POST /api/v1/diary/login catches only DiaryDisabled and HTTPException. On the sign-in page, a catch-all turns them into a generic 500 page and keeps the ticket spent.

This breaks the client's own contract. A failure before the password POST was supposed to be UpstreamUnavailable/AddressRefused/SignInUnsupported, with «anything unreadable before the password POST is UpstreamUnavailable, so the ticket survives». An unreadable answer was supposed to be UnexpectedResponse.

The failure scenario.

Reproduced at HEAD with a mock upstream. The request each time is POST /api/v1/diary/login with {"login": "parent", "password": "hunter2", "provider": "netschool", "region": "zabaikalsky", "school_id": 42}.

  1. GET /webapi/logindata answers 200 with []. The client raises AttributeError: 'list' object has no attribute 'get' at data.get("schoolLogin", True), and the API answers 500 Internal Server Error. Nothing but a request for the sign-in options had been sent.
  2. POST /webapi/auth/getdata answers 200 with []. payload.get("salt", "") raises AttributeError, and the API answers 500. This is also before any password was sent.
  3. getdata answers {"lt": "1", "ver": "2", "salt": "соль"}. (salt + inner).encode("ascii") in _hash_password raises UnicodeEncodeError, because the try there wraps only the password's windows-1251 encode. The API answers 500. This is before the password POST.
  4. POST /webapi/login answers 200 with []. body.get("entryPoint") raises AttributeError, and the API answers 500.
  5. login answers {"at": "a", "timeOut": "abc"}. int(body["timeOut"]) raises ValueError: invalid literal for int(), and the API answers 500. "900.5" does the same, and a list there is a TypeError with the same result. This happens after the upstream accepted the password and issued at. So a right password answers 500 and the upstream session is left open, never logged out.
  6. On the JSON API, none of these reaches diary_login_limiter.record_failure, because they are not HTTPExceptions. That includes case 4, where the password had been sent.
  7. On the sign-in page (POST /diary/signin/{code}), the same answers go to the catch-all: a 500 page saying «Что-то пошло не так. Попробуйте ещё раз.», with the ticket kept spent. That includes cases 1–3, where no password had been sent — exactly where the client promises the ticket survives.

Where.

server/app/providers/netschool/client.py:

  • 204-214: _decode accepts any JSON value.
  • 259-261: logindata data.get("schoolLogin", True).
  • 289-290: getdata payload.get("salt", "").
  • 105-110: _hash_password; line 110's .encode("ascii") is outside the try.
  • 327-331: login body.get("entryPoint").
  • 341-342: int(body["timeOut"]).
  • 25-29 and 270-272: the contract these break.

Everything else:

  • server/app/providers/diary/errors.py:8: «anything outside it is a 500».
  • server/app/api/diary.py:145-187: _guard knows only the DiaryError family.
  • server/app/api/diary.py:279-323: the login route catches only DiaryDisabled and HTTPException.
  • server/app/api/diary_web.py:342-348: the catch-all answers 500 and keeps the ticket spent.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions