【发布时间】:2023-03-26 10:05:02
【问题描述】:
我有一个像下面这样的 Symfony 控制器:
public function postAction($key, Request $request)
{
/** @var @todo check that the key is passed and that it exists */
// Get the entity manager
$em = $this->getDoctrine()->getManager();
/**
* This call uses magic abilities of Doctrine that can find a record using
* the name of the field in the table on which the search has to be performed.
*
* ->findOneBy[FieldName]
*
*/
$entity = $em->getRepository('AppBundle:Entity')->findOneByKey($key);
如您所见,我将$key直接传递给Doctrine,以获取数据库中的对应行。
现在,由于这个 $key 是通过查询字符串传递的,并且攻击者可以传递他想要的东西,我的问题是:我应该对$key 的正确性进行一些检查吗?我是否应该实施一些机制来确保$key 不包含恶意代码,从而防止 SQL 注入攻击的可能性?
【问题讨论】:
-
Doctrine 在后台使用准备好的语句,您不必担心 sql 注入。
标签: php security symfony doctrine-orm sql-injection