Skip to content
Myr

Fixed a security issue with temporary files on the filesystem cache on UNIX.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 701e9ad · Browse files · 2 files+32 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+32 added−2 removed

  • other:+32 added−2 removed

2 files+32 added−2 removed

modified:jinja2/bccache.py+27 added-2 removed
13 unmodified lines
14 :copyright: (c) 2010 by the Jinja Team.15 :license: BSD.16"""17from os import path, listdir18import os19import sys20import errno21import marshal22import tempfile23import fnmatch24from hashlib import sha1
165 unmodified lines
190 """A bytecode cache that stores bytecode on the filesystem. It accepts191 two arguments: The directory where the cache items are stored and a192 pattern string that is used to build the filename.193192 If no directory is specified the system temporary items folder is used.194 If no directory is specified a default cache directory is selected. On195 Windows the user's temp directory is used, on UNIX systems a directory196 is created for the user in the system temp directory.197198 The pattern can be used to have multiple separate caches operate on the199 same directory. The default pattern is ``'__jinja2_%s.cache'``. ``%s``200 is replaced with the cache key.
4 unmodified lines
205 """206207 def __init__(self, directory=None, pattern='__jinja2_%s.cache'):208 if directory is None:205 directory = tempfile.gettempdir()209 directory = self._get_default_cache_dir()210 self.directory = directory211 self.pattern = pattern212213 def _get_default_cache_dir(self):214 tmpdir = tempfile.gettempdir()215216 # On windows the temporary directory is used specific unless217 # explicitly forced otherwise. We can just use that.218 if os.name == 'n':219 return tmpdir220 if not hasattr(os, 'getuid'):221 raise RuntimeError('Cannot determine safe temp directory. You '222 'need to explicitly provide one.')223224 dirname = '_jinja2-cache-%d' % os.getuid()225 actual_dir = os.path.join(tmpdir, dirname)226 try:227 os.mkdir(actual_dir, 0700)228 except OSError as e:229 if e.errno != errno.EEXIST:230 raise231232 return actual_dir233234 def _get_cache_filename(self, bucket):235 return path.join(self.directory, self.pattern % bucket.key)236237 def load_bytecode(self, bucket):
99 unmodified lines
modified:CHANGES+5 added
5 unmodified lines
6(bugfix release, release date to be decided)78- Prefix loader was not forwarding the locals properly to9 inner loaders. This is now fixed.10- Security issue: Changed the default folder for the filesystem cache to be11 user specific and read and write protected on UNIX systems. See `Debian bug12 734747`_ for more information.1314.. _Debian bug 734747: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=7347471516Version 2.7.117-------------18(bugfix release, released on August 7th 2013)19
308 unmodified lines