N
N
Never Ever2021-10-08 12:28:19
symfony
Never Ever, 2021-10-08 12:28:19

Does expr()->literal() protect against SQL injection?

They make a filter and have doubts about such a decision. Is SQL injection possible? If so, how to solve.

$orStatements = $this->queryBuilder->expr()->orX();
foreach ($result as $value) {
    $orStatements->add(
        $this->queryBuilder->expr()->like('table.column', $this->queryBuilder->expr()->literal('%' . $value . '%'))
    );
}
$this->queryBuilder->andWhere($orStatements);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl0, 2021-10-08
@sl0

https://www.doctrine-project.org/projects/doctrine...
You are NOT safe from SQL injection when using user input with:
Expression API of Doctrine\ORM\QueryBuilder
Concatenating user input into DQL SELECT, UPDATE or DELETE statements or Native SQL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question