6fca8f
diff --git a/jinja2/bccache.py b/jinja2/bccache.py
6fca8f
index 09ff845..c31a905 100644
6fca8f
--- a/jinja2/bccache.py
6fca8f
+++ b/jinja2/bccache.py
6fca8f
@@ -16,6 +16,7 @@
6fca8f
 """
6fca8f
 from os import path, listdir
6fca8f
 import os
6fca8f
+import stat
6fca8f
 import sys
6fca8f
 import errno
6fca8f
 import marshal
6fca8f
@@ -230,6 +231,14 @@ class FileSystemBytecodeCache(BytecodeCache):
6fca8f
             if e.errno != errno.EEXIST:
6fca8f
                 raise
6fca8f
 
6fca8f
+        if os.lstat(actual_dir).st_uid != os.getuid():
6fca8f
+            raise RuntimeError('Someone else owns temp directory with your '
6fca8f
+                               'uid. You need to explicitly provide another.')
6fca8f
+
6fca8f
+        if stat.S_IMODE(os.lstat(actual_dir).st_mode) != 448:
6fca8f
+            raise RuntimeError('Bad permission flags on temp directory, '
6fca8f
+                               'shoud be 0700. You need to fix this.')
6fca8f
+
6fca8f
         return actual_dir
6fca8f
 
6fca8f
     def _get_cache_filename(self, bucket):