0

我正在使用 cakephp 2.X 版本。我尝试使用 ssl 加密实现登录。但是当我单击提交按钮时,发布数据不通过 ssl。

尝试遵循安全组件解决方案: http: //book.cakephp.org/2.0/en/core-libraries/components/security-component.html

但是,当 post 请求不是通过 HTTPS 时,它将被重定向到 https get 请求。这样我就无法正确登录。

我手动将我的登录表单操作更改为

<form action="https://localhost/users/login">

我工作。但是有没有更好的解决方案?

4

1 回答 1

0

您的解决方案确实有效,您可以通过在您的用户控制器中添加安全组件来添加额外的安全层:

public function beforeFilter() {
    $this->Security->requireSecure('login');
}

此外,您可以使用如下方法强制任何非 SSL 请求自动重定向到 SSL 请求blackHoleCallback

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

public function forceSSL() {
    $this->redirect('https://' . env('SERVER_NAME') . $this->here);
}

如果 SSL 对您的整个应用程序很重要(例如,如果您正在处理敏感数据),最好的解决方案是让您的 Web 服务器(Apache/nginx/无论您使用什么)对所有请求强制 SSL 并重定向任何非SSL 替代他们的 SSL。

于 2012-10-31T08:58:12.797 回答