-
Notifications
You must be signed in to change notification settings - Fork 22
[이지수A] Sprint12 #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: express-이지수A
Are you sure you want to change the base?
[이지수A] Sprint12 #63
The head ref may contain hidden characters: "express-\uC774\uC9C0\uC218A"
Conversation
| export default { | ||
| accessTokenStrategy, | ||
| refreshTokenStrategy, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.env.JWT_SECRET을 HMAC 기반 서명키로 잘 분리하여 관리하고 있고,
디코딩된 payload의 무결성을 검증한 후 안전하게 사용자 조회에 사용하는 흐름이 보안적으로 잘 구성되어 있습니다.
이는 공무원 정보보호론 과목 기준으로도 MAC 기반 인증 구조의 실질 예시가 되며, 시험에서 다루는 무결성 보장/인증 구조가 그대로 코드로 구현된 셈입니다.
refreshToken은 쿠키 기반 전달 방식으로 설계되어, CSRF나 XSS 대응이 잘 고려된 점도 인상적입니다.
loquemedalagana
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
유효성 검증이 많아질 경우엔 zod나 joi 같은 validation 라이브러리를 사용하는 것도 고려해보면 좋습니다.
이 경우 코드 분리가 가능해지고, 클린코드와 유지보수성이 더 올라갑니다.
예: zod 활용
import { z } from "zod";
const productSchema = z.object({
name: z.string().min(1),
price: z.number().nonnegative(),
description: z.string().optional(),
});
const parsed = productSchema.safeParse(req.body);
if (!parsed.success) {
throw new CustomError(422, "유효하지 않은 상품 입력값입니다.");
}| message: responseMessage, | ||
| timestamp: new Date().toISOString(), | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
복습용 상태코드 테이블 정리했어요!
| Status | 이름 | 의미 | 예시 |
|---|---|---|---|
| 400 | Bad Request | 문법 오류, 누락된 파라미터 | JSON 파싱 오류 등 |
| 401 | Unauthorized | 인증되지 않은 사용자 | 로그인 실패, 토큰 없음 |
| 403 | Forbidden | 인증은 되었지만 권한 없음 | 관리자 전용 기능 접근 등 |
| 404 | Not Found | 요청 리소스 없음 | 잘못된 URL, ID 없음 |
| 405 | Method Not Allowed | 메서드 불허 | GET만 가능한 엔드포인트에 POST 요청 |
| 422 | Unprocessable Entity | 문법은 맞지만 처리 불가 | 빈 body, 유효성 검사 실패 등 |
| 500 | Internal Server Error | 서버 내부 오류 | DB 연결 실패 등 |
| const ownerId = req.user.id; | ||
| if (!req.body.name || req.body.price === undefined) { | ||
| throw new CustomError(422, "상품 이름과 가격은 필수입니다."); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
422 상태 코드를 적극적으로 도입한 것은 매우 바람직하며, 공무원 출신의 정책적 감각과 표준 해석 능력이 잘 반영된 예입니다.
앞으로도 400 vs 422, 403 vs 401 등 상황에 맞는 세분화된 상태 코드 사용은 REST API 품질을 결정짓는 핵심 요소입니다. 잘하셨습니다.
|
지금 conflict났어요ㅠㅠ |
|
|
||
| const accessTokenStrategy = new JwtStrategy(accessTokenOptions, jwtVerify); | ||
| const refreshTokenStrategy = new JwtStrategy(refreshTokenOptions, jwtVerify); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다은님이 짜신 코드 일부인데,
const verifyRefreshToken = expressjwt({
secret: JWT_SECRET as string,
algorithms: ["HS256"],
credentialsRequired: true, // 개발 중 새로고침 시 쿠키 누락 대응
// 쿠키에 리프레시 토큰을 담기 때문
getToken: (req: Request): string | undefined => {
const token = req.cookies?.refreshToken;
return token || undefined;
},
});위의 verifyRefreshToken 코드에서 HS256은 쿠키에 담긴 refreshToken의 무결성과 진위 여부를 검증하는 데 사용됩니다. JWT 서명 검증은 암호학적으로 다음과 같은 구조로 작동합니다:
signature = HMAC-SHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), secret)
- 예전에 지수님께서 준비하실 때는 HMAC 알고리즘이 대칭키 기반이며, 해시 충돌 회피와 메시지 무결성 검증에 사용된다는 점을 외웠어야 했는데,
- 실무에서는 단지
.verify()메서드만 호출하면 됩니다!
프론트주소 https://6-sprint-mission-fe-pxcf.vercel.app/
백엔드주소 https://api.mustvisit.shop/
기본 요구사항
공통
백엔드
프론트엔드
심화 요구사항
테스트 구현
상품 이미지 업로드
AWS Route 53을 활용한 도메인 관리
도메인을 통한 애플리케이션 접속 및 운영을 테스트합니다.
SSL 인증서를 통한 HTTPS 연결 구현
주요 변경사항
스크린샷
멘토에게