在 Nginx 和 PHP 上添加“HttpOnly”和“Secure”cookie 标志

在 Nginx 和 PHP 上添加“HttpOnly”和“Secure”cookie 标志

我使用 Nginx 运行 PHP 和 WordPress。Acunetix 建议设置这些标志,但它们没有提供文档。我四处查看了一下,但没有看到任何确切说明如何实现这一点的内容。我有这个模块:http://wiki.nginx.org/HttpHeadersMoreModule在 Nginx 上,如果这有帮助的话。有没有关于如何设置这些标志的信息?谢谢。

根据此处的请求,cookie 示例

Cookie:__cfduid=d3-shortened-08;cf_use_ob=0;wordpress_logged_in_6dfda-shortened-e3e82d5;__utma=21-shortened-436.19;__utmc=21519150;__utmz=2119150.1396063475.3.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmct‌​r=(not%20provided);testing=1;sid=a14-shortened-384;sessiontest=1; wp-settings-2=editor%3Dhtml%26wplink%3D0%26uploader%3D1%26mfold%3Do%26ed_size%3D‌​677%26libraryContent%3Dbrowse%26urlbutton%3Dfile;wp-settings-time-2=139745167;wordpress_test_cookie=WP+Cookie+check;wordpress_logged_in_a9-shortened-d2a7=DrDinosaur%7C1397980-shortened-2f9

答案1

编辑你的 php.ini 并设置会话 cookie会话.cookie_secure或使用设置cookie在您的应用程序中。

答案2

这些 cookie 是在 PHP 代码中设置的,nginx 只是将从 PHP 收到的信息转发给网站访问者。

您也许能够使用 nginx-headers-more 模块修改标题,但这种方法也可能带来新的问题。

更安全的方法是修补 WP 的 Cookie 设置代码,以启用使用 httponly 和安全功能设置 cookie。

我不知道在 WP 中是否有任何启用这些功能的首选方法,或者您是否只需要破解实际的 cookie 设置代码。

答案3

确认一下:__cfduid这是 Cloudflare 提供的 cookie,不包含任何敏感数据。您也不能更改它以添加标志secure

答案4

尝试使用nginx_cookie_flag_module.它将解决您的问题。

相关内容