From edd0e0074adf80e3e7ed30dedc2ca4e3c69b82b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 24 Jul 2024 19:35:27 +0200 Subject: [PATCH] Don't calculate sig for payloads that don't need it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/web.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/web.rs b/src/web.rs index ec9b0d6..dd5758b 100644 --- a/src/web.rs +++ b/src/web.rs @@ -56,10 +56,22 @@ async fn hooks_inner(req: Request, secret: &str) -> Result = vec![]; let whole_body = req.collect().await?.aggregate(); whole_body.reader().read_to_end(&mut payload)?; + + if let Some(val) = headers.get("X-Gitlab-Token") { + debug!("Found Gitlab payload"); + if secret != val { + return Err(Error::InvalidSecret); + } + + let hook: GitlabHook = serde_json::from_slice(&payload[..])?; + return Ok(Hook::Gitlab(hook)); + } + + // Generate hmac signature let mut mac = HmacSha256::new_from_slice(secret.as_bytes())?; mac.update(&payload); let result = mac.finalize().into_bytes(); @@ -76,14 +88,6 @@ async fn hooks_inner(req: Request, secret: &str) -> Result