From 0bf9f107b5fed22aae23cddcbddafc3c524e9722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 4 Jul 2024 03:16:58 +0200 Subject: [PATCH] Dissociate content-type and token check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/web.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/web.rs b/src/web.rs index 1714a78..0892754 100644 --- a/src/web.rs +++ b/src/web.rs @@ -42,23 +42,19 @@ async fn webhooks_inner(req: Request, token: Option<&String>) -> Resul _ => return Err(Error::MethodMismatch), } - if token.is_none() { - return Err(Error::InvalidToken); - } - let token: &str = token.unwrap(); - debug!("Headers: {:?}", req.headers()); let headers = req.headers(); if let Some(content_type) = headers.get(header::CONTENT_TYPE) - && let Some(header_token) = headers.get("X-Gitlab-Token") + && content_type != "application/json" { - if content_type != "application/json" { - return Err(Error::InvalidContentType); - } + return Err(Error::InvalidContentType); + } - if header_token != token { - return Err(Error::InvalidToken); + if let Some(token) = token { + match headers.get("X-Gitlab-Token") { + Some(val) if val == token => (), + _ => return Err(Error::InvalidToken), } }