Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Fix webhook signature (cvat-ai#5622)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Sizov authored and mikhail-treskin committed Jul 1, 2023
1 parent da0fa5b commit 08fb489
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/opencv/cvat/pull/5557>)
- Windows Installation Instructions adjusted to work around <https://github.com/nuclio/nuclio/issues/1821>
- The contour detection function for semantic segmentation (<https://github.com/opencv/cvat/pull/4665>)
- Delete newline character when generating a webhook signature (<https://github.com/opencv/cvat/pull/5622>)

### Deprecated
- TDB
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/webhooks/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def send_webhook(webhook, payload, delivery):
"sha256="
+ hmac.new(
webhook.secret.encode("utf-8"),
(json.dumps(payload) + "\n").encode("utf-8"),
json.dumps(payload).encode("utf-8"),
digestmod=hashlib.sha256,
).hexdigest()
)
Expand Down
24 changes: 24 additions & 0 deletions site/content/en/docs/administration/advanced/webhooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,30 @@ Example of header value for empty request body and `secret = mykey`:
X-Signature-256: e1b24265bf2e0b20c81837993b4f1415f7b68c503114d100a40601eca6a2745f
```

Here is an example of how you can verify a webhook signature in your webhook receiver service:

```python
# webhook_receiver.py

import hmac
from hashlib import sha256
from flask import Flask, request

app = Flask(__name__)

@app.route("/webhook", methods=["POST"])
def webhook():
signature = (
"sha256="
+ hmac.new("mykey".encode("utf-8"), request.data, digestmod=sha256).hexdigest()
)

if hmac.compare_digest(request.headers["X-Signature-256"], signature):
return app.response_class(status=200)

raise app.response_class(status=500, response="Signatures didn't match!")
```

## Ping Webhook

To check that webhook configured well and CVAT can connect with target URL you can use `ping` webhook.
Expand Down

0 comments on commit 08fb489

Please sign in to comment.