verifyWebsocketToken checks for a valid websocket token in the request headers. If present, invalidate the token so it can't be reused. Returns a nil error if there is no token on the header but no user object. If the header is found,
()
| 1068 | // |
| 1069 | // Returns a nil error if there is no token on the header but no user object. If the header is found, |
| 1070 | func (h *handler) getWebsocketToken() string { |
| 1071 | // go blip expects only one Sec-WebSocket-Protocol header, with comma separated values |
| 1072 | protocolHeaders := h.rq.Header.Get(secWebSocketProtocolHeader) |
| 1073 | var outputHeaders []string |
| 1074 | var sessionID string |
| 1075 | for header := range strings.SplitSeq(protocolHeaders, ",") { |
| 1076 | trimmedHeader := strings.TrimSpace(header) |
| 1077 | if !strings.HasPrefix(trimmedHeader, blipSessionIDPrefix) { |
| 1078 | outputHeaders = append(outputHeaders, header) |
| 1079 | continue |
| 1080 | } |
| 1081 | sessionID = strings.TrimPrefix(trimmedHeader, blipSessionIDPrefix) |
| 1082 | } |
| 1083 | if sessionID == "" { |
| 1084 | return "" |
| 1085 | } |
| 1086 | // Remove the websocket protocol so it doesn't get logged in BlipWebsocketServer.handshake |
| 1087 | h.rq.Header.Set(secWebSocketProtocolHeader, strings.Join(outputHeaders, ",")) |
| 1088 | return sessionID |
| 1089 | } |
| 1090 | |
| 1091 | func checkJWTIssuerStillValid(ctx context.Context, dbCtx *db.DatabaseContext, user auth.User) *auth.PrincipalConfig { |
| 1092 | issuer := user.JWTIssuer() |
no test coverage detected