git.iko.soy/typeable/oauth2-proxy
on master help sign in
feat: update HashNonce to use crypto/sha256 (#2967)

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

commitb2c69e25eb7ed3a1fd9ba085ba1dd6047979de8d authorEvan Gibler <20933572+egibs@users.noreply.github.com> dateTue 25 Mar 2025, 15:12 (2 years ago) parent44d035c
2 files changed+9−9
CHANGELOG.md+1 pkg/encryption/nonce.go+8−9
CHANGELOG.md+1
@@ -36,6 +36,7 @@
3636- [#2977](https://github.com/oauth2-proxy/oauth2-proxy/pull/2977) Update golang.org/x/net to v0.36.0 to address CVE-2025-22870 (@dsymonds)
3737- [#2982](https://github.com/oauth2-proxy/oauth2-proxy/pull/2982) chore(deps): remove go:generate tool from go.mod (@dolmen)
3838- [#3011](https://github.com/oauth2-proxy/oauth2-proxy/pull/3011) chore(deps): update golang dependencies and pin to latest golang v1.23.x release (@tuunit)
39+- [#2967](https://github.com/oauth2-proxy/oauth2-proxy/pull/2967) Update HashNonce to use crypto/sha256 (@egibs)
3940
4041# V7.8.1
4142
pkg/encryption/nonce.go+8−9
@@ -3,9 +3,8 @@ package encryption
33import (
44 "crypto/hmac"
55 "crypto/rand"
6+ "crypto/sha256"
67 "encoding/base64"
7−
8− "golang.org/x/crypto/blake2b"
98)
109
1110// Nonce generates a random n-byte slice
@@ -18,16 +17,16 @@ func Nonce(length int) ([]byte, error) {
1817 return b, nil
1918}
2019
21−// HashNonce returns the BLAKE2b 256-bit hash of a nonce
22−// NOTE: Error checking (G104) is purposefully skipped:
23−// - `blake2b.New256` has no error path with a nil signing key
24−// - `hash.Hash` interface's `Write` has an error signature, but
25−// `blake2b.digest.Write` does not use it.
26−/* #nosec G104 */
20+// HashNonce returns the SHA256 hash of a nonce
2721func HashNonce(nonce []byte) string {
28− hasher, _ := blake2b.New256(nil)
22+ if nonce == nil {
23+ return ""
24+ }
25+
26+ hasher := sha256.New()
2927 hasher.Write(nonce)
3028 sum := hasher.Sum(nil)
29+
3130 return base64.RawURLEncoding.EncodeToString(sum)
3231}
3332