Skip to content

Commit

Permalink
feat: 회원가입시 이메일과 비밀번호 보안 개선 (#540)
Browse files Browse the repository at this point in the history
* feat(user): 기본 회원가입시 @student.42seoul.kr 금지

* feat(auth): 인트라 회원가입시 비밀번호 uuid로 랜덤 설정

* refactor(auth.controller): change import crypto to node:crypto

Co-authored-by: scarf <greenscarf005@gmail.com>

* build(package.json): remove uuid

Co-authored-by: scarf <greenscarf005@gmail.com>

* fix(users.controller): invalid exception code

Co-authored-by: scarf <greenscarf005@gmail.com>

---------

Co-authored-by: scarf <greenscarf005@gmail.com>
  • Loading branch information
middlefitting and scarf005 authored Jul 12, 2023
1 parent 2e51856 commit 3e7c219
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as bcrypt from 'bcrypt';
import { NextFunction, Request, Response } from 'express';
import * as status from 'http-status';
import { randomUUID } from 'node:crypto';
import * as models from '../DTO/users.model';
import { oauth42ApiOption, oauthUrlOption } from '../config';
import { updateSlackIdByUserId } from '../slack/slack.service';
Expand Down Expand Up @@ -30,7 +31,7 @@ export const getToken = async (req: Request, res: Response, next: NextFunction):
// 회원가입
try {
const email = `${nickName}@student.42seoul.kr`;
await usersService.createUser(String(email), await bcrypt.hash(String(email), 10));
await usersService.createUser(String(email), await bcrypt.hash(randomUUID(), 10));
const newUser: { items: models.User[] } = await usersService.searchUserByEmail(email);
await authService.updateAuthenticationUser(newUser.items[0].id, id, nickName);
await updateSlackIdByUserId(newUser.items[0].id);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/users.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const router = Router();
* application/json:
* schema:
* type: object
* description: 200, 201, 205 에러 가능
* description: 200, 201, 205, 209 에러 가능
* properties:
* errorCode:
* type: number
Expand Down
4 changes: 4 additions & 0 deletions backend/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export const create = async (req: Request, res: Response, next: NextFunction) =>
if (!email || !password) {
return next(new ErrorResponse(errorCode.INVALID_INPUT, status.BAD_REQUEST));
}
const regex = /@student\.42seoul\.kr$/;
if (regex.test(email)) {
return next(new ErrorResponse(errorCode.STUDENT_42_SUBSCRIPTION_FORBIDDEN, status.BAD_REQUEST));
}
try {
pwSchema
.is().min(10)
Expand Down
1 change: 1 addition & 0 deletions backend/src/utils/error/errorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const INVALIDATE_PASSWORD = '205';
export const INVALID_ROLE = '206';
export const SLACK_OVERLAP = '207';
export const INTRA_AUTHENTICATE_SUCCESS = '208';
export const STUDENT_42_SUBSCRIPTION_FORBIDDEN = '209';

export const SLACKID_OVERLAP = '301';
export const NO_ISBN = '302';
Expand Down

0 comments on commit 3e7c219

Please sign in to comment.