Skip to content

Commit 3301800

Browse files
committed
prevent panic when sse token is not found
1 parent 4dd6fd0 commit 3301800

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

backend/internal/api/middleware/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func DecodeAuth() func(http.Handler) http.Handler {
2929
}
3030

3131
tokenAuth := jwtauth.New("RS256", privateKey, publicKey)
32-
return jwtauth.Verify(tokenAuth, jwtauth.TokenFromHeader)
32+
return jwtauth.Verify(tokenAuth, jwtauth.TokenFromHeader, jwtauth.TokenFromQuery)
3333
}
3434

3535
// Enforce is a authentication middleware to enforce access from the

backend/internal/api/middleware/sse_auth.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ import (
1414
func SSEAuth(next http.Handler) http.Handler {
1515
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1616
ctx := r.Context()
17-
1817
token, claims, err := jwtauth.FromContext(ctx)
18+
1919
if err != nil {
2020
h.ResultErrorJSON(w, r, http.StatusUnauthorized, err.Error(), nil)
2121
return
2222
}
2323

24+
if token == nil {
25+
h.ResultErrorJSON(w, r, http.StatusUnauthorized, "No token given", nil)
26+
return
27+
}
28+
29+
if claims != nil {
30+
h.ResultErrorJSON(w, r, http.StatusUnauthorized, "Unauthorised", nil)
31+
return
32+
}
33+
2434
userID := uint(claims["uid"].(float64))
2535
_, enabled := user.IsEnabled(userID)
2636
if token == nil || !token.Valid || !enabled || !claims.VerifyIssuer("sse", true) {

0 commit comments

Comments
 (0)