Skip to content

Commit

Permalink
extra security
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
mitsuhiko committed May 4, 2008
1 parent 76c280b commit b5f522c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions jinja2/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
:copyright: Copyright 2008 by Armin Ronacher.
:license: BSD.
"""
from types import FunctionType, MethodType
from types import FunctionType, MethodType, TracebackType, CodeType, \
FrameType, GeneratorType
from jinja2.runtime import Undefined
from jinja2.environment import Environment

Expand Down Expand Up @@ -66,6 +67,12 @@ def is_safe_attribute(self, obj, attr, value):
if isinstance(obj, MethodType):
return attr not in UNSAFE_FUNCTION_ATTRIBUTES and \
attr not in UNSAFE_METHOD_ATTRIBUTES
if isinstance(obj, type):
return attr != 'mro'
if isinstance(obj, (CodeType, TracebackType, FrameType)):
return False
if isinstance(obj, GeneratorType):
return attr != 'gi_frame'
return True

def is_safe_callable(self, obj):
Expand Down Expand Up @@ -96,7 +103,7 @@ def subscribe(self, obj, argument):
' unsafe.' % (
argument,
obj.__class__.__name__
))
), name=argument)
return self.undefined(obj=obj, name=argument)

def call(__self, __obj, *args, **kwargs):
Expand Down

0 comments on commit b5f522c

Please sign in to comment.