gpt4 book ai didi

security - 在 FuelPHP 中清理用户输入

转载 作者:行者123 更新时间:2023-12-04 05:24:34 27 4
gpt4 key购买 nike

我对 FuelPHP 框架很陌生。现在我正在为位置列表实现“自动完成”。

我的代码如下所示:

public function action_search($term=null){
$clean_query = Security::clean($term);
$data["locations"] = array();
if ($clean_query != "") {
$data["locations"] = Model_Orm_Location::query()
->where("title", "like", $clean_query."%")
->get();
}

$response = Response::forge(View::forge("location/search", $data));
$response->set_header("Content-Type","application/json");
return $response;
}

如您所见,我正在连接 LIKE声明,这让我感觉很糟糕。这段代码对 SQL 注入(inject)安全吗?如果是,那是因为:
  • Security::clean将消除所有困惑;
  • where()在 ORM 查询中会做过滤吗?
  • 最佳答案

    看着implementation of Security::clean in the source code of core/class/security.php ,在您的情况下,应用的过滤器取决于 configuration security.input_filter, which is empty by default .所以没有应用过滤器。

    但是当你深入研究数据库抽象时,你会发现,当查询是 compiled就在执行之前,query builder will apply quote on the value在 where 条件下提供的 which will then apply escape on string values . escape 的实现方法取决于 DBMS 连接:

  • mysql_real_escape_string for mysql ,
  • mysqli::real_escape_string for mysqli , 和
  • PDO::quote for PDO .

  • 这反射(reflect)了当今的最佳实践。所以,是的,这对 SQL 注入(inject)是安全的。

    关于security - 在 FuelPHP 中清理用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13349155/

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