Skip to content

Commit 9284b83

Browse files
Merge pull request #417 from supertokens/fix/access-token-expiry
fix: update access token cookie expiry to 1 year
2 parents 85fbac6 + 024598a commit 9284b83

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.22.0] - 2024-06-24
11+
12+
### Breaking change
13+
14+
- The access token cookie expiry has been changed from 100 years to 1 year due to some browsers capping the maximum expiry at 400 days. No action is needed on your part.
15+
1016
## [0.21.0] - 2024-06-10
1117
- Adds caching per API based on user context.
1218

recipe/session/utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func ValidateAndNormaliseUserInput(appInfo supertokens.NormalisedAppinfo, config
257257
return typeNormalisedInput, nil
258258
}
259259

260-
var accessTokenCookiesExpiryDurationMillis uint64 = 3153600000000
260+
var accessTokenCookiesExpiryDurationMillis uint64 = 31536000000
261261

262262
func normaliseSameSiteOrThrowError(sameSite string) (string, error) {
263263
sameSite = strings.TrimSpace(sameSite)
@@ -325,17 +325,17 @@ func GetCurrTimeInMS() uint64 {
325325

326326
func SetAccessTokenInResponse(config sessmodels.TypeNormalisedInput, res http.ResponseWriter, accessToken string, frontToken string, tokenTransferMethod sessmodels.TokenTransferMethod, request *http.Request, userContext supertokens.UserContext) error {
327327
setFrontTokenInHeaders(res, frontToken)
328-
// We set the expiration to 100 years, because we can't really access the expiration of the refresh token everywhere we are setting it.
328+
// We set the expiration to 1 year, because we can't really access the expiration of the refresh token everywhere we are setting it.
329329
// This should be safe to do, since this is only the validity of the cookie (set here or on the frontend) but we check the expiration of the JWT anyway.
330330
// Even if the token is expired the presence of the token indicates that the user could have a valid refresh
331-
// Setting them to infinity would require special case handling on the frontend and just adding 100 years seems enough.
331+
// Some browsers now cap the maximum expiry at 400 days, so we set it to 1 year, which should suffice.
332332
setToken(config, res, sessmodels.AccessToken, accessToken, GetCurrTimeInMS()+accessTokenCookiesExpiryDurationMillis, tokenTransferMethod, request, userContext)
333333

334334
if config.ExposeAccessTokenToFrontendInCookieBasedAuth && tokenTransferMethod == sessmodels.CookieTransferMethod {
335-
// We set the expiration to 100 years, because we can't really access the expiration of the refresh token everywhere we are setting it.
335+
// We set the expiration to 1 year, because we can't really access the expiration of the refresh token everywhere we are setting it.
336336
// This should be safe to do, since this is only the validity of the cookie (set here or on the frontend) but we check the expiration of the JWT anyway.
337337
// Even if the token is expired the presence of the token indicates that the user could have a valid refresh
338-
// Setting them to infinity would require special case handling on the frontend and just adding 100 years seems enough.
338+
// Some browsers now cap the maximum expiry at 400 days, so we set it to 1 year, which should suffice.
339339
setToken(config, res, sessmodels.AccessToken, accessToken, GetCurrTimeInMS()+accessTokenCookiesExpiryDurationMillis, sessmodels.HeaderTransferMethod, request, userContext)
340340
}
341341
return nil

supertokens/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
// VERSION current version of the lib
24-
const VERSION = "0.21.0"
24+
const VERSION = "0.22.0"
2525

2626
var (
2727
cdiSupported = []string{"3.0"}

0 commit comments

Comments
 (0)