-
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 3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import crypto from "crypto" | ||
| import dotenv from "dotenv"; | ||
| import { Request } from "express"; | ||
|
|
||
| dotenv.config(); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Sentry 웹훅 요청의 시그니처 헤더를 검증합니다. | ||
| * | ||
| * HMAC SHA256과 Sentry의 Client Secret를 사용하여 요청 본문을 해시화하고, | ||
| * | ||
| * Sentry에서 제공하는 시그니처 헤더와 비교하여 요청의 무결성을 확인합니다. | ||
| * | ||
| * @param {Request} request - Express 요청 객체 | ||
| * @returns {boolean} 헤더가 유효하면 true, 그렇지 않으면 false | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const isValid = verifySignature(req, process.env.SENTRY_WEBHOOK_SECRET); | ||
| * if (!isValid) { | ||
| * return res.status(401).json({ error: 'Invalid signature' }); | ||
| * } | ||
| * ``` | ||
| */ | ||
| export function verifySignature(request: Request) { | ||
six-standard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if(!process.env.SENTRY_CLIENT_SECRET) throw new Error("SENTRY_CLIENT_SECRET is not defined"); | ||
| const hmac = crypto.createHmac("sha256", process.env.SENTRY_CLIENT_SECRET); | ||
| hmac.update(JSON.stringify(request.body), "utf8"); | ||
| const digest = hmac.digest("hex"); | ||
|
|
||
| return digest === request.headers["sentry-hook-signature"]; | ||
| } | ||
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.
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.
💡 Verification agent
🧩 Analysis chain
환경 변수 이름 불일치 확인 필요
src/utils/verify.util.ts에서 사용하는 환경 변수명은SENTRY_CLIENT_SECRET인데, 여기서는SLACK_SENTRY_SIGNATURE로 되어 있습니다. 환경 변수명이 일치하지 않으면 시그니처 검증이 실패할 수 있습니다.다음 스크립트로 실제 사용되는 환경 변수명을 확인해보세요:
🏁 Script executed:
Length of output: 593
환경 변수명 통일 필요
src/utils/verify.util.ts와 관련 테스트에서는SENTRY_CLIENT_SECRET을 사용하지만,.env.sample에는SLACK_SENTRY_SIGNATURE만 정의되어 있어 시그니처 검증 시 값이 로드되지 않습니다. 아래와 같이.env.sample의 변수를 수정해주세요..env.sample📝 Committable suggestion
🤖 Prompt for AI Agents