From 9cde9a2014f971a7f20edc27f325487e1b55fffc Mon Sep 17 00:00:00 2001 From: MateusMPereira Date: Thu, 2 May 2024 14:51:32 -0300 Subject: [PATCH 1/3] :bug: fix: Add base64 decode within try except scope --- src/Horse.BasicAuthentication.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Horse.BasicAuthentication.pas b/src/Horse.BasicAuthentication.pas index bf0724e..bde8d9e 100644 --- a/src/Horse.BasicAuthentication.pas +++ b/src/Horse.BasicAuthentication.pas @@ -139,9 +139,10 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED LBasicAuthenticationDecode.Delimiter := ':'; LBasicAuthenticationDecode.StrictDelimiter := True; LBase64String := LBasicAuthenticationEncode.Trim.Replace(BASIC_AUTH, '', [rfIgnoreCase]); - LBasicAuthenticationDecode.DelimitedText := {$IF DEFINED(FPC)}DecodeStringBase64(LBase64String){$ELSE}TBase64Encoding.base64.Decode(LBase64String){$ENDIF}; try + LBasicAuthenticationDecode.DelimitedText := {$IF DEFINED(FPC)}DecodeStringBase64(LBase64String){$ELSE}TBase64Encoding.base64.Decode(LBase64String){$ENDIF}; + if Assigned(AuthenticateWithResponse) then begin LIsAuthenticated := AuthenticateWithResponse(LBasicAuthenticationDecode.Strings[0], LBasicAuthenticationDecode.Strings[1], Res); From 9d1d69ad18b51efeff8f6f94f7c0bc03c12408a6 Mon Sep 17 00:00:00 2001 From: MateusMPereira Date: Thu, 2 May 2024 15:15:01 -0300 Subject: [PATCH 2/3] =?UTF-8?q?:recycle:=20refactor:=20Add=20tratativa=20d?= =?UTF-8?q?e=20erro=20de=20convers=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Horse.BasicAuthentication.pas | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Horse.BasicAuthentication.pas b/src/Horse.BasicAuthentication.pas index bde8d9e..a8ed6fa 100644 --- a/src/Horse.BasicAuthentication.pas +++ b/src/Horse.BasicAuthentication.pas @@ -152,6 +152,11 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED LIsAuthenticated := Authenticate(LBasicAuthenticationDecode.Strings[0], LBasicAuthenticationDecode.Strings[1]); end; except + on E: EEncodingError do + begin + Res.Send('Erro na conversão do Base64. Certifique-se de que a string Base64 está correta.').Status(THTTPStatus.InternalServerError); + raise EHorseCallbackInterrupted.Create; + end; on E: exception do begin Res.Send(E.Message).Status(THTTPStatus.InternalServerError); From 1be38ea2cd85f9f6f59d0ea9a470e8e42855f6f0 Mon Sep 17 00:00:00 2001 From: MateusMPereira Date: Thu, 2 May 2024 15:42:35 -0300 Subject: [PATCH 3/3] :card_file_box: raw: Att exception message. --- src/Horse.BasicAuthentication.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Horse.BasicAuthentication.pas b/src/Horse.BasicAuthentication.pas index a8ed6fa..80b57f0 100644 --- a/src/Horse.BasicAuthentication.pas +++ b/src/Horse.BasicAuthentication.pas @@ -154,7 +154,7 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED except on E: EEncodingError do begin - Res.Send('Erro na conversão do Base64. Certifique-se de que a string Base64 está correta.').Status(THTTPStatus.InternalServerError); + Res.Send('Base64 conversion error. Make sure that the Base64 string is correct.').Status(THTTPStatus.InternalServerError); raise EHorseCallbackInterrupted.Create; end; on E: exception do