【问题标题】:Symfony, Doctrine and passed parameters: of what should have I to take care?Symfony、Doctrine 和传递的参数:我应该注意什么?
【发布时间】: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


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 2019-09-26
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2012-06-23
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
相关资源
最近更新 更多