Secure the twig renderer template loader
This commit is contained in:
@ -4,7 +4,9 @@ namespace App\Service\SnipParser\Twig;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use App\Repository\SnipRepository;
|
||||
use App\Security\Voter\SnipVoter;
|
||||
use App\Service\SnipContent\SnipContentService;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Loader\LoaderInterface;
|
||||
use Twig\Source;
|
||||
@ -14,6 +16,7 @@ class SnipLoader implements LoaderInterface
|
||||
public function __construct(
|
||||
private readonly SnipRepository $repository,
|
||||
private readonly SnipContentService $contentService,
|
||||
private readonly Security $security,
|
||||
) {}
|
||||
|
||||
public function getSourceContext(string $name): Source
|
||||
@ -50,6 +53,9 @@ class SnipLoader implements LoaderInterface
|
||||
if (!$snip) {
|
||||
throw new LoaderError(\sprintf('Template "%s" is not defined.', $key));
|
||||
}
|
||||
if (!$this->security->isGranted(SnipVoter::VIEW, $snip)) {
|
||||
throw new LoaderError(\sprintf('You do not have permission to view the template "%s".', $key));
|
||||
}
|
||||
|
||||
return $snip;
|
||||
}
|
||||
|
Reference in New Issue
Block a user