Why it matters
Template code reaches objects and filters, so the caller can read data or run code on this server.
How to fix it
Keep template text in files on the server and pass the request value in the context the template renders.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class MailController
{
public function preview(Request $request, \Twig\Environment $twig): Response
{
$template = $twig->createTemplate($request->request->get('body'));
return new Response($template->render(['name' => 'Ada']));
}
}<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class MailController
{
public function preview(Request $request, \Twig\Environment $twig): Response
{
return new Response($twig->render('mail/welcome.html.twig', ['name' => $request->request->get('name')]));
}
}What TrustIvan reads
Runs on repository scans of PHP source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- Regex injection from request input (PHP)
PHPSeverity: Medium
trustivan-php-taint-regex-injection - NoSQL injection from request input (PHP)
PHPSeverity: High
trustivan-php-taint-nosql-injection - Code injection from request input (PHP)
PHPSeverity: High
trustivan-php-taint-code-injection - SQL string concatenation (PHP)
PHPSeverity: Medium
trustivan-php-sql-string-concatenation - XPath injection from request input (PHP)
PHPSeverity: High
trustivan-php-taint-xpath-injection - Weak password hash (PHP)
PHPSeverity: High
trustivan-php-weak-password-hash
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation