File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed
src/runtime/server/lib/validators Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change 1- import { subtle } from 'node:crypto'
2- import { Buffer } from 'node:buffer'
31import { type H3Event , getRequestHeaders , readRawBody } from 'h3'
4- import { encoder , HMAC_SHA256 , ensureConfiguration } from '../helpers'
2+ import { ensureConfiguration , sha256 } from '../helpers'
53
64const NUXTHUB_SIGNATURE = 'x-nuxthub-signature'
75
@@ -22,8 +20,7 @@ export const isValidNuxtHubWebhook = async (event: H3Event): Promise<boolean> =>
2220 if ( ! body || ! webhookSignature ) return false
2321
2422 const payload = body + config . secretKey
25- const signatureBuffer = await subtle . digest ( HMAC_SHA256 . hash , encoder . encode ( payload ) )
26- const signature = Buffer . from ( signatureBuffer ) . toString ( 'hex' )
23+ const signature = await sha256 ( payload )
2724
2825 return signature === webhookSignature
2926}
Original file line number Diff line number Diff line change 1- import { subtle } from 'node:crypto'
2- import { Buffer } from 'node:buffer'
31import { $fetch } from '@nuxt/test-utils/e2e'
4- import { encoder , HMAC_SHA256 } from '../../src/runtime/server/lib/helpers'
2+ import { sha256 } from '../../src/runtime/server/lib/helpers'
53import nuxtConfig from '../fixtures/basic/nuxt.config'
64
7- const body = 'testBody'
5+ const body = { message : 'NuxtHub Sample Webhook, this is a test message from NuxtHub Admin' }
86const secretKey = nuxtConfig . runtimeConfig ?. webhook ?. nuxthub ?. secretKey
97
108export const simulateNuxthubEvent = async ( ) => {
11- const payload = body + secretKey
12- const signatureBuffer = await subtle . digest ( HMAC_SHA256 . hash , encoder . encode ( payload ) )
13- const validSignature = Buffer . from ( signatureBuffer ) . toString ( 'hex' )
9+ const payload = JSON . stringify ( body ) + secretKey
10+ const validSignature = await sha256 ( payload )
1411
1512 const headers = { 'x-nuxthub-signature' : validSignature }
1613
You can’t perform that action at this time.
0 commit comments