AccessToken 过期后静默刷新仍然有效

问题描述

我有一个 ID4 身份验证服务器,它与一个 Angular 应用运行良好,该应用通过 SilentRefresh 和 PCKE 授权流程实现了 angular-oauth2-oidc

一切正常 - ID4 配置为以 5 分钟的生命周期提供 Accesstoken,Angular 应用程序将每分钟静刷新令牌(可能会随着 0.75 时间的流逝而更改为刷新)。然而,我发现的问题是,我可以关闭登录的浏览器 - 然后 10 分钟后在网站上再次打开它(在原始 Accesstoken 过期后没有刷新) - 但是静刷新会刷新令牌并且用户保持登录状态。这是一个重大的安全漏洞。

我的客户端配置如下:

{
    issuer: config.authServerUrl,clientId: '<redacted>',// The "Auth Code + PKCE" client
    responseType: 'code',redirectUri: window.location.origin,silentRefreshredirectUri: window.location.origin + '/silent-refresh.html',postlogoutRedirectUri: window.location.origin,scope: 'openid profile email api',useSilentRefresh: true,// Needed for Code Flow to suggest using iframe-based refreshes
    silentRefreshTimeout: 60000,// For faster testing
    sessionChecksEnabled: true,showDebuginformation: !config.production,// Also requires enabling "Verbose" level in devtools
    clearHashAfterLogin: false,nonceStateSeparator : 'semicolon',// Real semicolon gets mangled by IdentityServer's URI encoding
  }

我的 ID4 配置如下所示:

      {
        "Enabled": true,"ClientId": "<redacted>","ClientName": "<redacted>","ClientSecrets": [ { "Value": "<redacted>" } ],"AccesstokenLifetime": "300","AllowedGrantTypes": [ "authorization_code" ],"AllowedScopes": [ "openid","profile","email","api" ],"AllowedCorsOrigins": [
          "http://localhost:4200"
        ],"PostlogoutRedirectUris": [
          "http://localhost:4200"
        ],"RedirectUris": [
          "http://localhost:4200","http://localhost:4200/silent-refresh.html"
        ]
      }

我希望这种行为是,只有在 Accesstoken 的到期时间内再次在站点上打开浏览器时,静刷新才会起作用 - 即,如果我在 Accesstoken 过期后打开 - 那么我无法刷新并且需要登录

似乎 Silent Refresh 不使用 RefreshTokens,因为登录显示的范围不包括 offline_access 并且我没有在 ID4 端将 AllowOfflineAccess 设置为 true。此处是否使用了刷新令牌 - 是否以某种方式暗示了配置 - 如果是这样,为什么您可以允许 RefreshTokens 生命周期长于 Accesstokens?

解决方法

一个想法是您的 IdentityServer 在您初始登录期间设置了自己的“会话”cookie,并且使用该 cookie 允许应用程序以静默方式重新进行身份验证并获取新的访问令牌。您可以从 IdentityServer 调整此 cookie 的生命周期。

我会使用像 Fiddler 这样的代理来验证这种行为。