Skip to content

Commit

Permalink
Removes console warnings in webhook verifiers (redwoodjs#2563)
Browse files Browse the repository at this point in the history
  • Loading branch information
dthyresson authored May 23, 2021
1 parent daa7502 commit b9b5a7a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
3 changes: 0 additions & 3 deletions packages/api/src/auth/verifiers/secretKeyVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export const secretKeyVerifier = (
): SecretKeyVerifier => {
return {
sign: ({ secret }) => {
console.warn(
`With the SecretKeyVerifier verifier, your body isn't signed with a secret`
)
return secret
},
verify: ({ signature, secret = DEFAULT_WEBHOOK_SECRET }) => {
Expand Down
18 changes: 3 additions & 15 deletions packages/api/src/auth/verifiers/sha1Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ function toNormalizedJsonString(payload: Record<string, unknown>) {
const createSignature = ({
payload,
secret = DEFAULT_WEBHOOK_SECRET,
options,
}: {
payload: string | Record<string, unknown>
secret: string
options?: VerifyOptions
}): string => {
if (options) {
console.warn('VerifyOptions are invalid for the Sha1Verifier')
}

const algorithm = 'sha1'
const hmac = createHmac(algorithm, secret)

Expand All @@ -58,18 +52,12 @@ export const verifySignature = ({
payload,
secret = DEFAULT_WEBHOOK_SECRET,
signature,
options,
}: {
payload: string | Record<string, unknown>
secret: string
signature: string
options?: VerifyOptions
}): boolean => {
try {
if (options) {
console.warn('VerifyOptions are invalid for the Sha1Verifier')
}

const algorithm = signature.split('=')[0]
const webhookSignature = Buffer.from(signature || '', 'utf8')
const hmac = createHmac(algorithm, secret)
Expand Down Expand Up @@ -109,13 +97,13 @@ export const verifySignature = ({
* @see https://vercel.com/docs/api#integrations/webhooks/securing-webhooks
*
*/
const sha1Verifier = (options?: VerifyOptions | undefined): Sha1Verifier => {
const sha1Verifier = (_options?: VerifyOptions | undefined): Sha1Verifier => {
return {
sign: ({ payload, secret }) => {
return createSignature({ payload, secret, options })
return createSignature({ payload, secret })
},
verify: ({ payload, secret, signature }) => {
return verifySignature({ payload, secret, signature, options })
return verifySignature({ payload, secret, signature })
},
type: 'sha1Verifier',
}
Expand Down
18 changes: 3 additions & 15 deletions packages/api/src/auth/verifiers/sha256Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ function toNormalizedJsonString(payload: Record<string, unknown>) {
const createSignature = ({
payload,
secret = DEFAULT_WEBHOOK_SECRET,
options,
}: {
payload: string | Record<string, unknown>
secret: string
options?: VerifyOptions
}): string => {
if (options) {
console.warn('VerifyOptions are invalid for the Sha256Verifier')
}

const algorithm = 'sha256'
const hmac = createHmac(algorithm, secret)

Expand All @@ -58,18 +52,12 @@ export const verifySignature = ({
payload,
secret = DEFAULT_WEBHOOK_SECRET,
signature,
options,
}: {
payload: string | Record<string, unknown>
secret: string
signature: string
options?: VerifyOptions
}): boolean => {
try {
if (options) {
console.warn('VerifyOptions are invalid for the Sha256Verifier')
}

const algorithm = signature.split('=')[0]
const webhookSignature = Buffer.from(signature || '', 'utf8')
const hmac = createHmac(algorithm, secret)
Expand Down Expand Up @@ -110,14 +98,14 @@ export const verifySignature = ({
*
*/
const sha256Verifier = (
options?: VerifyOptions | undefined
_options?: VerifyOptions | undefined
): Sha256Verifier => {
return {
sign: ({ payload, secret }) => {
return createSignature({ payload, secret, options })
return createSignature({ payload, secret })
},
verify: ({ payload, secret, signature }) => {
return verifySignature({ payload, secret, signature, options })
return verifySignature({ payload, secret, signature })
},
type: 'sha256Verifier',
}
Expand Down

0 comments on commit b9b5a7a

Please sign in to comment.