From 802c5f92d7bec44815e7db662f97d5ac8074933f Mon Sep 17 00:00:00 2001 From: Luca Berneking Date: Thu, 11 Jan 2024 10:45:43 +0100 Subject: [PATCH] copy default parameters to prevent concurrent map write --- auth/handler.go | 7 ++++++- go.mod | 1 + go.sum | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/auth/handler.go b/auth/handler.go index 6ce306c..6bec6ce 100644 --- a/auth/handler.go +++ b/auth/handler.go @@ -30,6 +30,7 @@ import ( "github.com/dgrijalva/jwt-go" "github.com/gomodule/redigo/redis" + "github.com/jinzhu/copier" "github.com/mittwald/servicegateway/config" "github.com/op/go-logging" cache "github.com/patrickmn/go-cache" @@ -106,7 +107,11 @@ func NewAuthenticationHandler( func (h *AuthenticationHandler) Authenticate(username string, password string, additionalBodyProperties map[string]interface{}) (*JWTResponse, error) { response := JWTResponse{} - authRequest := h.config.ProviderConfig.Parameters + authRequest := make(map[string]interface{}) + err := copier.Copy(&authRequest, h.config.ProviderConfig.Parameters) + if err != nil { + return nil, fmt.Errorf("failed to copy default parameters!") + } authRequest["username"] = username authRequest["password"] = password diff --git a/go.mod b/go.mod index 58ed2f4..329ce17 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/gorilla/handlers v1.5.2 github.com/hashicorp/consul/api v1.26.1 github.com/hashicorp/golang-lru v1.0.2 + github.com/jinzhu/copier v0.4.0 github.com/julienschmidt/httprouter v1.3.0 github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 github.com/patrickmn/go-cache v2.1.0+incompatible diff --git a/go.sum b/go.sum index 7d3b5d6..cf54f2e 100644 --- a/go.sum +++ b/go.sum @@ -103,6 +103,8 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY= github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4= +github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8= +github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=