From fd578aa61e361a0b74a7751e7398a36dc22508da Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Wed, 18 Dec 2024 07:32:00 +0300 Subject: [PATCH] fix: add condition for token --- .../Controllers/Configuration/SetupController.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Endpoint/Controllers/Configuration/SetupController.cs b/Endpoint/Controllers/Configuration/SetupController.cs index cbb449f..ecc21c2 100644 --- a/Endpoint/Controllers/Configuration/SetupController.cs +++ b/Endpoint/Controllers/Configuration/SetupController.cs @@ -70,7 +70,17 @@ public class SetupController( [HttpGet("CheckToken")] public ActionResult CheckToken([FromQuery] string token) { - if (!setupToken.MatchToken(Convert.FromBase64String(token))) + byte[] tokenBase64; + try + { + tokenBase64 = Convert.FromBase64String(token); + } + catch (FormatException) + { + throw new ControllerArgumentException("A token of the wrong format."); + } + + if (!setupToken.MatchToken(tokenBase64)) return Unauthorized("The token is not valid"); Response.Cookies.Append(TokenAuthenticationAttribute.AuthToken, token, new CookieOptions