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

オープン 初心者向け
#235 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
express, postgresql, typescript

調査の方向性

プロジェクトの入力解析パターンを確認するため、apps/http-server/src/controllers/authController.ts と registerInput.ts にある既存の parseRegisterInput の実装を読みます。説明にあるとおり、オブジェクト、配列、数値、body がない場合のログイン入力テストを追加します。無効な入力で500を発生させず、明確な400レスポンスを返すようになれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
21
フォーク
7
平均マージ
8時間 12分
マージ済み PR(30日)
36

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TheCodeHeist-Coder/Rexial のほかの issue

TheCodeHeist-Coder/Rexial の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。