Skip to content
Myr

Fix CVE-2014-0012

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

Add checks for the per-user temporary directory. If it already exists, make sure that it: - is owned by the current user - is directory - has expected permissions This commit also fixes: - nt -> n typo pointed out in the review of acb672b - replace 448 with stat.S_IRWXU when setting directory mode

authored by Tomas Hoger · committed by Armin Ronacher · parent 5662125 · Browse files · 1 file+10 added−3 removed
This commit

State

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

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

1 file+10 added−3 removed

  • other:+10 added−3 removed

1 file+10 added−3 removed

modified:jinja2/bccache.py+10 added-3 removed
14 unmodified lines
15 :license: BSD.16"""17from os import path, listdir18import os19import stat20import sys21import errno22import marshal23import tempfile
191 unmodified lines
215 tmpdir = tempfile.gettempdir()216217 # On windows the temporary directory is used specific unless218 # explicitly forced otherwise. We can just use that.218 if os.name == 'n':219 if os.name == 'nt':220 return tmpdir221 if not hasattr(os, 'getuid'):222 raise RuntimeError('Cannot determine safe temp directory. You '223 'need to explicitly provide one.')224225 dirname = '_jinja2-cache-%d' % os.getuid()226 actual_dir = os.path.join(tmpdir, dirname)227 try:227 # 448 == 0700228 os.mkdir(actual_dir, 448)228 os.mkdir(actual_dir, stat.S_IRWXU) # 0o700229 except OSError as e:230 if e.errno != errno.EEXIST:231 raise232233 actual_dir_stat = os.lstat(actual_dir)234 if actual_dir_stat.st_uid != os.getuid() \235 or not stat.S_ISDIR(actual_dir_stat.st_mode) \236 or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:237 raise RuntimeError('Temporary directory \'%s\' has an incorrect '238 'owner, permissions, or type.' % actual_dir)239240 return actual_dir241242 def _get_cache_filename(self, bucket):243 return path.join(self.directory, self.pattern % bucket.key)
101 unmodified lines