blob: 2b65f9c49b5ecfcc3c7d6b7f73c1fc3af6bd03bb [file] [log] [blame]
Armin Ronacher5cdc1ac2008-05-07 12:17:18 +02001Sandbox
2=======
3
4The Jinja2 sandbox can be used to evaluate untrusted code. Access to unsafe
5attributes and methods is prohibited.
6
7Assuming `env` is a :class:`SandboxedEnvironment` in the default configuration
8the following piece of code shows how it works:
9
10>>> env.from_string("{{ func.func_code }}").render(func=lambda:None)
11u''
12>>> env.from_string("{{ func.func_code.do_something }}").render(func=lambda:None)
13Traceback (most recent call last):
14 ...
15SecurityError: access to attribute 'func_code' of 'function' object is unsafe.
16
17
18.. module:: jinja2.sandbox
19
20.. autoclass:: SandboxedEnvironment([options])
21 :members: is_safe_attribute, is_safe_callable
22
Armin Ronacher522cad62008-05-17 13:55:37 +020023.. autoclass:: ImmutableSandboxedEnvironment([options])
24
Armin Ronacher5cdc1ac2008-05-07 12:17:18 +020025.. autoexception:: SecurityError
26
27.. autofunction:: unsafe
28
29.. autofunction:: is_internal_attribute
Armin Ronacher522cad62008-05-17 13:55:37 +020030
31.. autofunction:: modifies_builtin_mutable