【问题标题】:Remove grafana cookie for user logout API删除用户注销 API 的 grafana cookie
【发布时间】:2021-11-30 08:34:38
【问题描述】:

我正在使用 grafana HTTP API 在 grafana 上构建前端应用程序。 用户身份验证使用基本身份验证模型(默认 grafana 身份验证)。我需要注销 API,这会导致 grafana_session cookie 过期。

我无法从我的脚本中删除 grafana_session cookie,因为 httpOnly 标志已打开。你能帮我处理用户注销吗?

我更改的唯一 grafana 配置是以下两个配置:

# set cookie SameSite attribute. defaults to `lax`. can be set to "lax", "strict", "none" and "disabled"
cookie_samesite = none

# set to true if you want to allow browsers to render Grafana in a <frame>, <iframe>, <embed> or <object>. d$
allow_embedding = true

【问题讨论】:

  • Cookie 是用于 UI 身份验证的,因此拥有用于 UI 注销的 API 没有意义。
  • 那么如何从脚本中删除 HttpOnly cookie?

标签: cookies grafana setcookie httpcookie grafana-api


【解决方案1】:

我找到了解决方案并在此处分享以帮助有相同问题的人。

正如 Jan 在评论中所说,Cookie 用于 UI 身份验证,并且是从服务器设置的。 HttpOnly 标志使 cookie 在跨站点脚本 (XSS) 的风险中安全,并且不能从 js 脚本中删除或覆盖。

Grafana 的默认身份验证使用 grafana_session cookie,这是一个 HttpOnly cookie。因此,如果其他人需要知道我们如何删除grafana_session cookie 以供用户注销,您应该只调用/logout 端点。

axios.get('http://localhost:3000/logout')

它会自动在请求头中设置cookie,这将删除geafana_session令牌并且用户需要登录才能进行下一个请求。

headers: {
  Cookie: 'grafana_session=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax'
}

以下链接帮助我了解了 HttpOnly cookie。可能对其他人有用:

https://stackoverflow.com/a/1085792/16994002

https://security.stackexchange.com/questions/211356/delete-secure-cookie-using-javascript

https://www.sjoerdlangkemper.nl/2020/05/27/overwriting-httponly-cookies-from-javascript-using-cookie-jar-overflow/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 2018-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-03
    • 1970-01-01
    相关资源
    最近更新 更多