Php Symfony,教义和通过的参数:我应该注意什么?
我有一个Symfony控制器,如下所示:Php Symfony,教义和通过的参数:我应该注意什么?,php,security,symfony,doctrine-orm,sql-injection,Php,Security,Symfony,Doctrine Orm,Sql Injection,我有一个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 ca
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注入攻击的可能性?不,您不必担心,条令会帮您做到这一点
请参阅以了解更多信息,并且原则使用预先准备好的语句,您不必担心sql注入。