File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,14 @@ testing = [
2222[dependencies ]
2323anyhow = { workspace = true }
2424async-trait = { workspace = true }
25+ aws-lc-rs = { workspace = true }
2526bytes = { workspace = true }
2627common = { workspace = true }
2728convex_macro = { workspace = true }
2829database = { workspace = true }
2930errors = { workspace = true }
3031futures = { workspace = true }
32+ hex = { workspace = true }
3133http = { workspace = true }
3234keybroker = { workspace = true }
3335maplit = { workspace = true }
Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ use std::{
33 sync:: Arc ,
44} ;
55
6+ use aws_lc_rs:: hmac:: {
7+ self ,
8+ HMAC_SHA256 ,
9+ } ;
610use bytes:: Bytes ;
711use common:: {
812 backoff:: Backoff ,
@@ -23,7 +27,11 @@ use errors::{
2327 ErrorMetadata ,
2428 ErrorMetadataAnyhowExt ,
2529} ;
26- use http:: header:: CONTENT_TYPE ;
30+ use hex:: ToHex ;
31+ use http:: {
32+ header:: CONTENT_TYPE ,
33+ HeaderValue ,
34+ } ;
2735use model:: log_sinks:: types:: webhook:: {
2836 WebhookConfig ,
2937 WebhookFormat ,
@@ -166,9 +174,17 @@ impl<RT: Runtime> WebhookSink<RT> {
166174 } ;
167175 let payload = Bytes :: from ( payload) ;
168176
169- // Make request in a loop that retries on transient errors
170- let headers = HeaderMap :: from_iter ( [ ( CONTENT_TYPE , APPLICATION_JSON_CONTENT_TYPE ) ] ) ;
177+ // Create HMAC-SHA256 signature
178+ let s_key = hmac:: Key :: new ( HMAC_SHA256 , self . config . hmac_secret . as_ref ( ) ) ;
179+ let signature: String = hmac:: sign ( & s_key, & payload) . encode_hex ( ) ;
171180
181+ let mut headers = HeaderMap :: from_iter ( [ ( CONTENT_TYPE , APPLICATION_JSON_CONTENT_TYPE ) ] ) ;
182+ headers. append (
183+ "x-webhook-signature" ,
184+ HeaderValue :: from_str ( format ! ( "sha256={signature}" ) . as_str ( ) ) ?,
185+ ) ;
186+
187+ // Make request in a loop that retries on transient errors
172188 for _ in 0 ..consts:: WEBHOOK_SINK_MAX_REQUEST_ATTEMPTS {
173189 let response = self
174190 . fetch_client
You can’t perform that action at this time.
0 commit comments