当启用 cookies HTTPOnly 时,Primefaces 监视器下载停止不起作用

发布于 2025-01-09 09:35:38 字数 1183 浏览 0 评论 0原文

我正在使用 Primefaces 11.0.0 我有一个下载文件组件,如下所示:

<p:commandButton 
    onclick="PrimeFaces.monitorDownload(startDownload, stopDownload);"
    ajax="false"
    icon="fa fa-download">
    <p:fileDownload value="#{downloadBean.getDownloadFile(document.id)}"/>
</p:commandButton>

我的应用程序在 Nginx 后面的 tomcat 上运行 我们有一个安全建议,将 HTTPOnly,Secure 添加到我们的 cookie 中 所以在Nginx上配置HTTPOnly到cookie时 stopDownload 永远不会被调用。

我的 Nginx 配置如下:

location /myapp {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_cookie_path /myapp "/myapp; HTTPOnly; Secure";
        }

How to make stopDownload Works with HTTPOnly ?

编辑:

我可以通过将 HTTPOnly 设置为重要的会话 cookie 来使其工作,如下所示:

proxy_cookie_flags ~ Secure;
proxy_cookie_flags JSESSIONID HTTPOnly Secure;

这是最佳实践还是有更好的解决方案?

I am using Primefaces 11.0.0
and I have a download file component as follows :

<p:commandButton 
    onclick="PrimeFaces.monitorDownload(startDownload, stopDownload);"
    ajax="false"
    icon="fa fa-download">
    <p:fileDownload value="#{downloadBean.getDownloadFile(document.id)}"/>
</p:commandButton>

My application is running on tomcat behind Nginx
and we have a security recommendation to add HTTPOnly,Secure to our cookies
so when configuring the HTTPOnly to cookies on Nginx
the stopDownload is never get called.

My Nginx config is as follows:

location /myapp {
            proxy_pass http://localhost:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_cookie_path /myapp "/myapp; HTTPOnly; Secure";
        }

How to make stopDownload works with HTTPOnly ?

EDIT:

I was able to make it work by setting HTTPOnly to important session cookies as follows :

proxy_cookie_flags ~ Secure;
proxy_cookie_flags JSESSIONID HTTPOnly Secure;

Is this is the best practice or there's a better solution ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2025-01-16 09:35:38

这是正确的。

因为 Monitor Download 需要使用 JavaScript 访问 cookie 来“停止下载”,所以 cookie 不能是 HTTP Only,这就是您的代码被破坏的原因。

您的 JSESSIONID cookie 绝对正确地锁定它。我认为您上面的配置是正确的。

That is correct.

Because Monitor Download needs to access the cookie with JavaScript to "stop the download" that cookie can not be HTTP Only which is why your code is breaking.

Your JSESSIONID cookie absolutely is correct to lock it down. In my opinion your configuration above is correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文