Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jwt): set issued_at to nil prior to validating claims #813

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/token/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (tm *Manager) ParseToken(token string) (*Claims, error) {
claims = t.Claims.(*Claims)
name := claims.Subject

// according to JWT RFC, the iat field is optional for security purposes and is purely informational.
// setting it to nil avoids any worries of race conditions.
claims.IssuedAt = nil

// check if subject has a value in claims;
// we can save a db lookup attempt
if len(name) == 0 {
Expand Down
6 changes: 3 additions & 3 deletions internal/token/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestTokenManager_ParseToken(t *testing.T) {
TokenType: constants.UserAccessTokenType,
RegisteredClaims: jwt.RegisteredClaims{
Subject: u.GetName(),
IssuedAt: jwt.NewNumericDate(now),
IssuedAt: nil,
ExpiresAt: jwt.NewNumericDate(now.Add(time.Minute * 5)),
},
},
Expand All @@ -69,7 +69,7 @@ func TestTokenManager_ParseToken(t *testing.T) {
TokenType: constants.UserRefreshTokenType,
RegisteredClaims: jwt.RegisteredClaims{
Subject: u.GetName(),
IssuedAt: jwt.NewNumericDate(now),
IssuedAt: nil,
ExpiresAt: jwt.NewNumericDate(now.Add(time.Minute * 30)),
},
},
Expand All @@ -89,7 +89,7 @@ func TestTokenManager_ParseToken(t *testing.T) {
TokenType: constants.WorkerBuildTokenType,
RegisteredClaims: jwt.RegisteredClaims{
Subject: "worker",
IssuedAt: jwt.NewNumericDate(now),
IssuedAt: nil,
ExpiresAt: jwt.NewNumericDate(now.Add(time.Minute * 90)),
},
},
Expand Down
4 changes: 2 additions & 2 deletions router/middleware/claims/claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestClaims_Establish(t *testing.T) {
IsActive: true,
RegisteredClaims: jwt.RegisteredClaims{
Subject: "foo",
IssuedAt: jwt.NewNumericDate(now),
IssuedAt: nil,
ExpiresAt: jwt.NewNumericDate(now.Add(time.Minute * 5)),
},
},
Expand All @@ -108,7 +108,7 @@ func TestClaims_Establish(t *testing.T) {
Repo: "foo/bar",
RegisteredClaims: jwt.RegisteredClaims{
Subject: "host",
IssuedAt: jwt.NewNumericDate(now),
IssuedAt: nil,
ExpiresAt: jwt.NewNumericDate(now.Add(time.Minute * 35)),
},
},
Expand Down