unique_toolkit 2026.46.0.dev9__py3-none-any.whl → 2026.46.0.dev10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unique_toolkit/_common/utils/jinja/sandbox.py +40 -2
- {unique_toolkit-2026.46.0.dev9.dist-info → unique_toolkit-2026.46.0.dev10.dist-info}/METADATA +1 -1
- {unique_toolkit-2026.46.0.dev9.dist-info → unique_toolkit-2026.46.0.dev10.dist-info}/RECORD +4 -4
- {unique_toolkit-2026.46.0.dev9.dist-info → unique_toolkit-2026.46.0.dev10.dist-info}/WHEEL +0 -0
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
from functools import cache
|
|
2
2
|
|
|
3
|
-
from jinja2 import Template
|
|
4
|
-
from jinja2.
|
|
3
|
+
from jinja2 import Template, TemplateError, nodes
|
|
4
|
+
from jinja2.exceptions import SecurityError
|
|
5
|
+
from jinja2.sandbox import (
|
|
6
|
+
UNSAFE_ASYNC_GENERATOR_ATTRIBUTES,
|
|
7
|
+
UNSAFE_COROUTINE_ATTRIBUTES,
|
|
8
|
+
UNSAFE_FUNCTION_ATTRIBUTES,
|
|
9
|
+
UNSAFE_GENERATOR_ATTRIBUTES,
|
|
10
|
+
UNSAFE_METHOD_ATTRIBUTES,
|
|
11
|
+
SandboxedEnvironment,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = ["TemplateError", "sandboxed_template", "validate_sandboxed_template"]
|
|
15
|
+
|
|
16
|
+
_UNSAFE_STATIC_ATTRIBUTES: frozenset[str] = frozenset(
|
|
17
|
+
{
|
|
18
|
+
"mro",
|
|
19
|
+
*UNSAFE_FUNCTION_ATTRIBUTES,
|
|
20
|
+
*UNSAFE_METHOD_ATTRIBUTES,
|
|
21
|
+
*UNSAFE_GENERATOR_ATTRIBUTES,
|
|
22
|
+
*UNSAFE_COROUTINE_ATTRIBUTES,
|
|
23
|
+
*UNSAFE_ASYNC_GENERATOR_ATTRIBUTES,
|
|
24
|
+
}
|
|
25
|
+
)
|
|
5
26
|
|
|
6
27
|
|
|
7
28
|
@cache
|
|
@@ -16,3 +37,20 @@ def sandboxed_template(source: str, *, lstrip_blocks: bool = False) -> Template:
|
|
|
16
37
|
sandbox rejects raises ``jinja2.exceptions.SecurityError``.
|
|
17
38
|
"""
|
|
18
39
|
return _sandboxed_environment(lstrip_blocks=lstrip_blocks).from_string(source)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def validate_sandboxed_template(source: str, *, lstrip_blocks: bool = False) -> str:
|
|
43
|
+
"""Validate that ``source`` compiles and accesses no sandbox-forbidden attributes.
|
|
44
|
+
|
|
45
|
+
Raises ``jinja2.TemplateSyntaxError`` on malformed syntax (and top-level
|
|
46
|
+
unknown filters/tests; filters inside conditionals are resolved by Jinja at
|
|
47
|
+
render time) and ``jinja2.exceptions.SecurityError`` on static dot-access to
|
|
48
|
+
private or internal Python attributes.
|
|
49
|
+
"""
|
|
50
|
+
env = _sandboxed_environment(lstrip_blocks=lstrip_blocks)
|
|
51
|
+
ast = env.parse(source)
|
|
52
|
+
for node in ast.find_all(nodes.Getattr):
|
|
53
|
+
if node.attr.startswith("_") or node.attr in _UNSAFE_STATIC_ATTRIBUTES:
|
|
54
|
+
raise SecurityError("access to private or internal attribute is unsafe.")
|
|
55
|
+
env.from_string(source)
|
|
56
|
+
return source
|
{unique_toolkit-2026.46.0.dev9.dist-info → unique_toolkit-2026.46.0.dev10.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: unique-toolkit
|
|
3
|
-
Version: 2026.46.0.
|
|
3
|
+
Version: 2026.46.0.dev10
|
|
4
4
|
Summary:
|
|
5
5
|
Author: Cedric Klinkert, Martin Fadler, Sadique Sheik, Fabian Schläpfer, Pascal Hauri, Ejiroghene Oki-Peter, Rami Azouz, Ricardo Visini, Sanzio Monti
|
|
6
6
|
Author-email: Cedric Klinkert <cedric.klinkert@unique.ch>, Martin Fadler <martin.fadler@unique.ch>, Sadique Sheik <sadique@unique.ch>, Fabian Schläpfer <fabian@unique.ch>, Pascal Hauri <pascal@unique.ch>, Ejiroghene Oki-Peter <oki-peter.ejiroghene@unique.ai>, Rami Azouz <rami.ext@unique.ch>, Ricardo Visini <ricardo.visini@unique.ch>, Sanzio Monti <sanzio.monti@unique.ai>
|
|
@@ -75,7 +75,7 @@ unique_toolkit/_common/utils/files.py,sha256=cPJU3Y5DlAbdakPaF1vICOCOujMHESrP4b3
|
|
|
75
75
|
unique_toolkit/_common/utils/image/encode.py,sha256=IJhtTcIT_azhiDsPp15oYs2LPze2l-sGlZrJASHrDVI,658
|
|
76
76
|
unique_toolkit/_common/utils/jinja/helpers.py,sha256=UQWj0hFMtnuUFYDJ8NKbEblvYE8DrWX1o7fKQU3H9IQ,262
|
|
77
77
|
unique_toolkit/_common/utils/jinja/render.py,sha256=D48hVbDcaGz_O01Xgawd3fBgbFIiZkThShZyjN96nBo,537
|
|
78
|
-
unique_toolkit/_common/utils/jinja/sandbox.py,sha256=
|
|
78
|
+
unique_toolkit/_common/utils/jinja/sandbox.py,sha256=b39fvrHyvFiTK1ft8mIlPOvaiP7JktLLpzLgPK27hbA,2045
|
|
79
79
|
unique_toolkit/_common/utils/jinja/schema.py,sha256=uyGGN1uvcGTBBujs8KUrnMMND73MNC5YGJkSETVyUCo,2007
|
|
80
80
|
unique_toolkit/_common/utils/jinja/utils.py,sha256=0SrwN6qfLlRJrl38HG7qsMr5-DwpABNnM9LpqpMgwUA,2814
|
|
81
81
|
unique_toolkit/_common/utils/structured_output/__init__.py,sha256=nm_orZrlCXL0FPLUg0Jv6Ty1flXPkCgZ9caAWaS8rz8,38
|
|
@@ -434,6 +434,6 @@ unique_toolkit/short_term_memory/service.py,sha256=2JMBEBn6GoyK-a0xvdcWpPft-3C74
|
|
|
434
434
|
unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
435
435
|
unique_toolkit/smart_rules/compile.py,sha256=vRe0aMJWuVIK-VsqomgxQImzke7MDmwgSxxJfYCa7zw,1386
|
|
436
436
|
unique_toolkit/test_utilities/events.py,sha256=FLrhMh0A_mQutAUjoD0FdMcVQ4Gq31r35OVGzRjvLro,6760
|
|
437
|
-
unique_toolkit-2026.46.0.
|
|
438
|
-
unique_toolkit-2026.46.0.
|
|
439
|
-
unique_toolkit-2026.46.0.
|
|
437
|
+
unique_toolkit-2026.46.0.dev10.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
438
|
+
unique_toolkit-2026.46.0.dev10.dist-info/METADATA,sha256=HAm3qjU5XV6WbIQPBJ8eYK-El5mJrvFmnLVR8lB8u-k,7822
|
|
439
|
+
unique_toolkit-2026.46.0.dev10.dist-info/RECORD,,
|
|
File without changes
|