~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
"""Refresh pip's reviewed bundled urllib3 and MessagePack releases.
Inputs are the unmodified, hash-verified PyPI wheels for pip 26.2.2 and
urllib3 2.8.0 and msgpack 1.2.3. Preserve pip's namespace rewrites,
disabled Brotli support, and pure-Python MessagePack implementation,
update its vendor manifest and CycloneDX SBOM, and regenerate wheel RECORD.
The Docker build installs this wheel and also replaces ensurepip's copy so
creating a venv cannot restore the vulnerable vendored urllib3 2.7.0.
Upstream fixes: https://github.com/urllib3/urllib3/releases/tag/2.8.0
Vendoring baseline: https://github.com/pypa/pip/tree/26.2.2/src/pip/_vendor
Delete this helper and its Docker wiring when a pinned pip release carries
urllib3 >=2.8.0 and msgpack >=1.2.3. A changed input or ensurepip layout
requires a new review.
"""
from __future__ import annotations
import argparse
import base64
import csv
import hashlib
import io
import json
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
from zipfile import ZIP_DEFLATED, ZipFile, ZipInfo
PIP_VERSION = "26.2.2"
URLLIB3_VERSION = "2.8.0"
MSGPACK_VERSION = "1.2.3"
PIP_WHEEL = f"pip-{PIP_VERSION}-py3-none-any.whl"
URLLIB3_WHEEL = f"urllib3-{URLLIB3_VERSION}-py3-none-any.whl"
MSGPACK_INPUT_HASHES = {
(
f"msgpack-{MSGPACK_VERSION}-cp314-cp314-manylinux2014_aarch64."
"manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl"
): "9324c54995641c3d1f92a9d55093c8cde0ffa2fbc87a467a688ef60428393220", # DevSkim: ignore DS173237 - public integrity checksum, not a secret
(
f"msgpack-{MSGPACK_VERSION}-cp314-cp314-manylinux2014_x86_64."
"manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl"
): "d8ef3a66e4b52d2d7fdd90df2984670124b2ff7546d76bb25dcf68ef47f7df58", # DevSkim: ignore DS173237 - public integrity checksum, not a secret
}
INPUT_HASHES = {
PIP_WHEEL: "fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70", # DevSkim: ignore DS173237 - public integrity checksum, not a secret
URLLIB3_WHEEL: "0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", # DevSkim: ignore DS173237 - public integrity checksum, not a secret
**MSGPACK_INPUT_HASHES,
}
VENDOR = "pip/_vendor/"
DIST_INFO = f"pip-{PIP_VERSION}.dist-info/"
def verified_wheel(path: Path) -> dict[str, bytes]:
"""Read only the exact reviewed input, before interpreting ZIP contents."""
expected = INPUT_HASHES.get(path.name)
data = path.read_bytes()
if expected is None or hashlib.sha256(data).hexdigest() != expected:
raise ValueError(f"unreviewed wheel: {path.name}")
with ZipFile(io.BytesIO(data)) as archive:
return {name: archive.read(name) for name in archive.namelist()}
def replace_once(text: str, old: str, new: str, count: int = 1) -> str:
if text.count(old) != count:
raise ValueError(
f"vendoring source drift: expected {count} copies of {old!r}"
)
return text.replace(old, new)
def vendored_sources(upstream: dict[str, bytes]) -> dict[str, bytes]:
"""Apply the same seven-file vendoring delta pip uses for urllib3 2.7.0."""
files = {
VENDOR + name: content
for name, content in upstream.items()
if name.startswith("urllib3/") and not name.endswith("/")
}
# These rewrites include documentation examples, as pip's vendor tool does.
for name, count in (
("poolmanager.py", 2),
("util/request.py", 1),
("util/timeout.py", 1),
("util/url.py", 2),
):
path = VENDOR + "urllib3/" + name
files[path] = replace_once(
files[path].decode(),
"import urllib3\n",
"from pip._vendor import urllib3\n",
count,
).encode()
for name in ("util/url.py", "contrib/pyopenssl.py"):
path = VENDOR + "urllib3/" + name
files[path] = replace_once(
files[path].decode(),
"import idna\n",
"from pip._vendor import idna\n",
).encode()
path = VENDOR + "urllib3/contrib/pyopenssl.py"
text = replace_once(
files[path].decode(),
"import urllib3.contrib.pyopenssl\n urllib3.contrib.pyopenssl.inject_into_urllib3()",
"import pip._vendor.urllib3.contrib.pyopenssl as pyopenssl\n pyopenssl.inject_into_urllib3()",
)
files[path] = text.encode()
path = VENDOR + "urllib3/contrib/emscripten/__init__.py"
text = replace_once(
files[path].decode(),
"import urllib3.connection\n",
"import pip._vendor.urllib3.connection as urllib3_connection\n",
)
text = replace_once(text, "urllib3.connection.", "urllib3_connection.", 3)
files[path] = text.encode()
# pip deliberately does not import ambient Brotli implementations.
for name, replacement in (
("response.py", "brotli = None\n"),
("util/request.py", ""),
):
path = VENDOR + "urllib3/" + name
text = files[path].decode()
start = text.index("try:\n try:\n import brotlicffi")
end = text.index("\n\n", start)
text = text[:start] + replacement + text[end:]
files[path] = text.encode()
files[VENDOR + "urllib3/LICENSE.txt"] = upstream[
f"urllib3-{URLLIB3_VERSION}.dist-info/licenses/LICENSE.txt"
]
return files
def vendored_msgpack_sources(upstream: dict[str, bytes]) -> dict[str, bytes]:
"""Retain pip's pure-Python MessagePack layout on both image architectures."""
files = {
VENDOR + name: content
for name, content in upstream.items()
if name.startswith("msgpack/") and name.endswith(".py")
}
required = {"__init__.py", "exceptions.py", "ext.py", "fallback.py"}
if {name.removeprefix(VENDOR + "msgpack/") for name in files} != required:
raise ValueError("upstream msgpack Python layout changed")
files[VENDOR + "msgpack/COPYING"] = upstream[
f"msgpack-{MSGPACK_VERSION}.dist-info/licenses/COPYING"
]
return files
def refresh_inventory(
files: dict[str, bytes], name: str, previous: str, version: str
) -> None:
"""Keep the manifest, component and dependency references consistent."""
manifest, count = re.subn(
rf"(?m)^(\s*){re.escape(name)}=={re.escape(previous)}$",
rf"\g<1>{name}=={version}",
files[VENDOR + "vendor.txt"].decode(),
)
if count != 1:
raise ValueError(
f"pip's {name} vendor pin changed; review or remove the refresh"
)
files[VENDOR + "vendor.txt"] = manifest.encode()
sbom = json.loads(files[VENDOR + "bom.cdx.json"])
components = [
component
for component in sbom["components"]
if component["name"] == name
]
if len(components) != 1 or components[0]["version"] != previous:
raise ValueError(f"pip's {name} SBOM component changed")
old_ref = f"pkg:pypi/{name}@{previous}"
new_ref = f"pkg:pypi/{name}@{version}"
component = components[0]
if component["bom-ref"] != old_ref or component["purl"] != old_ref:
raise ValueError(f"pip's {name} SBOM reference changed")
component.update(version=version, purl=new_ref)
component["bom-ref"] = new_ref
for dependency in sbom["dependencies"]:
if dependency["ref"] == old_ref:
dependency["ref"] = new_ref
if "dependsOn" in dependency:
dependency["dependsOn"] = [
new_ref if ref == old_ref else ref
for ref in dependency["dependsOn"]
]
files[VENDOR + "bom.cdx.json"] = (
json.dumps(sbom, indent=2) + "\n"
).encode()
def refreshed_contents(
pip: dict[str, bytes],
urllib3: dict[str, bytes],
msgpack: dict[str, bytes],
) -> dict[str, bytes]:
files = {
name: content
for name, content in pip.items()
if not name.startswith((VENDOR + "urllib3/", VENDOR + "msgpack/"))
}
files.update(vendored_sources(urllib3))
files.update(vendored_msgpack_sources(msgpack))
for path in ("urllib3/LICENSE.txt", "msgpack/COPYING"):
files[DIST_INFO + "licenses/src/pip/_vendor/" + path] = files[
VENDOR + path
]
refresh_inventory(files, "urllib3", "2.7.0", URLLIB3_VERSION)
refresh_inventory(files, "msgpack", "1.1.2", MSGPACK_VERSION)
record = DIST_INFO + "RECORD"
rows = io.StringIO(newline="")
writer = csv.writer(rows, lineterminator="\n")
for name, content in sorted(files.items()):
if name == record:
continue
digest = (
base64.urlsafe_b64encode(hashlib.sha256(content).digest())
.rstrip(b"=")
.decode()
)
writer.writerow((name, "sha256=" + digest, len(content)))
writer.writerow((record, "", ""))
files[record] = rows.getvalue().encode()
return files
def build_wheel(inputs: Path, output: Path) -> Path:
msgpack_wheels = list(inputs.glob(f"msgpack-{MSGPACK_VERSION}-*.whl"))
if len(msgpack_wheels) != 1:
raise ValueError("expected exactly one reviewed msgpack wheel")
files = refreshed_contents(
verified_wheel(inputs / PIP_WHEEL),
verified_wheel(inputs / URLLIB3_WHEEL),
verified_wheel(msgpack_wheels[0]),
)
output.mkdir(parents=True, exist_ok=True)
destination = output / PIP_WHEEL
if destination.resolve() == (inputs / PIP_WHEEL).resolve():
raise ValueError("output must not overwrite the reviewed input")
with ZipFile(destination, "w", compression=ZIP_DEFLATED) as archive:
for name, content in sorted(files.items()):
info = ZipInfo(name, date_time=(2026, 10, 11, 0, 0, 0))
info.compress_type = ZIP_DEFLATED
info.external_attr = 0o644 << 16
archive.writestr(info, content)
return destination
def install(wheel: Path, verifier: Path) -> None:
verifier = verifier.resolve(strict=True)
import ensurepip
import pip
if pip.__version__ != PIP_VERSION or ensurepip.version() != PIP_VERSION:
raise ValueError(
"pip/ensurepip changed; review or remove the vendored refresh"
)
bundle = Path(ensurepip.__file__).parent / "_bundled" / PIP_WHEEL
# Refuse an alternative system-wheel layout or an unexpected bundle.
with ensurepip._get_pip_whl_path_ctx() as selected:
if selected.resolve() != bundle.resolve():
raise ValueError(
"ensurepip does not use the reviewed bundled-wheel layout"
)
if hashlib.sha256(bundle.read_bytes()).hexdigest() not in {
INPUT_HASHES[PIP_WHEEL],
hashlib.sha256(wheel.read_bytes()).hexdigest(),
}:
raise ValueError("ensurepip's bundled pip is not the reviewed wheel")
subprocess.run(
[
sys.executable,
"-I",
"-m",
"pip",
"install",
"--no-index",
"--no-deps",
"--no-cache-dir",
"--force-reinstall",
str(wheel),
],
check=True,
)
shutil.copyfile(wheel, bundle)
# Fresh interpreters avoid trusting modules cached before reinstalling pip.
check = ["-I", str(verifier), URLLIB3_VERSION, MSGPACK_VERSION]
subprocess.run([sys.executable, *check], check=True)
subprocess.run(
[sys.executable, "-I", "-m", "pip", "debug", "--verbose"], check=True
)
with tempfile.TemporaryDirectory(prefix="pip-vendor-venv-") as directory:
subprocess.run(
[sys.executable, "-I", "-m", "venv", directory], check=True
)
subprocess.run(
[str(Path(directory) / "bin/python"), *check], check=True
)
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("inputs", type=Path)
parser.add_argument("output", type=Path)
parser.add_argument(
"--install",
type=Path,
metavar="VERIFIER",
help="install the wheel and run this standalone verifier in pip and a new venv",
)
args = parser.parse_args()
wheel = build_wheel(args.inputs, args.output)
if args.install is not None:
install(wheel, args.install)
if __name__ == "__main__":
main()