为什么不总是使用 HTTPOnly 和 Secure cookie 标志?

Why not always use HTTPOnly and Secure cookie flags?

安全 cookie 标志阻止通过 HTTP 发送 cookie。 HTTPOnly 标志阻止 JavaScript 访问 cookie。

仅 HTTPS 站点始终使用安全和 HTTPOnly cookie 是否是一个现实的准则?混合 HTTPS 和 HTTP 站点呢?缺点是什么?

显然,如果您需要 HTTPS 和 HTTP 页面上的 cookie,以及 JavaScript 访问您的网站才能正常工作,您不能使用这些标志,但设计良好的网站是否需要这样做?

Is it a realistic guideline that HTTPS only sites always use Secure and HTTPOnly cookies?

是的。

What about mixed HTTPS and HTTP sites?

不要创建混合 HTTPS/HTTP 站点。只是……不要。

CPU 不再那么昂贵,以至于在任何地方使用 HTTPS 都是一项严重的开销。搜索引擎将 HTTPS-only 视为一个积极的排名指标。

What are the disadvantages?

没有。

如果您确实需要从纯 HTTP 或 JS 访问 cookie,那么您可以关闭该设置。这就是指南的意义所在,您可以在有充分理由的情况下打破它们。在这种情况下很少见。

信息安全堆栈交换站点上有一个类似的 question。 Jonathan 的回答包括以下内容 - "For HTTP Only, you might want javascript to interact with the cookie. Maybe you track page state in a cookie, write to the cookie with JS, and read from JS." 换句话说,如果您想使用 cookie 跨会话维护用户的 UI 首选项,HTTPOnly 可能会产生干扰。