Current File : //usr/share/doc/python-jinja2-2.7.2/html/_sources/sandbox.txt
Sandbox
=======

The Jinja2 sandbox can be used to evaluate untrusted code.  Access to unsafe
attributes and methods is prohibited.

Assuming `env` is a :class:`SandboxedEnvironment` in the default configuration
the following piece of code shows how it works:

>>> env.from_string("{{ func.func_code }}").render(func=lambda:None)
u''
>>> env.from_string("{{ func.func_code.do_something }}").render(func=lambda:None)
Traceback (most recent call last):
  ...
SecurityError: access to attribute 'func_code' of 'function' object is unsafe.

API
---

.. module:: jinja2.sandbox

.. autoclass:: SandboxedEnvironment([options])
    :members: is_safe_attribute, is_safe_callable, default_binop_table,
              default_unop_table, intercepted_binops, intercepted_unops,
              call_binop, call_unop

.. autoclass:: ImmutableSandboxedEnvironment([options])

.. autoexception:: SecurityError

.. autofunction:: unsafe

.. autofunction:: is_internal_attribute

.. autofunction:: modifies_known_mutable

.. admonition:: Note

    The Jinja2 sandbox alone is no solution for perfect security.  Especially
    for web applications you have to keep in mind that users may create
    templates with arbitrary HTML in so it's crucial to ensure that (if you
    are running multiple users on the same server) they can't harm each other
    via JavaScript insertions and much more.

    Also the sandbox is only as good as the configuration.  We strongly
    recommend only passing non-shared resources to the template and use
    some sort of whitelisting for attributes.

    Also keep in mind that templates may raise runtime or compile time errors,
    so make sure to catch them.

Operator Intercepting
---------------------

.. versionadded:: 2.6

For maximum performace Jinja2 will let operators call directly the type
specific callback methods.  This means that it's not possible to have this
intercepted by overriding :meth:`Environment.call`.  Furthermore a
conversion from operator to special method is not always directly possible
due to how operators work.  For instance for divisions more than one
special method exist.

With Jinja 2.6 there is now support for explicit operator intercepting.
This can be used to customize specific operators as necessary.  In order
to intercept an operator one has to override the
:attr:`SandboxedEnvironment.intercepted_binops` attribute.  Once the
operator that needs to be intercepted is added to that set Jinja2 will
generate bytecode that calls the :meth:`SandboxedEnvironment.call_binop`
function.  For unary operators the `unary` attributes and methods have to
be used instead.

The default implementation of :attr:`SandboxedEnvironment.call_binop`
will use the :attr:`SandboxedEnvironment.binop_table` to translate
operator symbols into callbacks performing the default operator behavior.

This example shows how the power (``**``) operator can be disabled in
Jinja2::

    from jinja2.sandbox import SandboxedEnvironment


    class MyEnvironment(SandboxedEnvironment):
        intercepted_binops = frozenset(['**'])

        def call_binop(self, context, operator, left, right):
            if operator == '**':
                return self.undefined('the power operator is unavailable')
            return SandboxedEnvironment.call_binop(self, context,
                                                   operator, left, right)

Make sure to always call into the super method, even if you are not
intercepting the call.  Jinja2 might internally call the method to
evaluate expressions.
blog

blog

91 Club Online Casino in India Demo Mode and Practice.1118

91 Club Online Casino in India – Demo Mode and Practice ▶️ PLAY Содержимое 91 Club Online Casino in India: A Comprehensive Guide Discover the Thrill of Online Casino Gaming with 91 Club Why Choose 91 Club? Practice Your Skills in Demo Mode and Get Ready to Win Big In …

Read More »

– Официальный сайт Pinco Casino.5445

Пинко Казино – Официальный сайт Pinco Casino ▶️ ИГРАТЬ Содержимое Преимущества игры на официальном сайте Pinco Casino Как начать играть на официальном сайте Pinco Casino Конечно, безопасность и конфиденциальность игроков В наше время интернета и онлайн-игр, казино стали одним из самых популярных развлечений для многих людей. И среди них есть …

Read More »

1Win Azerbaijan – İdman Mərcləri və Casino saytı.3459

1Win Azerbaijan – İdman Mərcləri və Casino saytı ▶️ OYNA Содержимое 1Win Azerbaijan haqqında məlumatlar 1Win Azerbaijanın məqsədi Idman mərcələrindən istifadə edən məsləhətlər 1Win Casino saytı haqqında məlumatlar Idman mərcələrindən və casino saytı ilə bağlı məlumatlar Idman mərcəzlərindən məlumatlar Casino saytı ilə bağlı məlumatlar 1Win Azerbaycan – bu idman mərcəzi …

Read More »

Plinko – Online Casino Spel.921

Plinko – Online Casino Spel ▶️ SPELEN Содержимое Welkom bij het spel Winnen met de Plinko-regels Spelen met de online casino-opties Als je op zoek bent naar een online casino spel dat een beetje extra heeft, dan is Plinko zeker een spel waard om te proberen. Dit klassieke spel is …

Read More »

Glory Casino Bangladesh Official Website.513

Glory Casino Bangladesh Official Website ▶️ PLAY Содержимое Why Choose Glory Casino Bangladesh? Glory Casino APK and App Features and Benefits of Playing at Glory Casino Bangladesh How to Register and Start Playing at Glory Casino Bangladesh Are you looking for a reliable and secure online casino experience in Bangladesh? …

Read More »

– Официальный сайт Pinco Casino.885

Пинко Казино – Официальный сайт Pinco Casino ▶️ ИГРАТЬ Содержимое Преимущества игры на официальном сайте Pinco Casino Виды игр и слотов на официальном сайте Pinco Casino Бонусы и акции на официальном сайте Pinco Casino Бонусы для новых игроков Акции для постоянных игроков Как начать играть на официальном сайте Pinco Casino …

Read More »

– Официальный сайт Pinco Casino.1335

Пинко Казино – Официальный сайт Pinco Casino ▶️ ИГРАТЬ Содержимое Преимущества игры на официальном сайте Pinco Casino Как начать играть на официальном сайте Pinco Casino Шаг 1: Регистрация Шаг 2: Выбор игры Конечно, безопасность и конфиденциальность игроков В современном мире игроки казино имеют доступ к огромному количеству онлайн-казино, но не …

Read More »

Glory Casino (3322)

Glory Casino Bangladesh ▶️ PLAY Содержимое What is Glory Casino Online? Why Choose Glory Casino Bangladesh? How to Get Started with Glory Casino Bangladesh? Glory Casino Login: A Quick Guide Understanding the Online Casino Experience The Benefits of Online Casinos Glory Casino is a popular online casino that has gained …

Read More »

Glory Casino (1880)

Glory Casino Bangladesh Official Website ▶️ PLAY Содержимое About Glory Casino Glory Casino APK and Online Version Glory Casino Bangladesh: A Popular Choice Features of the Official Website Secure and Reliable How to Register and Start Playing at Glory Casino Bangladesh Are you looking for a reliable and secure online …

Read More »