Skip to content

Commit

Permalink
Tweak Sandbox docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 28, 2025
1 parent 932a584 commit 71f83ec
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions doc/sandbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The sandbox security is managed by a policy instance, which must be passed to
the ``SandboxExtension`` constructor.

By default, Twig comes with one policy class: ``\Twig\Sandbox\SecurityPolicy``.
This class allows you to allow-list some tags, filters, functions, but also
This class allows you to allow-list some tags, filters, functions, and
properties and methods on objects::

$tags = ['if'];
Expand All @@ -31,11 +31,11 @@ properties and methods on objects::
$functions = ['range'];
$policy = new \Twig\Sandbox\SecurityPolicy($tags, $filters, $methods, $properties, $functions);

With the previous configuration, the security policy will only allow usage of
the ``if`` tag, and the ``upper`` filter. Moreover, the templates will only be
able to call the ``getTitle()`` and ``getBody()`` methods on ``Article``
objects, and the ``title`` and ``body`` public properties. Everything else
won't be allowed and will generate a ``\Twig\Sandbox\SecurityError`` exception.
With the above configuration, the security policy will only allow usage of the
``if`` tag, and the ``upper`` filter. Moreover, the templates will only be able
to call the ``getTitle()`` and ``getBody()`` methods on ``Article`` objects,
and the ``title`` and ``body`` public properties. Everything else won't be
allowed and will generate a ``\Twig\Sandbox\SecurityError`` exception.

.. note::

Expand Down Expand Up @@ -66,7 +66,7 @@ function:
You can sandbox all templates by passing ``true`` as the second argument of
the extension constructor::

$sandbox = new \Twig\Extension\SandboxExtension($policy, true);
$twig->addExtension(new \Twig\Extension\SandboxExtension($policy, true));

Accepting Callables Arguments
-----------------------------
Expand Down

0 comments on commit 71f83ec

Please sign in to comment.