- Notifications
You must be signed in to change notification settings - Fork 0
[TASK-220 / 25.07.04] Refactor: 시그니처 인증 과정 추가 #39
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits Select commit Hold shift + click to select a range
60c416c refactor: 시그니처 인증 과정 추가
six-standard 0116921 feature: 테스트 코드 추가
six-standard f3da727 refactor: 중복 테스트 제거
six-standard 2fe688c refactor: CI env 변경 반영
six-standard f6619d9 refactor: 미들웨어로 수정
six-standard 9b98d89 refactor: body 값 및 검증 코드 개선
six-standard 4ee3f53 refactor: 제거된 파일 import 제거
six-standard 3ce78d7 refactor: 예외 처리 수정
six-standard cc217da refactor: 테스트 오류 수정
six-standard 3ba6149 refactor: 린팅 이슈 해결 및 통일성 강조
six-standard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -4,6 +4,7 @@ import logger from '@/configs/logger.config'; | |
| import pool from '@/configs/db.config'; | ||
| import { DBError, InvalidTokenError } from '@/exception'; | ||
| import { VelogJWTPayload, User } from '@/types'; | ||
| import crypto from "crypto"; | ||
| | ||
| /** | ||
| * 요청에서 토큰을 추출하는 함수 | ||
| | @@ -66,10 +67,36 @@ const verifyBearerTokens = () => { | |
| }; | ||
| }; | ||
| | ||
| /** | ||
| * Sentry 웹훅 요청의 시그니처 헤더를 검증합니다. | ||
| * HMAC SHA256과 Sentry의 Client Secret를 사용하여 요청 본문을 해시화하고, | ||
| * Sentry에서 제공하는 시그니처 헤더와 비교하여 요청의 무결성을 확인합니다. | ||
| * @param {Request} request - Express 요청 객체 | ||
| * @returns {boolean} 헤더가 유효하면 true, 그렇지 않으면 false | ||
| */ | ||
| function verifySignature(request: Request, res: Response, next: NextFunction) { | ||
| try { | ||
| if(!process.env.SENTRY_CLIENT_SECRET) throw new Error("SENTRY_CLIENT_SECRET가 env에 없습니다"); | ||
| const hmac = crypto.createHmac("sha256", process.env.SENTRY_CLIENT_SECRET); | ||
| hmac.update(JSON.stringify(request.body), "utf8"); | ||
six-standard marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| const digest = hmac.digest("hex"); | ||
| | ||
| if(digest !== request.headers["sentry-hook-signature"]) { | ||
| throw new Error("유효하지 않은 시그니처 헤더입니다."); | ||
| ||
| } | ||
coderabbitai[bot] marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| next(); | ||
| } catch (error) { | ||
| logger.error('시그니처 검증 중 오류가 발생하였습니다. : ', error); | ||
| next(error); | ||
| } | ||
| | ||
| } | ||
| | ||
| /** | ||
| * 사용자 인증을 위한 미들웨어 모음 | ||
| * @property {Function} verify | ||
| */ | ||
| export const authMiddleware = { | ||
| verify: verifyBearerTokens(), | ||
| verifySignature, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.