HttpOnly cookie 如何与 Javascript 和身份验证代理一起使用?

How do HttpOnly cookies work with Javascript and authentication proxies?

我在 OIDC 反向代理后面有一个 Web 应用程序——换句话说,当我访问这个应用程序时,我被重定向到我的身份提供者,我登录并且我的浏览器设置了一个 cookie,该 cookie 用于后续请求证明我已经登录了。

此 cookie 设置了 HttpOnly 标志,我认为这是防止 XSS 漏洞被恶意网站利用的最佳做法。

但是,正如预期的那样,我的应用程序中的 Javascript 无法访问登录 cookie,因此在我的浏览器控制台中,我看到返回到应用程序的请求(尝试通过 HTTP 请求和websocket 连接)被重定向到我的身份提供者(并被 CORS 策略阻止),因为他们无权访问登录 cookie。

Does this mean that such an architecture cannot used Javascript?

没有。说明JS无法从cookie中读取数据

I see requests back to the application (trying to update dynamic content through both HTTP requests and websocket connections) being redirected to my identity provider (and blocked by CORS policy) since they do not have access to the login cookie.

CORS 策略不应阻止请求,因为缺少 cookie。

如果 cookie 丢失,那可能是因为您 (a) 混淆了您的来源并且该来源没有 cookie 或 (b) 您没有启用 credentials option 用于跨源请求。

Is it common to disable the HTTPOnly flag to allow Javascript to work?

没有

My understanding is that Javascript from a malicious website at a different origin trying to access my application would be blocked by CORS anyway, so would keeping the HTTPOnly flag only help against attacks where the attacker managed to inject Javascript into my application?

是的。 XSS 攻击非常普遍,因此有许多工具可以抵御它们。这是其中之一。