Skip to content

Commit 65cb8df

Browse files
MariusVanDerWijdencp-wjhan
authored andcommitted
node: set JWT expiry to 60 seconds (ethereum#25416)
* node: set JWT expiry to 60 seconds * node: rename var
1 parent 7385c06 commit 65cb8df

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

node/jwt_handler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/golang-jwt/jwt/v4"
2525
)
2626

27+
const jwtExpiryTimeout = 60 * time.Second
28+
2729
type jwtHandler struct {
2830
keyFunc func(token *jwt.Token) (interface{}, error)
2931
next http.Handler
@@ -68,9 +70,9 @@ func (handler *jwtHandler) ServeHTTP(out http.ResponseWriter, r *http.Request) {
6870
http.Error(out, "token is expired", http.StatusForbidden)
6971
case claims.IssuedAt == nil:
7072
http.Error(out, "missing issued-at", http.StatusForbidden)
71-
case time.Since(claims.IssuedAt.Time) > 5*time.Second:
73+
case time.Since(claims.IssuedAt.Time) > jwtExpiryTimeout:
7274
http.Error(out, "stale token", http.StatusForbidden)
73-
case time.Until(claims.IssuedAt.Time) > 5*time.Second:
75+
case time.Until(claims.IssuedAt.Time) > jwtExpiryTimeout:
7476
http.Error(out, "future token", http.StatusForbidden)
7577
default:
7678
handler.next.ServeHTTP(out, r)

node/rpcstack_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ func TestJWT(t *testing.T) {
356356
expFail := []func() string{
357357
// future
358358
func() string {
359-
return fmt.Sprintf("Bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix() + 6}))
359+
return fmt.Sprintf("Bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix() + int64(jwtExpiryTimeout.Seconds()) + 1}))
360360
},
361361
// stale
362362
func() string {
363-
return fmt.Sprintf("Bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix() - 6}))
363+
return fmt.Sprintf("Bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix() - int64(jwtExpiryTimeout.Seconds()) - 1}))
364364
},
365365
// wrong algo
366366
func() string {

0 commit comments

Comments
 (0)