Bug 1868137 - CVE-2019-20916 python-pip-epel: python-pip: directory traversal in _download_http_url() function in src/pip/_internal/download.py [epel-7]
Summary: CVE-2019-20916 python-pip-epel: python-pip: directory traversal in _download_...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora EPEL
Classification: Fedora
Component: python-pip-epel
Version: epel7
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
Assignee: Tomas Orsava
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: CVE-2019-20916
TreeView+ depends on / blocked
 
Reported: 2020-08-11 19:25 UTC by Pedro Sampaio
Modified: 2020-09-18 15:30 UTC (History)
3 users (show)

Fixed In Version: python-pip-epel-8.1.2-14.el7
Clone Of:
Environment:
Last Closed: 2020-09-18 15:30:36 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Pedro Sampaio 2020-08-11 19:25:33 UTC
This is an automatically created tracking bug!  It was created to ensure
that one or more security vulnerabilities are fixed in affected versions
of epel-7.

For comments that are specific to the vulnerability please use bugs filed
against the "Security Response" product referenced in the "Blocks" field.

For more information see:
http://fedoraproject.org/wiki/Security/TrackingBugs

When submitting as an update, use the fedpkg template provided in the next
comment(s).  This will include the bug IDs of this tracking bug as well as
the relevant top-level CVE bugs.

Please also mention the CVE IDs being fixed in the RPM changelog and the
fedpkg commit message.

Comment 1 Pedro Sampaio 2020-08-11 19:25:35 UTC
Use the following template to for the 'fedpkg update' request to submit an
update for this issue as it contains the top-level parent bug(s) as well as
this tracking bug.  This will ensure that all associated bugs get updated
when new packages are pushed to stable.

=====

# bugfix, security, enhancement, newpackage (required)
type=security

# low, medium, high, urgent (required)
severity=medium

# testing, stable
request=testing

# Bug numbers: 1234,9876
bugs=1868135,1868137

# Description of your update
notes=Security fix for [PUT CVEs HERE]

# Enable request automation based on the stable/unstable karma thresholds
autokarma=True
stable_karma=3
unstable_karma=-3

# Automatically close bugs when this marked as stable
close_bugs=True

# Suggest that users restart after update
suggest_reboot=False

======

Additionally, you may opt to use the bodhi web interface to submit updates:

https://bodhi.fedoraproject.org/updates/new

Comment 2 Tomas Orsava 2020-09-02 15:23:56 UTC
Pull Request: https://src.fedoraproject.org/rpms/python-pip-epel/pull-request/2



Using reproducer from: https://bugzilla.redhat.com/show_bug.cgi?id=1868016#c2


OLD:


$ rpm -qa python2-pip
python2-pip-8.1.2-12.el7.noarch

$ pip2 install http://0.0.0.0:8765/
Collecting http://0.0.0.0:8765/
/
127.0.0.1 - - [02/Sep/2020 11:09:31] "GET / HTTP/1.1" 200 -
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 307, in run
    requirement_set.prepare_files(finder)
  File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 370, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 587, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/lib/python2.7/site-packages/pip/download.py", line 810, in unpack_url
    hashes=hashes
  File "/usr/lib/python2.7/site-packages/pip/download.py", line 649, in unpack_http_url
    hashes)
  File "/usr/lib/python2.7/site-packages/pip/download.py", line 870, in _download_http_url
    with open(file_path, 'wb') as content_file:
IOError: [Errno 21] Is a directory: '/tmp/pip-Yy352C-unpack/../../../../../../../../../../tmp/'
You are using pip version 8.1.2, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


$ rpm -qa python34-pip
python34-pip-8.1.2-12.el7.noarch

$ pip3.4 install http://0.0.0.0:8765/
Collecting http://0.0.0.0:8765/
/
127.0.0.1 - - [02/Sep/2020 11:10:41] "GET / HTTP/1.1" 200 -
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3.4/site-packages/pip/commands/install.py", line 307, in run
    requirement_set.prepare_files(finder)
  File "/usr/lib/python3.4/site-packages/pip/req/req_set.py", line 370, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3.4/site-packages/pip/req/req_set.py", line 587, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/lib/python3.4/site-packages/pip/download.py", line 810, in unpack_url
    hashes=hashes
  File "/usr/lib/python3.4/site-packages/pip/download.py", line 649, in unpack_http_url
    hashes)
  File "/usr/lib/python3.4/site-packages/pip/download.py", line 870, in _download_http_url
    with open(file_path, 'wb') as content_file:
IsADirectoryError: [Errno 21] Is a directory: '/tmp/pip-u8ra9r3n-unpack/../../../../../../../../../../tmp/'
You are using pip version 8.1.2, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.



NEW:

$ rpm -qa python2-pip
python2-pip-8.1.2-14.el7.noarch

$ pip2 install http://0.0.0.0:8765/
Collecting http://0.0.0.0:8765/
/
127.0.0.1 - - [02/Sep/2020 11:13:37] "GET / HTTP/1.1" 200 -
  Downloading http://0.0.0.0:8765/
  Cannot unpack file /tmp/pip-BFdOgn-unpack/0.0.0.0:8765 (downloaded from /tmp/pip-8UdO4R-build, content-type: ); cannot detect archive format
Cannot determine archive format of /tmp/pip-8UdO4R-build
You are using pip version 8.1.2, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


$ rpm -qa python34-pip
python34-pip-8.1.2-14.el7.noarch

$ pip3.4 install http://0.0.0.0:8765/
Collecting http://0.0.0.0:8765/
/
127.0.0.1 - - [02/Sep/2020 11:14:25] "GET / HTTP/1.1" 200 -
  Downloading http://0.0.0.0:8765/
  Cannot unpack file /tmp/pip-nk4fa1i8-unpack/0.0.0.0:8765 (downloaded from /tmp/pip-4uhk8st7-build, content-type: ); cannot detect archive format
Cannot determine archive format of /tmp/pip-4uhk8st7-build
You are using pip version 8.1.2, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@ci-vm-10-0-139-142 ~]#



Test suite:

$ py.test -k unit/test_download.py -v

[..]
tests/unit/test_download.py::test_sanitize_content_filename[dir/file-file] PASSED
tests/unit/test_download.py::test_sanitize_content_filename[../file-file] PASSED
tests/unit/test_download.py::test_sanitize_content_filename[../../file-file] PASSED
tests/unit/test_download.py::test_sanitize_content_filename[../-] PASSED
tests/unit/test_download.py::test_sanitize_content_filename[../..-..] PASSED
tests/unit/test_download.py::test_sanitize_content_filename[/-] PASSED
tests/unit/test_download.py::test_sanitize_content_filename__platform_dependent[dir\file-file-dir\file] PASSED
tests/unit/test_download.py::test_sanitize_content_filename__platform_dependent[..\file-file-..\file] PASSED
tests/unit/test_download.py::test_sanitize_content_filename__platform_dependent[..\..\file-file-..\..\file] PASSED
tests/unit/test_download.py::test_sanitize_content_filename__platform_dependent[..\--..\] PASSED
tests/unit/test_download.py::test_sanitize_content_filename__platform_dependent[..\..-..-..\..] PASSED
tests/unit/test_download.py::test_sanitize_content_filename__platform_dependent[\--\] PASSED
tests/unit/test_download.py::test_parse_content_disposition[attachment;filename="../file"-df-file] PASSED
tests/unit/test_download.py::test_download_http_url__no_directory_traversal PASSED
[..]
============================================================= 626 tests deselected by '-kunit/test_download.py' ==============================================================
====================================================== 33 passed, 3 skipped, 626 deselected, 1 warnings in 1.13 seconds ======================================================



OLD fails & NEW succeeds & test suite succeeds => VERIFIED.

Comment 3 Fedora Update System 2020-09-03 06:27:21 UTC
FEDORA-EPEL-2020-49c5f31e92 has been submitted as an update to Fedora EPEL 7. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2020-49c5f31e92

Comment 4 Fedora Update System 2020-09-03 16:51:20 UTC
FEDORA-EPEL-2020-49c5f31e92 has been pushed to the Fedora EPEL 7 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2020-49c5f31e92

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 5 Fedora Update System 2020-09-18 15:30:36 UTC
FEDORA-EPEL-2020-49c5f31e92 has been pushed to the Fedora EPEL 7 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.