-
Notifications
You must be signed in to change notification settings - Fork 89
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
docs: add info for webhook signature validation #3054
base: main
Are you sure you want to change the base?
Conversation
Adding content for optional but recommended webhook signature validation
✅ Deploy Preview for brilliant-pasca-3e80ec ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
||
### Compare the signatures | ||
|
||
Finally, compare the signature in the header to the expected signature you generated. For security, use a constant-time comparison function to prevent timing attacks. Also, check the timestamp to ensure that it is within the allowed TTL (configured in the `ADMIN_API_SIGNATURE_TTL_SECONDS` environment variable) to ensure freshness. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, compare the signature in the header to the expected signature you generated. For security, use a constant-time comparison function to prevent timing attacks. Also, check the timestamp to ensure that it is within the allowed TTL (configured in the `ADMIN_API_SIGNATURE_TTL_SECONDS` environment variable) to ensure freshness. | |
Finally, compare the signature in the header to the expected signature you generated. For security, use a constant-time comparison function to prevent timing attacks. |
Does not apply to webhooks for now
|
||
To protect your endpoint from unauthorized or spoofed requests, Rafiki supports an optional, but highly recommended, webhook signature verification process. By enabling signature verification, you can ensure that webhook requests are genuinely from Rafiki. | ||
|
||
Each webhook request includes a `Rafiki-Signature` header with a timestamp and signature digest. If you instance is configured with a `SIGNATURE_SECRET` environment variable, you can verify the authenticity of each webhook request using the steps below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version is set using SIGNATURE_VERSION
``` | ||
// Really cool code example in some commonly used language (JavaScript, Python?) | ||
|
||
// Extract timestamp and signatures from header | ||
|
||
// Prepare the signed payload string | ||
|
||
// Generate the expected signature | ||
|
||
// Compare the signatures and check the timestamp | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``` | |
// Really cool code example in some commonly used language (JavaScript, Python?) | |
// Extract timestamp and signatures from header | |
// Prepare the signed payload string | |
// Generate the expected signature | |
// Compare the signatures and check the timestamp | |
``` | |
```js | |
function verifyWebhookSignature(request: Request): boolean { | |
const signatureParts = request.headers['Rafiki-Signature'].split(', ') | |
const timestamp = signatureParts[0].split('=')[1] | |
const signatureVersionAndDigest = signatureParts[1].split('=') | |
const signatureVersion = signatureVersionAndDigest[0].replace('v', '') | |
const signatureDigest = signatureVersionAndDigest[1] | |
if (signatureVersion !== config['SIGNATURE_VERSION']) { | |
return false | |
} | |
const payload = `${timestamp}.${canonicalize(request.body)}` | |
const hmac = createHmac('sha256', config['SIGNATURE_SECRET']) | |
hmac.update(payload) | |
const digest = hmac.digest('hex') | |
return digest === signatureDigest | |
} |
Adding content for optional but recommended webhook signature validation
Fixes #3022