Skip to content

Commit

Permalink
Fix a XSS when using a custom format callable, it was silently bypass…
Browse files Browse the repository at this point in the history
…ing twig default escape by wrapping the string in a "Markup" object that is whitelisted

instead if people do need it we force them do to

->setStripTag(true) before
  • Loading branch information
allan-simon committed Apr 11, 2024
1 parent df81f10 commit ca8b01b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Field/Configurator/CommonPostConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use function Symfony\Component\String\u;
use Twig\Markup;
Expand Down Expand Up @@ -53,6 +54,14 @@ private function buildFormattedValueOption($value, FieldDto $field, EntityDto $e

$formatted = $callable($field->getValue(), $entityDto->getInstance());

// we don't want to unintentionally allow people to add XSS vulnerabilities
// in the code just because some people need to have HTML/JS
// so that if you want know what you're doing you have to explicitly
// disable this.
if ($field->getCustomOptions(TextField::OPTION_STRIP_TAGS)) {

Check failure on line 61 in src/Field/Configurator/CommonPostConfigurator.php

View workflow job for this annotation

GitHub Actions / phpstan

If condition is always true.

Check failure on line 61 in src/Field/Configurator/CommonPostConfigurator.php

View workflow job for this annotation

GitHub Actions / phpstan

Method EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto::getCustomOptions() invoked with 1 parameter, 0 required.

Check failure on line 61 in src/Field/Configurator/CommonPostConfigurator.php

View workflow job for this annotation

GitHub Actions / phpstan

Only booleans are allowed in an if condition, EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore given.
return $formatted;
}

// if the callable returns a string, wrap it in a Twig Markup to render the
// HTML and CSS/JS elements that it might contain
return \is_string($formatted) ? new Markup($formatted, $this->charset) : $formatted;

Check failure on line 67 in src/Field/Configurator/CommonPostConfigurator.php

View workflow job for this annotation

GitHub Actions / phpstan

Unreachable statement - code above always terminates.
Expand Down

0 comments on commit ca8b01b

Please sign in to comment.