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 ca8b01b commit 0c8aa0f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Field/Configurator/CommonPostConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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\Field\FieldTrait;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use function Symfony\Component\String\u;
use Twig\Markup;
Expand Down Expand Up @@ -58,7 +58,7 @@ private function buildFormattedValueOption($value, FieldDto $field, EntityDto $e
// 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)) {
if ($field->getCustomOption(FieldTrait::OPTION_STRIP_TAGS) ?? true) {

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, mixed given.
return $formatted;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Field/FieldTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
trait FieldTrait
{
public const OPTION_STRIP_TAGS = 'stripTags';

private FieldDto $dto;

private function __construct()
Expand Down Expand Up @@ -337,6 +339,13 @@ public function setCustomOptions(array $options): self

return $this;
}

public function stripTags(bool $stripTags = true): self
{
$this->setCustomOption(self::OPTION_STRIP_TAGS, $stripTags);

return $this;
}

public function hideOnDetail(): self
{
Expand Down
8 changes: 0 additions & 8 deletions src/Field/TextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class TextField implements FieldInterface

public const OPTION_MAX_LENGTH = 'maxLength';
public const OPTION_RENDER_AS_HTML = 'renderAsHtml';
public const OPTION_STRIP_TAGS = 'stripTags';

/**
* @param TranslatableInterface|string|false|null $label
Expand Down Expand Up @@ -55,11 +54,4 @@ public function renderAsHtml(bool $asHtml = true): self

return $this;
}

public function stripTags(bool $stripTags = true): self
{
$this->setCustomOption(self::OPTION_STRIP_TAGS, $stripTags);

return $this;
}
}
9 changes: 0 additions & 9 deletions src/Field/TextareaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ final class TextareaField implements FieldInterface
public const OPTION_MAX_LENGTH = TextField::OPTION_MAX_LENGTH;
public const OPTION_NUM_OF_ROWS = 'numOfRows';
public const OPTION_RENDER_AS_HTML = TextField::OPTION_RENDER_AS_HTML;
public const OPTION_STRIP_TAGS = TextField::OPTION_STRIP_TAGS;

/**
* @param TranslatableInterface|string|false|null $label
*/
Expand Down Expand Up @@ -70,11 +68,4 @@ public function renderAsHtml(bool $asHtml = true): self

return $this;
}

public function stripTags(bool $stripTags = true): self
{
$this->setCustomOption(self::OPTION_STRIP_TAGS, $stripTags);

return $this;
}
}

0 comments on commit 0c8aa0f

Please sign in to comment.