Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enableTwigSandbox config setting
  • Loading branch information
brandonkelly committed Jan 2, 2026
commit acd83072d490d67c554ea1316c55a98197234e7a
37 changes: 37 additions & 0 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,24 @@ class GeneralConfig extends BaseConfig
*/
public bool $enableTemplateCaching = true;

/**
* @var bool Whether all Twig templates should be sandboxed.
*
* ::: code
* ```php Static Config
* ->enableTwigSandbox(false)
* ```
* ```shell Environment Override
* CRAFT_ENABLE_TWIG_SANDBOX=false
* ```
* :::
*
* @see enableTwigSandbox()
* @group Security
* @since 4.17.0
*/
public bool $enableTwigSandbox = true;

/**
* @var string The prefix that should be prepended to HTTP error status codes when determining the path to look for an error’s template.
*
Expand Down Expand Up @@ -4564,6 +4582,25 @@ public function enableTemplateCaching(bool $value = true): self
return $this;
}

/**
* Whether all Twig templates should be sandboxed.
*
* ```php
* ->enableTwigSandbox(false)
* ```
*
* @group Security
* @param bool $value
* @return self
* @see $enableTwigSandbox
* @since 4.17.0
*/
public function enableTwigSandbox(bool $value = true): self
{
$this->enableTwigSandbox = $value;
return $this;
}

/**
* The prefix that should be prepended to HTTP error status codes when determining the path to look for an error’s template.
*
Expand Down
2 changes: 1 addition & 1 deletion src/web/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function createTwig(): Environment
$twig = new Environment(new TemplateLoader($this), $this->_getTwigOptions());

// Even an empty security policy will prevent non-closures from being allowed as arrow functions
$twig->addExtension(new SandboxExtension(new SecurityPolicy(), true));
$twig->addExtension(new SandboxExtension(new SecurityPolicy(), Craft::$app->getConfig()->getGeneral()->enableTwigSandbox));

$twig->addExtension(new StringLoaderExtension());
$twig->addExtension(new Extension($this, $twig));
Expand Down