Skip to content

Commit

Permalink
fix: use timing-safe string comparison (#7)
Browse files Browse the repository at this point in the history
Resolves #6
  • Loading branch information
coolaj86 authored Oct 1, 2023
1 parent 78e3768 commit af84da9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/XHubSignature.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import crypto from 'crypto'

let encoder = new TextEncoder()

export default class XHubSignature {
#algorithm = null
#secret = null
Expand All @@ -24,6 +26,12 @@ export default class XHubSignature {
}

verify (expectedSignature, requestBody) {
return expectedSignature === this.sign(requestBody)
const expected = encoder.encode(expectedSignature)
const actualSignature = this.sign(requestBody)
const actual = encoder.encode(signature)
if (expected.length !== actual.length) {
return false
}
return crypto.timingSafeEqual(expected, actual)
}
}

0 comments on commit af84da9

Please sign in to comment.