【发布时间】:2022-07-30 18:45:56
【问题描述】:
我是初学者。我写了这篇文章,并被告知我的 find() 方法存在安全漏洞。我认为我的 queryType 方法的 if else 阻止了 Sql 注入尝试。
public function queryType(string $sql, array $attributes = null)
{
## instance of Database singleton
$this->Database = Database::getInstance();
if($attributes !== null) {
## if attr, prepared request
$query = $this->Database->prepare($sql);
$query->execute($attributes);
return $query;
}else{
## else, simple request
return $this->Database->query($sql);
}
}
## SECURITY ISSUE /!\ ?? queryType if/else doesn't prevent ??
public function find(int $id)
{
return $this->queryType("SELECT * FROM {$this->table} WHERE id = $id")->fetch();
}
我该如何解决?
【问题讨论】:
-
您的
queryType方法是,这允许在其中执行原始查询,并且您的find不使用占位符,尽管有类型提示,但它没有被正确使用。并小心{$this->table},如果这是用户提供的,您需要将其与您的表一起列入白名单或仅定义它
标签: php sql sql-injection