aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/gorilla/websocket/util.go
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2023-12-16 17:41:01 -0700
committerJordan <me@jordan.im>2023-12-16 17:41:01 -0700
commit7ecc048ae012a631bc3f0dcbd62f6190384ea0cd (patch)
treef8dd09feb67af740fb92d13c458e602f9bee8d45 /vendor/github.com/gorilla/websocket/util.go
parenta3dac1a28fdc9e42d85c4686858c64597cf1a15b (diff)
downloadkeep-7ecc048ae012a631bc3f0dcbd62f6190384ea0cd.tar.gz
keep-7ecc048ae012a631bc3f0dcbd62f6190384ea0cd.zip
misc: go get -u; go mod tidy; go mod vendorHEADmain
Diffstat (limited to 'vendor/github.com/gorilla/websocket/util.go')
-rw-r--r--vendor/github.com/gorilla/websocket/util.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/vendor/github.com/gorilla/websocket/util.go b/vendor/github.com/gorilla/websocket/util.go
index 7bf2f66..9b1a629 100644
--- a/vendor/github.com/gorilla/websocket/util.go
+++ b/vendor/github.com/gorilla/websocket/util.go
@@ -6,7 +6,7 @@ package websocket
import (
"crypto/rand"
- "crypto/sha1"
+ "crypto/sha1" //#nosec G505 -- (CWE-327) https://datatracker.ietf.org/doc/html/rfc6455#page-54
"encoding/base64"
"io"
"net/http"
@@ -17,7 +17,7 @@ import (
var keyGUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
func computeAcceptKey(challengeKey string) string {
- h := sha1.New()
+ h := sha1.New() //#nosec G401 -- (CWE-326) https://datatracker.ietf.org/doc/html/rfc6455#page-54
h.Write([]byte(challengeKey))
h.Write(keyGUID)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
@@ -281,3 +281,18 @@ headers:
}
return result
}
+
+// isValidChallengeKey checks if the argument meets RFC6455 specification.
+func isValidChallengeKey(s string) bool {
+ // From RFC6455:
+ //
+ // A |Sec-WebSocket-Key| header field with a base64-encoded (see
+ // Section 4 of [RFC4648]) value that, when decoded, is 16 bytes in
+ // length.
+
+ if s == "" {
+ return false
+ }
+ decoded, err := base64.StdEncoding.DecodeString(s)
+ return err == nil && len(decoded) == 16
+}