From 458cf36ae702d1d596ef95de6cfbfd609fc2b8c7 Mon Sep 17 00:00:00 2001 From: Frederic Jahn Date: Thu, 27 Jun 2024 10:29:44 +0200 Subject: [PATCH] fix: set an empty json body if no body is set --- server/api/handler/webauthn.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/api/handler/webauthn.go b/server/api/handler/webauthn.go index fbbe79f..35a7e65 100644 --- a/server/api/handler/webauthn.go +++ b/server/api/handler/webauthn.go @@ -8,7 +8,9 @@ import ( auditlog "github.com/teamhanko/passkey-server/audit_log" "github.com/teamhanko/passkey-server/persistence" "github.com/teamhanko/passkey-server/persistence/models" + "io" "net/http" + "strings" ) type WebauthnHandler interface { @@ -49,6 +51,11 @@ func (w *webauthnHandler) handleError(logger auditlog.Logger, logType models.Aud func BindAndValidateRequest[I request.CredentialRequests | request.WebauthnRequests](ctx echo.Context) (*I, error) { var requestDto I + + if ctx.Request().ContentLength <= 0 { + ctx.Request().Body = io.NopCloser(strings.NewReader("{}")) + } + err := ctx.Bind(&requestDto) if err != nil { ctx.Logger().Error(err)