【问题标题】:Micronaut JWT attribute settings being ignoredMicronaut JWT 属性设置被忽略
【发布时间】:2020-12-17 09:23:58
【问题描述】:

我有一个基于 Micronaut 的网络应用程序,但在身份验证方面遇到了一些问题。该问题与浏览器正在发生的变化特别相关,SameSite 默认为 Lax,如果您使用 SameSite: none 那么 cookie 必须是安全的。我正在使用所有最新的稳定版本,例如Micronaut 2.0.1。

Chrome 给了我以下异常:

与跨站点资源关联的 cookie http://xxxxxx.herokuapp.com/ 设置时没有 SameSite 属性。 它已被阻止,因为 Chrome 现在只提供带有 使用SameSite=NoneSecure 设置的跨站点请求。 您可以在以下开发人员工具中查看 cookie 应用程序>存储>Cookies 并在以下位置查看更多详细信息 https://www.chromestatus.com/feature/5088147346030592https://www.chromestatus.com/feature/5633521622188032.

一个令人困惑的事情是它提到了 http 而不是 https,尽管当我观看网络活动时所有的 URL 都是 https。特别是,它抱怨两个请求,两个请求者的 URL 都是 https。

当我尝试登录时,会发生身份验证并返回 JWT cookie,但随后出现错误。我可以看到 JWT 的详细信息如下:

设置 Cookie:JWT=eyJhbGciOiJub2...U5ODYxNzA2MX0.;最大年龄=3600;过期=格林威治标准时间 2020 年 8 月 28 日星期五 13:17:41;路径=/;仅 HTTP

cookie 既不“安全”,也未指定 SameSite(因此默认为 Lax)。我要求它既是“SameSite: None”又是“secure”。

我在不同环境中配置了不同的 Micronaut 安全性,因为我们在生产环境中使用 OpenId (Azure AD),而在测试环境中只使用内部身份验证。我们似乎在两种环境中都存在同样被忽略的配置问题。这是两个 YML:

  application:
    name: xxxxx
  security:
    authentication: idtoken
    oauth2:
      enabled: true
      clients:
        azure:
          client-id: ${OAUTH_CLIENT_ID}
          client-secret: ${OAUTH_CLIENT_SECRET}
          openid:
            issuer: https://login.microsoftonline.com/xxx
      callback-uri: ${OAUTH_CALLBACK_URI}
    redirect:
      login-success: ${LOGIN_SUCCESS_URL}
      logout: '/logout-handler/logout-success'
    endpoints:
      logout:
        get-allowed: true
    token:
      jwt:
        cookie:
          cookie-same-site: none
          cookie-secure: true

  application:
    name: xxxxx
  security:
    authentication: cookie
    oauth2:
      enabled: false
      clients:
        azure:
          client-id: ${OAUTH_CLIENT_ID}
          client-secret: ${OAUTH_CLIENT_SECRET}
          openid:
            issuer: https://login.microsoftonline.com/xxx
      callback-uri: ${OAUTH_CALLBACK_URI}
    redirect:
      login-success: ${LOGIN_SUCCESS_URL}
      logout: '/logout-handler/logout-success'
    endpoints:
      logout:
        get-allowed: true
    token:
      jwt:
        cookie:
          cookie-same-site: none
          cookie-secure: true

如您所见,我正在尝试将 cookie-same-site 设置为 none 并将 cookie-secure 设置为 true 。它似乎不起作用。就此而言,根据文档,cookie-secure 应该默认为 true,所以我更加困惑为什么这没有通过。

我认为问题要么是 (1) 我在配置中误解了一些东西,要么是 (2) Micronaut 中的错误。如果有人可以提供建议,那就太好了。

【问题讨论】:

    标签: cookies oauth-2.0 jwt micronaut samesite


    【解决方案1】:

    有点晚了,但值必须是cookie-same-site: 'None'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-24
      • 2021-03-21
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多