Optimize template sandbox for Home Assistant (#39731)

pull/39742/head
J. Nick Koston 2020-09-07 02:17:41 -05:00 committed by GitHub
parent 12cc158b64
commit 2e6cd4f12b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -1122,7 +1122,13 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
def is_safe_attribute(self, obj, attr, value):
"""Test if attribute is safe."""
return isinstance(obj, Namespace) or super().is_safe_attribute(obj, attr, value)
if isinstance(obj, Namespace):
return True
if isinstance(obj, (AllStates, DomainStates, TemplateState)):
return not attr.startswith("_")
return super().is_safe_attribute(obj, attr, value)
def compile(self, source, name=None, filename=None, raw=False, defer_init=False):
"""Compile the template."""