From ecf8f2c6b37e6fd89907fd8eed05c3b6af88047b Mon Sep 17 00:00:00 2001 From: rach-ba Date: Wed, 27 Sep 2023 14:40:43 +0200 Subject: [PATCH] [gapi] add pattern body validation --- middleware/body_decoder.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/middleware/body_decoder.go b/middleware/body_decoder.go index ab05372..5577cc0 100644 --- a/middleware/body_decoder.go +++ b/middleware/body_decoder.go @@ -132,6 +132,10 @@ func (m BodyDecoder) Wrap(h handler.Handler) handler.Handler { return nil, errors.InternalServerError("pattern_must_be_regex", "pattern must contain a regular expression") } + if !val.Field(i).CanInterface() { + return nil, errors.InternalServerError("interface_failed", "interface cannot be used without panicking") + } + fieldValue := val.Field(i).Interface() if !rex.MatchString(fmt.Sprintf("%v", fieldValue)) { return nil, errors.BadRequest("body_validation_failed", "field %s does not match the required pattern", typeOfFieldI.Name)