From 1adfca9d281ab63beb5b0e2d031fd97ddda80291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 15 Dec 2023 13:16:05 +0200 Subject: [PATCH] fix(crypto): allow parsing of cost int from env string (#7061) fic(crypto): allow parsing of cost int from env string --- internal/crypto/passwap.go | 10 +++++++--- internal/crypto/passwap_test.go | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/crypto/passwap.go b/internal/crypto/passwap.go index 1d9fb6752..280fbe4d8 100644 --- a/internal/crypto/passwap.go +++ b/internal/crypto/passwap.go @@ -145,11 +145,15 @@ func (c *HasherConfig) buildHasher() (hasher passwap.Hasher, prefixes []string, } } +// decodeParams uses a mapstructure decoder from the Params map to dst. +// The decoder fails when there are unused fields in dst. +// It uses weak input typing, to allow conversion of env strings to ints. func (c *HasherConfig) decodeParams(dst any) error { decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ - ErrorUnused: false, - ErrorUnset: true, - Result: dst, + ErrorUnused: false, + ErrorUnset: true, + WeaklyTypedInput: true, + Result: dst, }) if err != nil { return err diff --git a/internal/crypto/passwap_test.go b/internal/crypto/passwap_test.go index 0538ac631..38ca0d5d3 100644 --- a/internal/crypto/passwap_test.go +++ b/internal/crypto/passwap_test.go @@ -397,7 +397,11 @@ func TestHasherConfig_decodeParams(t *testing.T) { "a": 1, "b": "2", }, - wantErr: true, + want: dst{ + A: 1, + B: 2, + }, + wantErr: false, // https://github.com/zitadel/zitadel/issues/6913 }, { name: "ok",