Skip to content
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

Removes console warnings in webhook verifiers #2563

Merged
merged 2 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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