gpt4 book ai didi

php - 安全组件给出 'secure' 黑洞错误,而在 https 上

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:54 24 4
gpt4 key购买 nike

刚刚移动了服务器,现有代码现在出现了一个奇怪的问题。

代码的要点是捕获“安全”黑洞错误,并将其重定向到该页面的安全版本。它是在旧服务器上执行的,但现在表现得很奇怪。

// App Controller

public function beforeFilter() {
$this->Security->blackHoleCallback = 'blackhole';
}

public function blackhole($type) {
switch($type) {
case 'secure':
debug(Router::url($this->here, true));
exit;
$this->redirect('https://' . env('SERVER_NAME') . $this->here);
break;
}
}

调试显示:`http://www.example.com/ '

但是我的浏览器显示' https://www.example.com/ '(注意 S)

最佳答案

更好的答案是根本不使用此功能。

您不应该在代码中重定向到 HTTPS。你应该使用 Strict-Transport-Security .这仍然涉及重定向,但还涉及设置额外的 header 。

您可以使用 mod_ssl 的功能:

SSLOptions +StrictRequire
SSLRequireSSL

请注意,SSLRequireSSL 指令将拒绝所有未启用 SSL 的请求。

和一个正常的重定向:

RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

这基本上重写了使用 HTTPS 作为 403 重定向的请求。

您还想设置 Strict-Transport-Security header :

Header set Strict-Transport-Security "max-age=8640000;includeSubdomains"

完成了。无需使用 Cake。在服务器级别处理它,因为那是服务器级别。这意味着甚至没有错误的请求可以进入...

关于php - 安全组件给出 'secure' 黑洞错误,而在 https 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25513253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com