aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-06-29 11:03:48 -0400
committerJason R. Coombs <jaraco@jaraco.com>2013-06-29 11:03:48 -0400
commit7ece8c26352879f5d4486e329cec5d35d10d3ed6 (patch)
tree58ca555b23c0131e6f343964b947b1d4d688935d /pkg_resources.py
parent72495bf98af2c556721126fceff8a5e7d8283a91 (diff)
parentb99749aa06cc7c235cb456a81ad50187d701fc4c (diff)
downloadexternal_python_setuptools-7ece8c26352879f5d4486e329cec5d35d10d3ed6.tar.gz
external_python_setuptools-7ece8c26352879f5d4486e329cec5d35d10d3ed6.tar.bz2
external_python_setuptools-7ece8c26352879f5d4486e329cec5d35d10d3ed6.zip
Merge with 0.7.5
Diffstat (limited to 'pkg_resources.py')
-rw-r--r--pkg_resources.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg_resources.py b/pkg_resources.py
index 3dc85525..a8ead572 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -14,6 +14,8 @@ method.
"""
import sys, os, time, re, imp, types, zipfile, zipimport
+import warnings
+import stat
try:
from urlparse import urlparse, urlunparse
except ImportError:
@@ -1016,6 +1018,7 @@ variable to point to an accessible directory.
extract, as it tracks the generated names for possible cleanup later.
"""
extract_path = self.extraction_path or get_default_cache()
+ self._warn_unsafe_extraction(extract_path)
target_path = os.path.join(extract_path, archive_name+'-tmp', *names)
try:
_bypass_ensure_directory(target_path)
@@ -1025,6 +1028,29 @@ variable to point to an accessible directory.
self.cached_files[target_path] = 1
return target_path
+ @staticmethod
+ def warn_unsafe_extraction_path(path):
+ """
+ If the default extraction path is overridden and set to an insecure
+ location, such as /tmp, it opens up an opportunity for an attacker to
+ replace an extracted file with an unauthorized payload. Warn the user
+ if a known insecure location is used.
+
+ See Distribute #375 for more details.
+ """
+ if os.name == 'nt' and not path.startswith(os.environ['windir']):
+ # On Windows, permissions are generally restrictive by default
+ # and temp directories are not writable by other users, so
+ # bypass the warning.
+ return
+ mode = os.stat(path).st_mode
+ if mode & stat.S_IWOTH or mode & stat.S_IWGRP:
+ msg = ("%s is writable by group/others and vulnerable to attack "
+ "when "
+ "used with get_resource_filename. Consider a more secure "
+ "location (set with .set_extraction_path or the "
+ "PYTHON_EGG_CACHE environment variable)." % path)
+ warnings.warn(msg, UserWarning)