Skip to content

Commit 53a0113

Browse files
committed
Upgrade ensurepip bundle to point to pip>=26.1 to address CVE-2026-6357
1 parent 69ede5e commit 53a0113

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

sdks/python/container/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,20 @@ RUN \
8585
rm -rf /root/.cache/pip && \
8686

8787
# Update ensurepip to use most recent versions of setuptools and pip. This avoids some vulnerabilities which won't be fixed on older versions of python.
88-
pip install upgrade_ensurepip && \
89-
python3 -m upgrade_ensurepip && \
90-
# setuptools is not bundled with ensurepip in Python 3.12+
88+
# Note: We do not use the third-party 'upgrade_ensurepip' package because:
89+
# 1) It is incompatible with Python 3.12+ (which no longer bundles setuptools inside ensurepip, causing an AssertionError).
90+
# 2) It queries public PyPI via raw HTTP calls, failing in sandboxed build environments with custom package mirrors.
91+
# Instead, we download the wheels via pip and patch ensurepip's version mapping manually.
92+
pip download --dest /usr/local/lib/python${py_version}/ensurepip/_bundled/ --only-binary=:all: "pip>=26.1" && \
93+
python3 -c 'import ensurepip, glob, re; whl = glob.glob(ensurepip.__path__[0] + "/_bundled/pip-*.whl")[-1]; version = re.search(r"pip-(.*?)-py", whl).group(1); init_py = ensurepip.__file__; content = open(init_py).read(); content = re.sub(r"_PIP_VERSION = \".*?\"", f"_PIP_VERSION = \"{version}\"", content); open(init_py, "w").write(content);' && \
94+
if [ "${py_version}" = "3.10" ] || [ "${py_version}" = "3.11" ]; then \
95+
pip download --dest /usr/local/lib/python${py_version}/ensurepip/_bundled/ --only-binary=:all: "setuptools" && \
96+
python3 -c 'import ensurepip, glob, re; whl = glob.glob(ensurepip.__path__[0] + "/_bundled/setuptools-*.whl")[-1]; version = re.search(r"setuptools-(.*?)-py", whl).group(1); init_py = ensurepip.__file__; content = open(init_py).read(); content = re.sub(r"_SETUPTOOLS_VERSION = \".*?\"", f"_SETUPTOOLS_VERSION = \"{version}\"", content); open(init_py, "w").write(content);'; \
97+
fi && \
9198
if [ "${py_version}" = "3.10" ] || [ "${py_version}" = "3.11" ]; then \
9299
find /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-*-py3-none-any.whl | tail -n 1)) -delete; \
93100
fi && \
94101
find /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-*-py3-none-any.whl | tail -n 1)) -delete && \
95-
pip uninstall upgrade_ensurepip -y && \
96102
python3 -m ensurepip && \
97103
python3 -c "import ensurepip; assert list(map(int, ensurepip._PIP_VERSION.split('.'))) >= [26, 1], f'Bundled pip version {ensurepip._PIP_VERSION} is older than 26.1';"
98104

0 commit comments

Comments
 (0)