Skip to content

Commit 7813b67

Browse files
authored
node: change JWT error status to 401 Unauthorized (ethereum#25629)
1 parent 8df8eb4 commit 7813b67

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

node/jwt_handler.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (handler *jwtHandler) ServeHTTP(out http.ResponseWriter, r *http.Request) {
5151
strToken = strings.TrimPrefix(auth, "Bearer ")
5252
}
5353
if len(strToken) == 0 {
54-
http.Error(out, "missing token", http.StatusForbidden)
54+
http.Error(out, "missing token", http.StatusUnauthorized)
5555
return
5656
}
5757
// We explicitly set only HS256 allowed, and also disables the
@@ -63,17 +63,17 @@ func (handler *jwtHandler) ServeHTTP(out http.ResponseWriter, r *http.Request) {
6363

6464
switch {
6565
case err != nil:
66-
http.Error(out, err.Error(), http.StatusForbidden)
66+
http.Error(out, err.Error(), http.StatusUnauthorized)
6767
case !token.Valid:
68-
http.Error(out, "invalid token", http.StatusForbidden)
68+
http.Error(out, "invalid token", http.StatusUnauthorized)
6969
case !claims.VerifyExpiresAt(time.Now(), false): // optional
70-
http.Error(out, "token is expired", http.StatusForbidden)
70+
http.Error(out, "token is expired", http.StatusUnauthorized)
7171
case claims.IssuedAt == nil:
72-
http.Error(out, "missing issued-at", http.StatusForbidden)
72+
http.Error(out, "missing issued-at", http.StatusUnauthorized)
7373
case time.Since(claims.IssuedAt.Time) > jwtExpiryTimeout:
74-
http.Error(out, "stale token", http.StatusForbidden)
74+
http.Error(out, "stale token", http.StatusUnauthorized)
7575
case time.Until(claims.IssuedAt.Time) > jwtExpiryTimeout:
76-
http.Error(out, "future token", http.StatusForbidden)
76+
http.Error(out, "future token", http.StatusUnauthorized)
7777
default:
7878
handler.next.ServeHTTP(out, r)
7979
}

0 commit comments

Comments
 (0)