-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg_resources.resource_string allows absolute paths and paths with .. - contrary to docs #1635
Comments
Note that this may have security impact… I already saw the code, which assumed that using pkg_resources guarantees that given path belongs to the package (so can be shown/safely used/…). |
I've started working on this in https://github.com/pypa/setuptools/tree/bugfix/1635-disallow-parent-paths but with that change, I notice that there are many DeprecationWarnings in the setuptools codebase itself, including this call: setuptools/pkg_resources/__init__.py Line 1936 in 82ae7bb
Due to the way the value is used, by splitting on
So in the case of '/', I suggest just changing the docs to update the expectation. |
@Mekk Would you review the PR and share your thoughts? |
|
The latest patch also disallows the leading '/'. I imagine there are hundreds of cases that will be affected by this change, so a longer deprecation period will be required.
Possibly a similar issue. There was no protection for this issue before.
I'd like to rely on the changelog to document transient aspects and allow the documentation to reflect the more permanent intentions/expectations. |
On Windows, if a
So I've updated the PR to unconditionally disallow Windows-based absolute paths. |
Hi, I am disagreed to this change because it is not preventing the security since I am able to use Second, this change is blocking to me and others, since I searched on Internet about this problem. Why
The [metadata]
; .... more set up here
long_description = file: ../README.md
long_description_content_type = text/markdown
url = https://github.com/airvzxf/sniparinject
; .... more set up here As, I mentioned above, it is easy to fix with import setuptools
with open('../README.md', 'r', encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
long_description=long_description,
) Other important reason is that it is using only to read files and put the content inside the In the file @classmethod
def _parse_file(cls, value):
"""Represents value as a string, allowing including text
from nearest files using `file:` directive.
Directive is sandboxed and won't reach anything outside
directory with setup.py.
Examples:
file: README.rst, CHANGELOG.md, src/file.txt
:param str value:
:rtype: str
"""
include_directive = 'file:'
if not isinstance(value, str):
return value
if not value.startswith(include_directive):
return value
spec = value[len(include_directive):]
filepaths = (os.path.abspath(path.strip()) for path in spec.split(','))
return '\n'.join(
cls._read_file(path)
for path in filepaths
if (cls._assert_local(path) or True)
and os.path.isfile(path)
)
@staticmethod
def _assert_local(filepath):
if not filepath.startswith(os.getcwd()):
raise DistutilsOptionError(
'`file:` directive can not access %s' % filepath)
@staticmethod
def _read_file(filepath):
with io.open(filepath, encoding='utf-8') as f:
return f.read() More information in the issue that I created: #2699 |
The https://setuptools.readthedocs.io/en/latest/pkg_resources.html ("Basic Resource Access") page claims:
Let's see:
I'd say some validation is missing.
Tested on both python2.7 and python3.6, with pkg_resources as in Ubuntu 18.04
The text was updated successfully, but these errors were encountered: