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

Fix webhook signature #5622

Merged
merged 3 commits into from
Jan 24, 2023
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
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