Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: remove expiration threshold (#7277)
Danny Xu51d728aef276
diff --git a/backend/api/auth/auth.go b/backend/api/auth/auth.goindex 54f16af781..d7fe55778d 100644--- a/backend/api/auth/auth.go+++ b/backend/api/auth/auth.go@@ -36,16 +36,9 @@ const (MFATempTokenAudienceFmt = "bb.user.mfa-temp.%s"apiTokenDuration = 1 * time.HouraccessTokenDuration = 1 * time.Hour- refreshTokenDuration = 7 * 24 * time.Hour- // RefreshThresholdDuration is the threshold duration for refreshing token.- RefreshThresholdDuration = 0 * time.Hour-- // CookieExpDuration expires slightly earlier than the jwt expiration. Client would be logged out if the user- // cookie expires, thus the client would always logout first before attempting to make a request with the expired jwt.- // Suppose we have a valid refresh token, we will refresh the token in 2 cases:- // 1. The access token is about to expire in <<refreshThresholdDuration>>- // 2. The access token has already expired, we refresh the token so that the ongoing request can pass through.- CookieExpDuration = refreshTokenDuration - 1*time.Minute+ // DefaultRefreshTokenDuration is the default refresh token expiration duration.+ DefaultRefreshTokenDuration = 7 * 24 * time.Hour+// AccessTokenCookieName is the cookie name of access token.AccessTokenCookieName = "access-token"// RefreshTokenCookieName is the cookie name of refresh token.@@ -175,9 +168,6 @@ func (in *APIAuthInterceptor) authenticate(ctx context.Context, accessTokenStr,fmt.Sprintf(AccessTokenAudienceFmt, in.mode),)}- if time.Until(claims.ExpiresAt.Time) < RefreshThresholdDuration {- generateToken = true- }principalID, err := strconv.Atoi(claims.Subject)if err != nil {@@ -348,7 +338,7 @@ func GenerateAccessToken(userName string, userID int, mode common.ReleaseMode, s// GenerateRefreshToken generates a refresh token for web.func GenerateRefreshToken(userName string, userID int, mode common.ReleaseMode, secret string) (string, error) {- expirationTime := time.Now().Add(refreshTokenDuration)+ expirationTime := time.Now().Add(DefaultRefreshTokenDuration)return generateToken(userName, userID, fmt.Sprintf(RefreshTokenAudienceFmt, mode), expirationTime, []byte(secret))}diff --git a/backend/api/auth/header.go b/backend/api/auth/header.goindex a8ce85f0c3..20389774aa 100644--- a/backend/api/auth/header.go+++ b/backend/api/auth/header.go@@ -50,9 +50,14 @@ func processMetadata(md runtime.ServerMetadata, metadataKey, cookieName string,sameSite = http.SameSiteNoneMode}http.SetCookie(response, &http.Cookie{- Name: cookieName,- Value: value,- Expires: time.Now().Add(CookieExpDuration),+ Name: cookieName,+ Value: value,+ // CookieExpDuration expires slightly earlier than the jwt expiration. Client would be logged out if the user+ // cookie expires, thus the client would always logout first before attempting to make a request with the expired jwt.+ // Suppose we have a valid refresh token, we will refresh the token in 2 cases:+ // 1. The access token is about to expire in <<refreshThresholdDuration>>+ // 2. The access token has already expired, we refresh the token so that the ongoing request can pass through.+ Expires: time.Now().Add(DefaultRefreshTokenDuration - 1*time.Minute),Path: "/",// Http-only helps mitigate the risk of client side script accessing the protected cookie.HttpOnly: httpOnly,diff --git a/backend/server/jwt.go b/backend/server/jwt.goindex a6f23ba870..107cd0b876 100644--- a/backend/server/jwt.go+++ b/backend/server/jwt.go@@ -42,7 +42,7 @@ func GenerateTokensAndSetCookies(c echo.Context, user *store.UserMessage, mode creturn pkgerrors.Wrap(err, "failed to generate access token")}- cookieExp := time.Now().Add(auth.CookieExpDuration)+ cookieExp := time.Now().Add(auth.DefaultRefreshTokenDuration - 1*time.Minute)setTokenCookie(c, auth.AccessTokenCookieName, accessToken, cookieExp)setUserCookie(c, user.ID, cookieExp)@@ -166,7 +166,7 @@ func JWTMiddleware(pathPrefix string, principalStore *store.Store, next echo.Han))}- generateToken := time.Until(claims.ExpiresAt.Time) < auth.RefreshThresholdDuration+ generateToken := falseif err != nil {var ve *jwt.ValidationErrorif errors.As(err, &ve) {