Merge branch 'psf:main' into patch-1
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by anupam-arista · committed by GitHub · parents 06d2a38, 23540c9 · Browse files · 11 files·+82 added−187 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+82 added−187 removed
- tests:+24 added−17 removed
- other:+58 added−170 removed
Provenance
- Commit
b653d80- Tree
5e3ee06- Author
anupam-arista <118899211+anupam-arista@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
06d2a38- Parent 2
23540c9
11 files changed+82 added−187 removed
modified:.github/workflows/codeql-analysis.yml+4 added-4 removed
30 unmodified lines313233343535363738394 unmodified lines444546474848495051522 unmodified lines555657585959606162635 unmodified lines69707172737330 unmodified lines
steps: - name: Checkout repository uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. fetch-depth: 24 unmodified lines if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0 uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 with: languages: "python" # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file.2 unmodified lines
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0 uses: github/codeql-action/autobuild@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
# ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl
5 unmodified lines # make bootstrap # make release
- name: Perform CodeQL Analysis uses: github/codeql-action/analyze@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0 uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0modified:.github/workflows/lint.yml+2 added-2 removed
9 unmodified lines101112131414151616171819209 unmodified lines runs-on: ubuntu-20.04 timeout-minutes: 10
steps: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Set up Python uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 with: python-version: "3.x" - name: Run pre-commit uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # v3.0.0modified:.github/workflows/run-tests.yml+26 added-14 removed
10 unmodified lines111213141515161718192021222324251718281920302122232425262728296 unmodified lines363738394840415042434445464748495051525354555657585960616263646566676869707110 unmodified lines timeout-minutes: 10 strategy: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.9", "pypy-3.10"] python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.9", "pypy-3.10"] os: [ubuntu-22.04, macOS-latest, windows-latest] # Python 3.8 and 3.9 do not run on macOS-latest which # is now using arm64 hardware. # https://github.com/actions/setup-python/issues/696#issuecomment-1637587760 exclude: - { python-version: "3.8", os: "macos-latest" } - { python-version: "3.9", os: "macos-latest" } include: - { python-version: "3.8", os: "macos-13" } - { python-version: "3.9", os: "macos-13" }
steps: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 with: python-version: ${{ matrix.python-version }} cache: 'pip' allow-prereleases: true - name: Install dependencies run: | make - name: Run tests6 unmodified lines strategy: fail-fast: true
steps: - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - name: 'Set up Python 3.8' uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b with: python-version: '3.8' - name: Install dependencies run: | make python -m pip uninstall -y "charset_normalizer" "chardet" - name: Run tests run: | make ci
urllib3: name: 'urllib3 1.x' runs-on: 'ubuntu-latest' strategy: fail-fast: true
steps: - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - name: 'Set up Python 3.8' uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b with: python-version: '3.8' - name: Install dependencies run: | make python -m pip install "urllib3<2" - name: Run tests run: | make cimodified:.github/SECURITY.md+4 added-13 removed
1 # Vulnerability Disclosure2 3 If you think you have found a potential security vulnerability in4-requests, please email [Nate](mailto:nate.prewitt@gmail.com)5-and [Seth](mailto:sethmichaellarson@gmail.com) directly.6-**Do not file a public issue.**4+requests, please open a [draft Security Advisory](https://github.com/psf/requests/security/advisories/new)5+via GitHub. We will coordinate verification and next steps through6+that secure medium.7 8-Our PGP Key fingerprints are:9-10-- 8722 7E29 AD9C FF5C FAC3 EA6A 44D3 FF97 B80D C864 ([@nateprewitt](https://keybase.io/nateprewitt))11-12-- EDD5 6765 A9D8 4653 CBC8 A134 51B0 6736 1740 F5FC ([@sethmlarson](https://keybase.io/sethmlarson))13-14-You can also contact us on [Keybase](https://keybase.io) with the15-profiles above if desired.16-8 If English is not your first language, please try to describe the9 problem and its impact to the best of your ability. For greater detail,10 please use your native language and we will try our best to translate it11 using online services.50 unmodified lines62 intended patch ahead of time, to ensure that they are able to promptly63 release their downstream packages. Currently the list of people we64 actively contact *ahead of a public release* is:65 75-- Jeremy Cline, Red Hat (@jeremycline)66+- Python Maintenance Team, Red Hat (python-maint@redhat.com)67 - Daniele Tricoli, Debian (@eriol)68 69 We will notify these individuals at least a week ahead of our planned70 release date to ensure that they have sufficient time to prepare. If you14 unmodified linesmodified:docs/community/vulnerabilities.rst+2 added-107 removed
1 Vulnerability Disclosure2 ========================3 4-If you think you have found a potential security vulnerability in requests,5-please email `Nate <mailto:nate.prewitt@gmail.com>`_ and `Seth <mailto:@sethmichaellarson@gmail.com>`_ directly. **Do not file a public issue.**6-7-Our PGP Key fingerprints are:8-9-- 8722 7E29 AD9C FF5C FAC3 EA6A 44D3 FF97 B80D C864 (`@nateprewitt <https://keybase.io/nateprewitt>`_)10-11-- EDD5 6765 A9D8 4653 CBC8 A134 51B0 6736 1740 F5FC (`@sethmlarson <https://keybase.io/sethmlarson>`_)12-13-You can also contact us on `Keybase <https://keybase.io/>`_ with the14-profiles above if desired.15-16-If English is not your first language, please try to describe the problem and17-its impact to the best of your ability. For greater detail, please use your18-native language and we will try our best to translate it using online services.19-20-Please also include the code you used to find the problem and the shortest21-amount of code necessary to reproduce it.22-23-Please do not disclose this to anyone else. We will retrieve a CVE identifier24-if necessary and give you full credit under whatever name or alias you provide.25-We will only request an identifier when we have a fix and can publish it in a26-release.27-28-We will respect your privacy and will only publicize your involvement if you29-grant us permission.30-31-Process32--------33-34-This following information discusses the process the requests project follows35-in response to vulnerability disclosures. If you are disclosing a36-vulnerability, this section of the documentation lets you know how we will37-respond to your disclosure.38-39-Timeline40-~~~~~~~~41-42-When you report an issue, one of the project members will respond to you within43-two days *at the outside*. In most cases responses will be faster, usually44-within 12 hours. This initial response will at the very least confirm receipt45-of the report.46-47-If we were able to rapidly reproduce the issue, the initial response will also48-contain confirmation of the issue. If we are not, we will often ask for more49-information about the reproduction scenario.50-51-Our goal is to have a fix for any vulnerability released within two weeks of52-the initial disclosure. This may potentially involve shipping an interim53-release that simply disables function while a more mature fix can be prepared,54-but will in the vast majority of cases mean shipping a complete release as soon55-as possible.56-57-Throughout the fix process we will keep you up to speed with how the fix is58-progressing. Once the fix is prepared, we will notify you that we believe we59-have a fix. Often we will ask you to confirm the fix resolves the problem in60-your environment, especially if we are not confident of our reproduction61-scenario.62-63-At this point, we will prepare for the release. We will obtain a CVE number64-if one is required, providing you with full credit for the discovery. We will65-also decide on a planned release date, and let you know when it is. This66-release date will *always* be on a weekday.67-68-At this point we will reach out to our major downstream packagers to notify69-them of an impending security-related patch so they can make arrangements. In70-addition, these packagers will be provided with the intended patch ahead of71-time, to ensure that they are able to promptly release their downstream72-packages. Currently the list of people we actively contact *ahead of a public73-release* is:74-75-- Python Maintenance Team, Red Hat (python-maint@redhat.com)76-- Daniele Tricoli, Debian (@eriol)77-78-We will notify these individuals at least a week ahead of our planned release79-date to ensure that they have sufficient time to prepare. If you believe you80-should be on this list, please let one of the maintainers know at one of the81-email addresses at the top of this article.82-83-On release day, we will push the patch to our public repository, along with an84-updated changelog that describes the issue and credits you. We will then issue85-a PyPI release containing the patch.86-87-At this point, we will publicise the release. This will involve mails to88-mailing lists, Tweets, and all other communication mechanisms available to the89-core team.90-91-We will also explicitly mention which commits contain the fix to make it easier92-for other distributors and users to easily patch their own versions of requests93-if upgrading is not an option.94-95-Previous CVEs96--------------97-98-- Fixed in 2.20.099- - `CVE 2018-18074 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=2018-18074>`_100-101-- Fixed in 2.6.0102-103- - `CVE 2015-2296 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=2015-2296>`_,104- reported by Matthew Daley of `BugFuzz <https://bugfuzz.com/>`_.105-106-- Fixed in 2.3.0107-108- - `CVE 2014-1829 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=2014-1829>`_109-110- - `CVE 2014-1830 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=2014-1830>`_4+The latest vulnerability disclosure information can be found on GitHub in our5+`Security Policy <https://github.com/psf/requests/blob/main/.github/SECURITY.md>`_.modified:src/requests/compat.py+12 added
8 unmodified lines9 10 import importlib11 import sys12 13+# -------14+# urllib315+# -------16+from urllib3 import __version__ as urllib3_version17+18+# Detect which major version of urllib3 is being used.19+try:20+ is_urllib3_1 = int(urllib3_version.split(".")[0]) == 121+except (TypeError, AttributeError):22+ # If we can't discern a version, prefer old functionality.23+ is_urllib3_1 = True24+25 # -------------------26 # Character Detection27 # -------------------28 78 unmodified linesmodified:src/requests/utils.py+4 added-1 removed
36 unmodified lines37 bytes,38 getproxies,39 getproxies_environment,40 integer_types,41+ is_urllib3_1,42 )43 from .compat import parse_http_list as _parse_list_header44 from .compat import (45 proxy_bypass,90 unmodified lines136 def super_len(o):137 total_length = None138 current_position = 0139 139- if isinstance(o, str):140+ if not is_urllib3_1 and isinstance(o, str):141+ # urllib3 2.x+ treats all strings as utf-8 instead142+ # of latin-1 (iso-8859-1) like http.client.143 o = o.encode("utf-8")144 145 if hasattr(o, "__len__"):146 total_length = len(o)953 unmodified linesmodified:tests/test_requests.py+24 added-17 removed
23 unmodified lines24 MutableMapping,25 builtin_str,26 cookielib,27 getproxies,28+ is_urllib3_1,29 urlparse,30 )31 from requests.cookies import cookiejar_from_dict, morsel_to_cookie32 from requests.exceptions import (1777 unmodified lines1810 p = req.prepare()1811 1812 assert p.headers["Content-Length"] == length1813 1813- def test_content_length_for_bytes_data(self, httpbin):1814- data = "This is a string containing multi-byte UTF-8 ☃️"1815- encoded_data = data.encode("utf-8")1816- length = str(len(encoded_data))1817- req = requests.Request("POST", httpbin("post"), data=encoded_data)1818- p = req.prepare()1819-1820- assert p.headers["Content-Length"] == length1821-1822- def test_content_length_for_string_data_counts_bytes(self, httpbin):1823- data = "This is a string containing multi-byte UTF-8 ☃️"1824- length = str(len(data.encode("utf-8")))1825- req = requests.Request("POST", httpbin("post"), data=data)1826- p = req.prepare()1827-1828- assert p.headers["Content-Length"] == length1829-1814 def test_nonhttp_schemes_dont_check_URLs(self):1815 test_urls = (1816 "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",1817 "file:///etc/passwd",1131 unmodified lines2949 2950 assert client_cert is not None2951 2952 2953+def test_content_length_for_bytes_data(httpbin):2954+ data = "This is a string containing multi-byte UTF-8 ☃️"2955+ encoded_data = data.encode("utf-8")2956+ length = str(len(encoded_data))2957+ req = requests.Request("POST", httpbin("post"), data=encoded_data)2958+ p = req.prepare()2959+2960+ assert p.headers["Content-Length"] == length2961+2962+2963+@pytest.mark.skipif(2964+ is_urllib3_1,2965+ reason="urllib3 2.x encodes all strings to utf-8, urllib3 1.x uses latin-1",2966+)2967+def test_content_length_for_string_data_counts_bytes(httpbin):2968+ data = "This is a string containing multi-byte UTF-8 ☃️"2969+ length = str(len(data.encode("utf-8")))2970+ req = requests.Request("POST", httpbin("post"), data=data)2971+ p = req.prepare()2972+2973+ assert p.headers["Content-Length"] == length2974+2975+2976 def test_json_decode_errors_are_serializable_deserializable():2977 json_decode_error = requests.exceptions.JSONDecodeError(2978 "Extra data",2979 '{"responseCode":["706"],"data":null}{"responseCode":["706"],"data":null}',4 unmodified linesmodified:requirements-dev.txt+1 added-1 removed
1 -e .[socks]2 pytest>=2.8.0,<93 pytest-cov4-pytest-httpbin==2.0.04+pytest-httpbin==2.1.05 httpbin~=0.10.06 trustme7 wheelmodified:setup.py+2 added-27 removed
2 unmodified lines3 import sys4 from codecs import open5 6 from setuptools import setup7-from setuptools.command.test import test as TestCommand7 8 CURRENT_PYTHON = sys.version_info[:2]9 REQUIRED_PYTHON = (3, 8)10 15 unmodified lines26 )27 sys.exit(1)28 29 31-class PyTest(TestCommand):32- user_options = [("pytest-args=", "a", "Arguments to pass into py.test")]33-34- def initialize_options(self):35- TestCommand.initialize_options(self)36- try:37- from multiprocessing import cpu_count38-39- self.pytest_args = ["-n", str(cpu_count()), "--boxed"]40- except (ImportError, NotImplementedError):41- self.pytest_args = ["-n", "1", "--boxed"]42-43- def finalize_options(self):44- TestCommand.finalize_options(self)45- self.test_args = []46- self.test_suite = True47-48- def run_tests(self):49- import pytest50-51- errno = pytest.main(self.pytest_args)52- sys.exit(errno)53-54-30 # 'setup.py publish' shortcut.31 if sys.argv[-1] == "publish":32 os.system("python setup.py sdist bdist_wheel")33 os.system("twine upload dist/*")5 unmodified lines39 "urllib3>=1.21.1,<3",40 "certifi>=2017.4.17",41 ]42 test_requirements = [68- "pytest-httpbin==2.0.0",43+ "pytest-httpbin==2.1.0",44 "pytest-cov",45 "pytest-mock",46 "pytest-xdist",47 "PySocks>=1.5.6, !=1.5.7",38 unmodified lines86 "Programming Language :: Python :: 3.9",87 "Programming Language :: Python :: 3.10",88 "Programming Language :: Python :: 3.11",89 "Programming Language :: Python :: 3.12",90+ "Programming Language :: Python :: 3.13",91 "Programming Language :: Python :: 3 :: Only",92 "Programming Language :: Python :: Implementation :: CPython",93 "Programming Language :: Python :: Implementation :: PyPy",94 "Topic :: Internet :: WWW/HTTP",95 "Topic :: Software Development :: Libraries",96 ],121- cmdclass={"test": PyTest},97 tests_require=test_requirements,98 extras_require={99 "security": [],100 "socks": ["PySocks>=1.5.6, !=1.5.7"],7 unmodified linesmodified:tox.ini+1 added-1 removed
1 [tox]2-envlist = py{38,39,310,311,312}-{default, use_chardet_on_py3}2+envlist = py{38,39,310,311,312,313}-{default, use_chardet_on_py3}3 4 [testenv]5 deps = -rrequirements-dev.txt6 extras =12 unmodified lines