简体   繁体   English

如何保护控制器中的代码点火器功能?

[英]How to secure codeigniter functions in the controller?

I am currently developing something in codeigniter, a project that i need a little more security. 我目前在Codeigniter中开发一些东西,这个项目我需要更多的安全性。 (I bought an ssl certificate) (我买了ssl证书)

I saw that if i create a function, let's say the one that is called when i submit the account details to register an account, i can access it easy directly calling it. 我看到,如果我创建了一个函数,可以说当我提交帐户详细信息以注册帐户时调用的函数,我可以直接调用它来轻松地进行访问。

First of all it looks bad. 首先,它看起来很糟糕。 I wonder also if there is any security concerns i should worry about. 我也不知道我是否应该担心任何安全问题。

I found on the internet that a way of blocking direct access is to put this in every function: 我在互联网上发现阻止直接访问的一种方法是将其置于每个函数中:

$THE_REFER = strval(isset($_SERVER['HTTP_REFERER']));
if (!$THE_REFER)
redirect('home'); 

But doesn't look too professional. 但是看起来不太专业。

Thank you 谢谢

Are you looking for public vs private functions? 您在寻找公共功能还是私人功能?

HTML HTML

<form method="POST" action="/validate/register">
    <!-- username, password, blah blah blah -->
</form>

PHP (validate.php) PHP(validate.php)

class Validate extends CI_Controller {

    // accessible in URL
    public function register()
    {
        if($this->check_credentials())
        {
            // success message
        }
        else
        {
            // error message
        }
    }

    // accessible only in this class/controller
    private function verify_info()
    {
        // logic to check if info is good
        // work in CSRF token protection
        // return true or false
    }
}

The HTTP Referrer header contains whatever the client wants it to contain. HTTP Referrer标头包含客户端希望包含的所有内容。

You could store ( server side ) a timestamp against the session to record the client has loaded the account details form, then verify this record when you get an account submission . 您可以针对会话存储( 服务器端 )时间戳,以记录客户端已加载帐户详细信息表单,然后在提交帐户时验证此记录 It is up to you whether this record would be cleared if the user accesses other pages and how long it would remain valid. 由用户决定是否在用户访问其他页面时清除此记录以及该记录保持有效的时间。

There is no single easy solution as your ability to verify the client is limited. 没有一个简单的解决方案,因为您验证客户端的能力受到限制。 You must balance the effort you invest in security with the value of the data (and trust) you seek to protect and the degree to which you are exposed. 您必须在安全性投入与努力保护的数据(和信任)的价值以及暴露程度之间取得平衡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM