#108 F30 master sync
Merged 4 years ago by churchyard. Opened 5 years ago by churchyard.

@@ -1,46 +0,0 @@ 

- diff -up Python-3.2.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest Python-3.2.2/Lib/unittest/case.py

- --- Python-3.2.2/Lib/unittest/case.py.add-rpmbuild-hooks-to-unittest	2011-09-03 12:16:44.000000000 -0400

- +++ Python-3.2.2/Lib/unittest/case.py	2011-09-09 06:35:16.365568382 -0400

- @@ -3,6 +3,7 @@

-  import sys

-  import functools

-  import difflib

- +import os

-  import logging

-  import pprint

-  import re

- @@ -101,5 +102,21 @@ def expectedFailure(func):

-          raise self.test_case.failureException(msg)

-  

- +# Non-standard/downstream-only hooks for handling issues with specific test

- +# cases:

- +

- +def _skipInRpmBuild(reason):

- +    """

- +    Non-standard/downstream-only decorator for marking a specific unit test

- +    to be skipped when run within the %check of an rpmbuild.

- +

- +    Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within

- +    the environment, and has no effect otherwise.

- +    """

- +    if 'WITHIN_PYTHON_RPM_BUILD' in os.environ:

- +        return skip(reason)

- +    else:

- +        return _id

- +

-  class _AssertRaisesBaseContext(_BaseTestCaseContext):

-  

-      def __init__(self, expected, test_case, expected_regex=None):

- diff -up Python-3.2.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest Python-3.2.2/Lib/unittest/__init__.py

- --- Python-3.2.2/Lib/unittest/__init__.py.add-rpmbuild-hooks-to-unittest	2011-09-03 12:16:44.000000000 -0400

- +++ Python-3.2.2/Lib/unittest/__init__.py	2011-09-09 06:35:16.366568382 -0400

- @@ -57,7 +57,8 @@ __unittest = True

-  

-  from .result import TestResult

-  from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,

- -                   skipUnless, expectedFailure)

- +                   skipUnless, expectedFailure,

- +                   _skipInRpmBuild)

-  from .suite import BaseTestSuite, TestSuite

-  from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames,

-                       findTestCases)

@@ -1,11 +0,0 @@ 

- diff -up cpython-59223da36dec/Lib/test/test_posix.py.disable-test_fs_holes-in-rpm-build cpython-59223da36dec/Lib/test/test_posix.py

- --- cpython-59223da36dec/Lib/test/test_posix.py.disable-test_fs_holes-in-rpm-build	2012-08-07 17:15:59.000000000 -0400

- +++ cpython-59223da36dec/Lib/test/test_posix.py	2012-08-07 17:16:53.528330330 -0400

- @@ -973,6 +973,7 @@ class PosixTester(unittest.TestCase):

-          posix.RTLD_GLOBAL

-          posix.RTLD_LOCAL

-  

- +    @unittest._skipInRpmBuild('running kernel may not match kernel in chroot')

-      @unittest.skipUnless(hasattr(os, 'SEEK_HOLE'),

-                           "test needs an OS that reports file holes")

-      def test_fs_holes(self):

@@ -0,0 +1,42 @@ 

+ diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py

+ index 0faf2bb..d0365ec 100644

+ --- a/Lib/test/test_urlparse.py

+ +++ b/Lib/test/test_urlparse.py

+ @@ -1011,6 +1011,12 @@ class UrlParseTestCase(unittest.TestCase):

+          self.assertIn('\u2100', denorm_chars)

+          self.assertIn('\uFF03', denorm_chars)

+  

+ +        # bpo-36742: Verify port separators are ignored when they

+ +        # existed prior to decomposition

+ +        urllib.parse.urlsplit('http://\u30d5\u309a:80')

+ +        with self.assertRaises(ValueError):

+ +            urllib.parse.urlsplit('http://\u30d5\u309a\ufe1380')

+ +

+          for scheme in ["http", "https", "ftp"]:

+              for c in denorm_chars:

+                  url = "{}://netloc{}false.netloc/path".format(scheme, c)

+ diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py

+ index 8b6c9b1..e2f7b69 100644

+ --- a/Lib/urllib/parse.py

+ +++ b/Lib/urllib/parse.py

+ @@ -402,13 +402,16 @@ def _checknetloc(netloc):

+      # looking for characters like \u2100 that expand to 'a/c'

+      # IDNA uses NFKC equivalence, so normalize for this check

+      import unicodedata

+ -    netloc2 = unicodedata.normalize('NFKC', netloc)

+ -    if netloc == netloc2:

+ +    n = netloc.rpartition('@')[2] # ignore anything to the left of '@'

+ +    n = n.replace(':', '')        # ignore characters already included

+ +    n = n.replace('#', '')        # but not the surrounding text

+ +    n = n.replace('?', '')

+ +    netloc2 = unicodedata.normalize('NFKC', n)

+ +    if n == netloc2:

+          return

+ -    _, _, netloc = netloc.rpartition('@') # anything to the left of '@' is okay

+      for c in '/?#@:':

+          if c in netloc2:

+ -            raise ValueError("netloc '" + netloc2 + "' contains invalid " +

+ +            raise ValueError("netloc '" + netloc + "' contains invalid " +

+                               "characters under NFKC normalization")

+  

+  def urlsplit(url, scheme='', allow_fragments=True):

@@ -0,0 +1,150 @@ 

+ From 7e200e0763f5b71c199aaf98bd5588f291585619 Mon Sep 17 00:00:00 2001

+ From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>

+ Date: Tue, 7 May 2019 17:28:47 +0200

+ Subject: [PATCH] bpo-30458: Disallow control chars in http URLs. (GH-12755)

+  (GH-13154)

+ MIME-Version: 1.0

+ Content-Type: text/plain; charset=UTF-8

+ Content-Transfer-Encoding: 8bit

+ 

+ Disallow control chars in http URLs in urllib.urlopen.  This addresses a potential security problem for applications that do not sanity check their URLs where http request headers could be injected.

+ 

+ Disable https related urllib tests on a build without ssl (GH-13032)

+ These tests require an SSL enabled build. Skip these tests when python is built without SSL to fix test failures.

+ 

+ Use http.client.InvalidURL instead of ValueError as the new error case's exception. (GH-13044)

+ 

+ Backport Co-Authored-By: Miro Hrončok <miro@hroncok.cz>

+ ---

+  Lib/http/client.py                            | 15 ++++++

+  Lib/test/test_urllib.py                       | 53 +++++++++++++++++++

+  Lib/test/test_xmlrpc.py                       |  7 ++-

+  .../2019-04-10-08-53-30.bpo-30458.51E-DA.rst  |  1 +

+  4 files changed, 75 insertions(+), 1 deletion(-)

+  create mode 100644 Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst

+ 

+ diff --git a/Lib/http/client.py b/Lib/http/client.py

+ index 1de151c38e..2afd452fe3 100644

+ --- a/Lib/http/client.py

+ +++ b/Lib/http/client.py

+ @@ -140,6 +140,16 @@ _MAXHEADERS = 100

+  _is_legal_header_name = re.compile(rb'[^:\s][^:\r\n]*').fullmatch

+  _is_illegal_header_value = re.compile(rb'\n(?![ \t])|\r(?![ \t\n])').search

+  

+ +# These characters are not allowed within HTTP URL paths.

+ +#  See https://tools.ietf.org/html/rfc3986#section-3.3 and the

+ +#  https://tools.ietf.org/html/rfc3986#appendix-A pchar definition.

+ +# Prevents CVE-2019-9740.  Includes control characters such as \r\n.

+ +# We don't restrict chars above \x7f as putrequest() limits us to ASCII.

+ +_contains_disallowed_url_pchar_re = re.compile('[\x00-\x20\x7f]')

+ +# Arguably only these _should_ allowed:

+ +#  _is_allowed_url_pchars_re = re.compile(r"^[/!$&'()*+,;=:@%a-zA-Z0-9._~-]+$")

+ +# We are more lenient for assumed real world compatibility purposes.

+ +

+  # We always set the Content-Length header for these methods because some

+  # servers will otherwise respond with a 411

+  _METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'}

+ @@ -1101,6 +1111,11 @@ class HTTPConnection:

+          self._method = method

+          if not url:

+              url = '/'

+ +        # Prevent CVE-2019-9740.

+ +        match = _contains_disallowed_url_pchar_re.search(url)

+ +        if match:

+ +            raise InvalidURL(f"URL can't contain control characters. {url!r} "

+ +                             f"(found at least {match.group()!r})")

+          request = '%s %s %s' % (method, url, self._http_vsn_str)

+  

+          # Non-ASCII characters should have been eliminated earlier

+ diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py

+ index 2ac73b58d8..7214492eca 100644

+ --- a/Lib/test/test_urllib.py

+ +++ b/Lib/test/test_urllib.py

+ @@ -329,6 +329,59 @@ class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin):

+          finally:

+              self.unfakehttp()

+  

+ +    @unittest.skipUnless(ssl, "ssl module required")

+ +    def test_url_with_control_char_rejected(self):

+ +        for char_no in list(range(0, 0x21)) + [0x7f]:

+ +            char = chr(char_no)

+ +            schemeless_url = f"//localhost:7777/test{char}/"

+ +            self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")

+ +            try:

+ +                # We explicitly test urllib.request.urlopen() instead of the top

+ +                # level 'def urlopen()' function defined in this... (quite ugly)

+ +                # test suite.  They use different url opening codepaths.  Plain

+ +                # urlopen uses FancyURLOpener which goes via a codepath that

+ +                # calls urllib.parse.quote() on the URL which makes all of the

+ +                # above attempts at injection within the url _path_ safe.

+ +                escaped_char_repr = repr(char).replace('\\', r'\\')

+ +                InvalidURL = http.client.InvalidURL

+ +                with self.assertRaisesRegex(

+ +                    InvalidURL, f"contain control.*{escaped_char_repr}"):

+ +                    urllib.request.urlopen(f"http:{schemeless_url}")

+ +                with self.assertRaisesRegex(

+ +                    InvalidURL, f"contain control.*{escaped_char_repr}"):

+ +                    urllib.request.urlopen(f"https:{schemeless_url}")

+ +                # This code path quotes the URL so there is no injection.

+ +                resp = urlopen(f"http:{schemeless_url}")

+ +                self.assertNotIn(char, resp.geturl())

+ +            finally:

+ +                self.unfakehttp()

+ +

+ +    @unittest.skipUnless(ssl, "ssl module required")

+ +    def test_url_with_newline_header_injection_rejected(self):

+ +        self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")

+ +        host = "localhost:7777?a=1 HTTP/1.1\r\nX-injected: header\r\nTEST: 123"

+ +        schemeless_url = "//" + host + ":8080/test/?test=a"

+ +        try:

+ +            # We explicitly test urllib.request.urlopen() instead of the top

+ +            # level 'def urlopen()' function defined in this... (quite ugly)

+ +            # test suite.  They use different url opening codepaths.  Plain

+ +            # urlopen uses FancyURLOpener which goes via a codepath that

+ +            # calls urllib.parse.quote() on the URL which makes all of the

+ +            # above attempts at injection within the url _path_ safe.

+ +            InvalidURL = http.client.InvalidURL

+ +            with self.assertRaisesRegex(

+ +                InvalidURL, r"contain control.*\\r.*(found at least . .)"):

+ +                urllib.request.urlopen(f"http:{schemeless_url}")

+ +            with self.assertRaisesRegex(InvalidURL, r"contain control.*\\n"):

+ +                urllib.request.urlopen(f"https:{schemeless_url}")

+ +            # This code path quotes the URL so there is no injection.

+ +            resp = urlopen(f"http:{schemeless_url}")

+ +            self.assertNotIn(' ', resp.geturl())

+ +            self.assertNotIn('\r', resp.geturl())

+ +            self.assertNotIn('\n', resp.geturl())

+ +        finally:

+ +            self.unfakehttp()

+ +

+      def test_read_0_9(self):

+          # "0.9" response accepted (but not "simple responses" without

+          # a status line)

+ diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py

+ index 32263f7f0b..0e002ec4ef 100644

+ --- a/Lib/test/test_xmlrpc.py

+ +++ b/Lib/test/test_xmlrpc.py

+ @@ -945,7 +945,12 @@ class SimpleServerTestCase(BaseServerTestCase):

+      def test_partial_post(self):

+          # Check that a partial POST doesn't make the server loop: issue #14001.

+          conn = http.client.HTTPConnection(ADDR, PORT)

+ -        conn.request('POST', '/RPC2 HTTP/1.0\r\nContent-Length: 100\r\n\r\nbye')

+ +        conn.send('POST /RPC2 HTTP/1.0\r\n'

+ +                  'Content-Length: 100\r\n\r\n'

+ +                  'bye HTTP/1.1\r\n'

+ +                  f'Host: {ADDR}:{PORT}\r\n'

+ +                  'Accept-Encoding: identity\r\n'

+ +                  'Content-Length: 0\r\n\r\n'.encode('ascii'))

+          conn.close()

+  

+      def test_context_manager(self):

+ diff --git a/Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst b/Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst

+ new file mode 100644

+ index 0000000000..ed8027fb4d

+ --- /dev/null

+ +++ b/Misc/NEWS.d/next/Security/2019-04-10-08-53-30.bpo-30458.51E-DA.rst

+ @@ -0,0 +1 @@

+ +Address CVE-2019-9740 by disallowing URL paths with embedded whitespace or control characters through into the underlying http client request.  Such potentially malicious header injection URLs now cause an http.client.InvalidURL exception to be raised.

+ -- 

+ 2.21.0

+ 

file modified
+26 -29
@@ -17,7 +17,7 @@ 

  #global prerel ...

  %global upstream_version %{general_version}%{?prerel}

  Version: %{general_version}%{?prerel:~%{prerel}}

- Release: 1%{?dist}

+ Release: 3%{?dist}

  License: Python

  

  
@@ -232,20 +232,6 @@ 

  # Downstream only: not appropriate for upstream

  Patch111: 00111-no-static-lib.patch

  

- # 00132 #

- # Add non-standard hooks to unittest for use in the "check" phase below, when

- # running selftests within the build:

- #   @unittest._skipInRpmBuild(reason)

- # for tests that hang or fail intermittently within the build environment, and:

- #   @unittest._expectedFailureInRpmBuild

- # for tests that always fail within the build environment

- #

- # The hooks only take effect if WITHIN_PYTHON_RPM_BUILD is set in the

- # environment, which we set manually in the appropriate portion of the "check"

- # phase below (and which potentially other python-* rpms could set, to reuse

- # these unittest hooks in their own "check" phases)

- Patch132: 00132-add-rpmbuild-hooks-to-unittest.patch

- 

  # 00155 #

  # Avoid allocating thunks in ctypes unless absolutely necessary, to avoid

  # generating SELinux denials on "import ctypes" and "import uuid" when
@@ -253,13 +239,6 @@ 

  # See https://bugzilla.redhat.com/show_bug.cgi?id=814391

  Patch155: 00155-avoid-ctypes-thunks.patch

  

- # 00160 #

- # Python 3.3 added os.SEEK_DATA and os.SEEK_HOLE, which may be present in the

- # header files in the build chroot, but may not be supported in the running

- # kernel, hence we disable this test in an rpm build.

- # Adding these was upstream issue http://bugs.python.org/issue10142

- # Not yet sent upstream

- Patch160: 00160-disable-test_fs_holes-in-rpm-build.patch

  

  # 00170 #

  # In debug builds, try to print repr() when a C-level assert fails in the
@@ -303,6 +282,18 @@ 

  # So we mark the command as unsupported - and the tests are skipped

  Patch316: 00316-mark-bdist_wininst-unsupported.patch

  

+ # 00320 #

+ # Fix handling of pre-normalization characters in urlsplit()

+ # This fixes a regression introduced by the fix for CVE-2019-9636

+ # Fixed upstream: https://bugs.python.org/issue36742

+ Patch320: 00320-fix-pre-normalization-chars-in-urlsplit.patch

+ 

+ # 00324 #

+ # Disallow control chars in http URLs

+ # Security fix for CVE-2019-9740 and CVE-2019-9947

+ # Fixed upstream: https://bugs.python.org/issue30458

+ Patch324: 00324-disallow-control-chars-in-http-urls.patch

+ 

  # (New patches go here ^^^)

  #

  # When adding new patches to "python" and "python3" in Fedora, EL, etc.,
@@ -583,9 +574,7 @@ 

  %patch102 -p1

  %endif

  %patch111 -p1

- %patch132 -p1

  %patch155 -p1

- %patch160 -p1

  %patch170 -p1

  %patch178 -p1

  
@@ -598,6 +587,8 @@ 

  %patch251 -p1

  %patch274 -p1

  %patch316 -p1

+ %patch320 -p1

+ %patch324 -p1

  

  

  # Remove files that should be generated by the build
@@ -924,6 +915,9 @@ 

  # See https://bugzilla.redhat.com/show_bug.cgi?id=1111275

  mv %{buildroot}%{_bindir}/2to3-%{pybasever} %{buildroot}%{_bindir}/2to3

  

+ # make man python3.Xm work https://bugzilla.redhat.com/show_bug.cgi?id=1612241

+ ln -s ./python%{pybasever}.1 %{buildroot}%{_mandir}/man1/python%{pybasever}m.1

+ 

  %if %{with flatpackage}

  # Remove stuff that would conflict with python3 package

  rm %{buildroot}%{_bindir}/python3
@@ -1000,17 +994,13 @@ 

    # Show some info, helpful for debugging test failures

    LD_LIBRARY_PATH=$ConfDir $ConfDir/python -m test.pythoninfo

  

-   # Run the upstream test suite, setting "WITHIN_PYTHON_RPM_BUILD" so that the

-   # our non-standard decorators take effect on the relevant tests:

-   #   @unittest._skipInRpmBuild(reason)

-   #   @unittest._expectedFailureInRpmBuild

+   # Run the upstream test suite

    # test_gdb skipped on armv7hl:

    #   https://bugzilla.redhat.com/show_bug.cgi?id=1196181

    # test_gdb skipped on s390x:

    #   https://bugzilla.redhat.com/show_bug.cgi?id=1678277

    # test_asyncio skipped:

    #   https://bugs.python.org/issue35998

-   WITHIN_PYTHON_RPM_BUILD= \

    LD_LIBRARY_PATH=$ConfDir $ConfDir/python -m test.regrtest \

      -wW --slowest -j0 \

      -x test_distutils \
@@ -1518,6 +1508,13 @@ 

  # ======================================================

  

  %changelog

+ * Tue May 07 2019 Charalampos Stratakis <cstratak@redhat.com> - 3.7.3-3

+ - Fix handling of pre-normalization characters in urlsplit

+ - Disallow control chars in http URLs (#1695572, #1700684, #1688169, #1706851)

+ 

+ * Wed Apr 17 2019 Patrik Kopkan <pkopkan@redhat.com> - 3.7.3-2

+ - Makes man python3.7m show python3.7 man pages (#1612241)

+ 

  * Wed Mar 27 2019 Miro Hrončok <mhroncok@redhat.com> - 3.7.3-1

  - Update to 3.7.3

  

file added
+1
@@ -0,0 +1,1 @@ 

+ 1

file added
+4
@@ -0,0 +1,4 @@ 

+ ---

+ standard-inventory-qcow2:

+   qemu:

+     m: 3G  # Amount of VM memory

no initial comment

test_concurrent_futures failed in simple-koji-ci on s390x

1 new commit added

  • Fedora CI: Provision 3 GiB of RAM
4 years ago

This can wait for the CI PRs (#109, #110).

2 new commits added

  • Security fix for CVE-2019-9740 and CVE-2019-9947
  • Fix handling of pre-normalization characters in urlsplit
4 years ago

Metadata Update from @churchyard:
- Pull-request tagged with: merge - rebase - CI

4 years ago

Metadata Update from @churchyard:
- Pull-request tagged with: backport, bugfix

4 years ago

Pull-Request has been merged by churchyard

4 years ago