Repository navigation
Description
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
.geton the body; _hash_passwordencodes the upstream's salt to ASCII outside the onlytryit has;- the login's
timeOutgoes through a bareint().
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}.
GET /webapi/logindataanswers200with[]. The client raisesAttributeError: 'list' object has no attribute 'get'atdata.get("schoolLogin", True), and the API answers500 Internal Server Error. Nothing but a request for the sign-in options had been sent.POST /webapi/auth/getdataanswers200with[].payload.get("salt", "")raisesAttributeError, and the API answers 500. This is also before any password was sent.- getdata answers
{"lt": "1", "ver": "2", "salt": "соль"}.(salt + inner).encode("ascii")in_hash_passwordraisesUnicodeEncodeError, because thetrythere wraps only the password's windows-1251 encode. The API answers 500. This is before the password POST. POST /webapi/loginanswers200with[].body.get("entryPoint")raisesAttributeError, and the API answers 500.- login answers
{"at": "a", "timeOut": "abc"}.int(body["timeOut"])raisesValueError: invalid literal for int(), and the API answers 500."900.5"does the same, and a list there is aTypeErrorwith the same result. This happens after the upstream accepted the password and issuedat. So a right password answers 500 and the upstream session is left open, never logged out. - On the JSON API, none of these reaches
diary_login_limiter.record_failure, because they are notHTTPExceptions. That includes case 4, where the password had been sent. - 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:
_decodeaccepts 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 thetry. - 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:_guardknows only theDiaryErrorfamily.server/app/api/diary.py:279-323: the login route catches onlyDiaryDisabledandHTTPException.server/app/api/diary_web.py:342-348: the catch-all answers 500 and keeps the ticket spent.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
Let a phone register a diary session it opened itself, and fix what t…