fix: validate types for login email and password (500 on non-string or missing body)

Offen Anfängerfreundlich
#235 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
express, postgresql, typescript

Rechercherichtung

Lies apps/http-server/src/controllers/authController.ts und die vorhandene Implementierung von parseRegisterInput in registerInput.ts, um das Eingabeparsing-Muster des Projekts zu verstehen. Füge Tests für Login-Eingaben für die Fälle Objekt, Array, Zahl und fehlender Body wie beschrieben hinzu. Fertig ist die Arbeit, wenn ungültige Eingaben eine klare 400-Antwort zurückgeben, statt einen 500-Fehler zu verursachen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary

userLoginController (apps/http-server/src/controllers/authController.ts) is the one auth input that is still only checked for being truthy. Register has parseRegisterInput, and join and create quiz got the same treatment in #231, but login still does const { email, password } = req.body and if (!email || !password).

What happens

From reading the code, POST /api/v1/auth/login should give a generic 500 in these cases:

  • No JSON body: the destructure throws, same as the no body case that #234 fixed for join.
  • {"email":{},"password":"x"}: gets past the check, then Prisma throws a validation error in findUnique.
  • {"email":"[email protected]","password":123}: bcrypt.compare throws on a non string.

I didn't run these against a database, the join versions behaved this way when I tested #234.

Expected behaviour

400 with a clear message for wrong types.

Proposed fix

A small parseLoginInput next to registerInput.ts, returned through the existing errorResponse(res, 400, ...), with tests for the object, array, number and no body cases.

Happy to send a PR for this, and #234 is merged so I don't have anything else open here. Labels and level are your call.

Vorherrschende Sprache
TypeScript
Sterne
21
Forks
7
Ø Merge
8 Std. 12 Min.
Gemergte PRs (30 T.)
36

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TheCodeHeist-Coder/Rexial

Alle Issues in TheCodeHeist-Coder/Rexial

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.