File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -77,19 +77,28 @@ const verifyBearerTokens = () => {
77
77
function verifySignature ( request : Request , res : Response , next : NextFunction ) {
78
78
try {
79
79
if ( ! process . env . SENTRY_CLIENT_SECRET ) throw new Error ( "SENTRY_CLIENT_SECRET가 env에 없습니다" ) ;
80
+
80
81
const hmac = crypto . createHmac ( "sha256" , process . env . SENTRY_CLIENT_SECRET ) ;
81
- hmac . update ( JSON . stringify ( request . body ) , "utf8" ) ;
82
+
83
+ // Raw body 사용 - Express에서 파싱되기 전의 원본 데이터 필요
84
+ // request.rawBody가 없다면 fallback으로 JSON.stringify 사용 (완벽하지 않음)
85
+ // @ts -expect-error - rawBody는 커스텀 미들웨어에서 추가되는 속성
86
+ const bodyToVerify = request . rawBody || JSON . stringify ( request . body ) ;
87
+ const sentrySignature = request . headers [ "sentry-hook-signature" ] ;
88
+
89
+ if ( ! bodyToVerify ) throw new Error ( "요청 본문이 없습니다." ) ;
90
+ if ( ! sentrySignature ) throw new Error ( "시그니처 헤더가 없습니다." ) ;
91
+
92
+ hmac . update ( bodyToVerify , "utf8" ) ;
82
93
const digest = hmac . digest ( "hex" ) ;
83
94
84
- if ( digest !== request . headers [ "sentry-hook-signature" ] ) {
85
- throw new Error ( "유효하지 않은 시그니처 헤더입니다." ) ;
86
- }
95
+ if ( digest !== sentrySignature ) throw new Error ( `유효하지 않은 시그니처 헤더입니다.` ) ;
96
+
87
97
next ( ) ;
88
- } catch ( error ) {
98
+ } catch ( error ) {
89
99
logger . error ( '시그니처 검증 중 오류가 발생하였습니다. : ' , error ) ;
90
100
next ( error ) ;
91
101
}
92
-
93
102
}
94
103
95
104
/**
You can’t perform that action at this time.
0 commit comments