Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Security audit: pin openai, and re-review the four digest-pinned entries (#9148)

Daniel Han659b9dad3fd0
diff --git a/scripts/scan_packages_baseline.json b/scripts/scan_packages_baseline.json
index 9b69c96fdab..fa5c4ac9183 100644
--- a/scripts/scan_packages_baseline.json
+++ b/scripts/scan_packages_baseline.json
@@ -1688,36 +1688,36 @@
"file": "openai/_client.py",
"check": "Harvests environment variables/secrets AND makes network calls",
"severity": "CRITICAL",
- "evidence": "Env: L210: api_key = os.environ.get(\"OPENAI_API_KEY\") | L220: admin_api_key = os.environ.get(\"OPENAI_ADMIN_KEY\") | L244: webhook_secret = os.environ.get(\"OPENAI_WEBHOOK_SECRET\") | L816: api_key = os.environ.get(\"OPENAI_API_KEY\") | L826: admin_api_key = os.environ.get(\"OPENAI_ADMIN_KEY\") | L850: webhook_secret = os.environ.get(\"OPENAI_WEBHOOK_SECRET\")\nNetwork: L147: http_client: httpx2.Client | None = None, | L599: http_client: httpx2.Client | None = None, | L753: http_client: httpx2.AsyncClient | None = None, | L1216: http_client: httpx2.AsyncClient | None = None,",
+ "evidence": "Env: L235: api_key = os.environ.get(\"OPENAI_API_KEY\") | L245: admin_api_key = os.environ.get(\"OPENAI_ADMIN_KEY\") | L269: webhook_secret = os.environ.get(\"OPENAI_WEBHOOK_SECRET\") | L908: api_key = os.environ.get(\"OPENAI_API_KEY\") | L918: admin_api_key = os.environ.get(\"OPENAI_ADMIN_KEY\") | L942: webhook_secret = os.environ.get(\"OPENAI_WEBHOOK_SECRET\")\nNetwork: L170: http_client: httpx2.Client | None = None, | L661: http_client: httpx2.Client | None = None, | L843: http_client: httpx2.AsyncClient | None = None, | L1347: http_client: httpx2.AsyncClient | None = None,",
"evidence_hash": "ee8e7ed79d2bfe99f85f53b1bff3d0f59cfc0de3393ab31a2955ef4365005e3c",
- "file_sha256": "389ea48de3b3c46a9048d6636ca19e43533bda98e4dccde2d7f96037d0c82817"
+ "file_sha256": "6303a1c4b4b01491dd6e9ef248ba74d8d7a5af5185a1d45721ab9c904dd77b42"
},
{
"package": "openai",
"file": "openai/auth/_workload.py",
"check": "Accesses cloud metadata/IMDS AND makes network calls",
"severity": "CRITICAL",
- "evidence": "IMDS: L97: url = \"http://169.254.169.254/metadata/identity/oauth2/token\" | L150: url = \"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity\"\nNetwork: L78: http_client: httpx2.Client | None = None, | L109: with httpx2.Client() as client: | L134: http_client: httpx2.Client | None = None, | L156: with httpx2.Client() as client:",
+ "evidence": "IMDS: L130: url = \"http://169.254.169.254/metadata/identity/oauth2/token\" | L183: url = \"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity\"\nNetwork: L111: http_client: httpx2.Client | None = None, | L142: with httpx2.Client() as client: | L167: http_client: httpx2.Client | None = None, | L189: with httpx2.Client() as client:",
"evidence_hash": "a4b0fb17867ab99605026f7d5d753ba2d3cd0a79f5fab6d77521ec251c256a4c",
- "file_sha256": "6a01858ee5a351df969067995bde0a97d4762455468f24c116f818db3aaec95d"
+ "file_sha256": "f61ff8db00ec65d293e7cea656289ac6b0c47faa0997fa70c1731ecf57949512"
},
{
"package": "openai",
"file": "openai/lib/azure.py",
"check": "Harvests environment variables/secrets AND makes network calls",
"severity": "CRITICAL",
- "evidence": "Env: L215: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") | L218: azure_ad_token = os.environ.get(\"AZURE_OPENAI_AD_TOKEN\") | L539: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") | L542: azure_ad_token = os.environ.get(\"AZURE_OPENAI_AD_TOKEN\")\nNetwork: L38: _HttpxClientT = TypeVar(\"_HttpxClientT\", bound=Union[httpx2.Client, httpx2.AsyncClient]) | L101: class AzureOpenAI(BaseAzureClient[httpx2.Client, Stream[Any]], OpenAI): | L120: http_client: httpx2.Client | None = None, | L142: http_client: httpx2.Client | None = None, | L164: http_client: httpx2.Client | None = None, | L190: http_client: httpx2.Client | None = None, | L298: http_client: httpx2.Client | None = None, | L422: class AsyncAzureOpenAI(BaseAzureClient[httpx2.AsyncClient, AsyncStream[Any]], AsyncOpenAI): | L442: http_client: httpx2.AsyncClient | None = None, | L465: http_client: httpx2.AsyncClient | None = None, | L488: http_client: httpx2.AsyncClient | None = None, | L514: http_client: httpx2.AsyncClient | None = None, | L622: http_client: httpx2.AsyncClient | None = None,",
+ "evidence": "Env: L219: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") | L222: azure_ad_token = os.environ.get(\"AZURE_OPENAI_AD_TOKEN\") | L548: api_key = os.environ.get(\"AZURE_OPENAI_API_KEY\") | L551: azure_ad_token = os.environ.get(\"AZURE_OPENAI_AD_TOKEN\")\nNetwork: L39: _HttpxClientT = TypeVar(\"_HttpxClientT\", bound=Union[httpx2.Client, httpx2.AsyncClient]) | L102: class AzureOpenAI(BaseAzureClient[httpx2.Client, Stream[Any]], OpenAI): | L121: http_client: httpx2.Client | None = None, | L143: http_client: httpx2.Client | None = None, | L165: http_client: httpx2.Client | None = None, | L191: http_client: httpx2.Client | None = None, | L302: http_client: httpx2.Client | None = None, | L428: class AsyncAzureOpenAI(BaseAzureClient[httpx2.AsyncClient, AsyncStream[Any]], AsyncOpenAI): | L448: http_client: httpx2.AsyncClient | None = None, | L471: http_client: httpx2.AsyncClient | None = None, | L494: http_client: httpx2.AsyncClient | None = None, | L520: http_client: httpx2.AsyncClient | None = None, | L631: http_client: httpx2.AsyncClient | None = None,",
"evidence_hash": "a2048fafc6303825095270dc766eb7630cdf9b0fb2e6eb0272695dbe9cd185c1",
- "file_sha256": "b031fc8ab1d1d7865cd7f09e07a8cb08ea15b9269c710df62b1bb505d0920ed2"
+ "file_sha256": "7f6f58dd6e0068765e58af2c59acfa40504a03187953e3459ea008c263f952d7"
},
{
"package": "openai",
"file": "openai/lib/bedrock.py",
"check": "Harvests environment variables/secrets AND makes network calls",
"severity": "CRITICAL",
- "evidence": "Env: L105: token = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\") | L150: environment_token = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\")\nNetwork: L415: http_client: httpx2.Client | None = None, | L531: http_client: httpx2.Client | None = None, | L649: http_client: httpx2.AsyncClient | None = None, | L767: http_client: httpx2.AsyncClient | None = None,",
+ "evidence": "Env: L117: token = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\") | L162: environment_token = os.environ.get(\"AWS_BEARER_TOKEN_BEDROCK\")\nNetwork: L440: http_client: httpx2.Client | None = None, | L554: http_client: httpx2.Client | None = None, | L672: http_client: httpx2.AsyncClient | None = None, | L788: http_client: httpx2.AsyncClient | None = None,",
"evidence_hash": "ed7177e905325f49fc00b6329c7b4c18436af60fa52a559251a3a54618715873",
- "file_sha256": "9d38c8b3d410100ea7d63d17eac2e92d71a2916305586c244a06111e99da7704"
+ "file_sha256": "75816d2632b709d789ca5ebef43e15c3916691bb7ce9e8ed57181a2faccc667e"
}
]
}
diff --git a/studio/backend/requirements/extras.txt b/studio/backend/requirements/extras.txt
index 865426d7455..41f8d72a57c 100644
--- a/studio/backend/requirements/extras.txt
+++ b/studio/backend/requirements/extras.txt
@@ -53,5 +53,18 @@ einops==0.8.2
# 0.10 requires >=3.10.
tabulate==0.10.0; python_version >= "3.10"
tabulate==0.9.0; python_version < "3.10"
-openai>=2.7.2
+# Pinned, not floating. scan_packages_baseline.json pins four reviewed-benign
+# CRITICALs in this package to the reviewed file digests, because the evidence
+# hash records a network call but not its destination (#8104, #8565). A floating
+# spec therefore reds the security gate on whatever day upstream ships, which is
+# what openai 3.2.0 did. Bump this deliberately and re-review the four entries
+# with --write-baseline.
+#
+# Split on 3.10 because openai 3.x requires it and this file still supports 3.9
+# (pyproject requires-python is >=3.9). A single `openai==3.2.0` would not resolve
+# at all there, where `>=2.7.2` had quietly been picking 2.48.0; that is the last
+# release accepting 3.9, so the pin keeps what 3.9 was already getting. Only the
+# 3.10 branch is what the security audit scans, since that job runs on 3.12.
+openai==3.2.0; python_version >= "3.10"
+openai==2.48.0; python_version < "3.10"
websockets>=15.0.1
diff --git a/tests/security/test_scan_packages.py b/tests/security/test_scan_packages.py
index 03af6c35018..853c3854fc9 100644
--- a/tests/security/test_scan_packages.py
+++ b/tests/security/test_scan_packages.py
@@ -2048,3 +2048,216 @@ def test_a_stalled_pool_exits_2_not_1(tmp_path, monkeypatch, capsys):
assert rc == 2, f"a stalled scan must exit 2 (incomplete), got {rc}"
assert "SCAN INCOMPLETE" in captured.err
assert "scan stalled" in captured.err
+
+
+def _tomllib():
+ """`tomllib` is stdlib only on 3.11+ (PEP 680); below that, the tomli backport.
+
+ pyproject's requires-python is >=3.9 and testpaths is ["tests/security"], so a bare
+ `pytest` from the repo root collects this file on 3.9 and 3.10, where a plain
+ `import tomllib` is a ModuleNotFoundError rather than a test result. tomli is already
+ a declared dependency there (extras-no-deps.txt pins it for python_version < "3.11"),
+ and this is the same shape the rest of the suite already uses -- see
+ tests/python/test_windows_xformers_wheel_match.py and
+ tests/studio/install/test_install_node_prebuilt_logic.py.
+ """
+ if sys.version_info >= (3, 11):
+ import tomllib
+ return tomllib
+ return pytest.importorskip("tomli")
+
+
+def _supported_python_versions(root):
+ """Every `python_version` marker value pyproject's requires-python admits."""
+ import re
+
+ tomllib = _tomllib()
+ with open(root / "pyproject.toml", "rb") as fh:
+ spec = tomllib.load(fh)["project"]["requires-python"]
+ lo = re.search(r">=\s*3\.(\d+)", spec)
+ hi = re.search(r"<\s*3\.(\d+)", spec)
+ assert lo, f"cannot read a floor out of requires-python {spec!r}"
+ last = int(hi.group(1)) - 1 if hi else int(lo.group(1))
+ return [f"3.{minor}" for minor in range(int(lo.group(1)), last + 1)]
+
+
+def _audited_requirements(root):
+ """(source, spec) for everything security-audit.yml feeds to the scanner.
+
+ Both halves, because the workflow has two. `audit-reqs/unsloth-deps.txt` is
+ generated from pyproject's `project.dependencies` plus the
+ `huggingfacenotorch` extra, and the rest are the studio requirement files
+ copied through a `git+` filter. Reading only the second half is how a pinned
+ package declared in pyproject goes unchecked.
+ """
+ tomllib = _tomllib()
+ for req in sorted((root / "studio" / "backend" / "requirements").glob("*.txt")):
+ for lineno, raw in enumerate(req.read_text(encoding = "utf-8").splitlines(), 1):
+ spec = raw.split("#", 1)[0].strip()
+ if spec and not spec.startswith("-") and "git+" not in spec:
+ yield f"{req.name}:{lineno}", spec
+ with open(root / "pyproject.toml", "rb") as fh:
+ project = tomllib.load(fh)["project"]
+ declared = list(project["dependencies"])
+ declared += list(project["optional-dependencies"]["huggingfacenotorch"])
+ for spec in declared:
+ if "git+" not in spec:
+ yield "pyproject.toml", spec
+
+
+# unsloth_zoo is digest-pinned and deliberately NOT version-pinned, so it is named
+# here rather than quietly skipped. The recurrence this guard exists to stop is an
+# upstream release we do not control changing the bytes and reddening main on a day
+# nobody touched the repo. unsloth_zoo is our own, released in lockstep with this
+# package, and pinning it exactly would break that; when its digest reopens, the
+# change is one of ours and re-reviewing it is the point of the pin (#8104, and that
+# entry is the credential send itself). Third-party packages get no such licence, so
+# the test asserts this list holds only first-party names.
+# Exactly the first-party packages that ARE digest-pinned today, asserted below to
+# be exactly that, so a name added here without an entry, or a third-party name
+# added at all, fails rather than silently widening the exemption.
+FIRST_PARTY_DIGEST_PINNED = {"unsloth-zoo"}
+
+
+def test_digest_pinned_packages_are_pinned_on_every_supported_python():
+ """A digest-pinned third-party package must be `==` pinned on every Python we support.
+
+ The two mechanisms are only coherent together. `file_sha256` deliberately reopens a
+ reviewed CRITICAL on ANY edit to the file, because the evidence records a network
+ call and not its destination, so nothing weaker can tell a benign refactor from an
+ added credential send. A `>=` spec then hands the choice of file bytes to whatever
+ upstream published most recently, so the gate turns red on release day rather than
+ on a change anyone here made. That is not hypothetical: `openai>=2.7.2` floated onto
+ 3.2.0, which touched all four pinned files, and the extras shard went red on main.
+
+ `==` has to mean one version. `openai==3.*` satisfies a naive prefix test and is a
+ floating prefix match to pip, which recreates the same failure, so the specifier is
+ parsed rather than pattern-matched and a wildcard is rejected.
+
+ And `==` is strictly narrower than `>=`, so pinning the newest release silently
+ drops every interpreter that release does not support: openai 3.x needs 3.10, this
+ project supports 3.9 back to pyproject's requires-python, and a bare
+ `openai==3.2.0` does not resolve there AT ALL, where `>=2.7.2` had been quietly
+ picking 2.48.0. A pin that fixes CI by breaking an install is not a fix, so the
+ markers on the pinned lines have to cover the whole supported range between them.
+
+ Marker-only, so it stays offline and deterministic. That bounds what the coverage
+ half can see: it catches a marker partition with a hole in it (a `>= "3.11"` beside
+ a `< "3.10"` leaves 3.10 resolving to nothing), but it cannot catch a single
+ unmarked pin whose version happens not to support 3.9, because knowing that means
+ asking PyPI for the release's requires-python. Resolving the requirements on each
+ supported interpreter is what covers that, and it is done as a resolution
+ simulation rather than from here, so this module stays network-free.
+ """
+ import json
+ import pathlib
+
+ from packaging.markers import Marker
+ from packaging.requirements import Requirement
+
+ root = pathlib.Path(__file__).resolve().parents[2]
+ baseline = json.loads(
+ (root / "scripts" / "scan_packages_baseline.json").read_text(encoding = "utf-8")
+ )
+ pinned_packages = {
+ sp._norm_pkg(e["package"]) for e in baseline["entries"] if e.get("file_sha256")
+ }
+ assert pinned_packages, "no digest-pinned entries; this guard would be vacuous"
+ stray = FIRST_PARTY_DIGEST_PINNED - pinned_packages
+ assert not stray, f"exemption names a package with no digest-pinned entry: {sorted(stray)}"
+ third_party = pinned_packages - FIRST_PARTY_DIGEST_PINNED
+ assert third_party, "every digest-pinned package is exempt; this guard would be vacuous"
+
+ pythons = _supported_python_versions(root)
+ assert pythons, "no supported python versions parsed out of requires-python"
+
+ floating = []
+ covered: dict[str, set[str]] = {}
+ present: set[str] = set()
+ for source, spec in _audited_requirements(root):
+ try:
+ requirement = Requirement(spec)
+ except Exception:
+ continue
+ pkg = sp._norm_pkg(requirement.name)
+ if pkg not in third_party:
+ continue
+ present.add(pkg)
+ specifiers = list(requirement.specifier)
+ exact = (
+ len(specifiers) == 1
+ and specifiers[0].operator == "=="
+ # `==3.*` is a prefix match, not a pin, and pip resolves it to
+ # whatever 3.x is newest.
+ and not specifiers[0].version.endswith(".*")
+ )
+ if not exact:
+ floating.append(f"{source}: {spec}")
+ continue
+ marker = requirement.marker
+ for python in pythons:
+ if marker is None or marker.evaluate({"python_version": python}):
+ covered.setdefault(pkg, set()).add(python)
+
+ assert not floating, (
+ "these packages carry digest-pinned baseline entries but are not pinned to one "
+ "version in what the security audit scans, so it goes red whenever upstream "
+ "publishes: " + "; ".join(floating)
+ )
+ gaps = {
+ pkg: sorted(set(pythons) - covered.get(pkg, set()), key = lambda v: int(v.split(".")[1]))
+ for pkg in sorted(present)
+ }
+ gaps = {pkg: missing for pkg, missing in gaps.items() if missing}
+ assert not gaps, (
+ "a digest-pinned package has no exact pin on some supported Python, so "
+ "installing there resolves to nothing at all: "
+ + "; ".join(f"{pkg} uncovered on {', '.join(missing)}" for pkg, missing in gaps.items())
+ )
+
+
+def test_the_toml_helpers_run_without_stdlib_tomllib(monkeypatch):
+ """The helpers above must work on 3.9/3.10, where `tomllib` does not exist.
+
+ pyproject declares requires-python >=3.9 and testpaths ["tests/security"], so a bare
+ `pytest` from the repo root runs this module on 3.9 and 3.10. `tomllib` landed in 3.11
+ (PEP 680), so an unguarded `import tomllib` there is a collection-time
+ ModuleNotFoundError, not a verdict.
+
+ Simulated rather than skipped: the interpreter running the suite is whatever CI picked
+ (3.12 today), so the below-3.11 branch is only ever reached by making the version look
+ old AND taking `tomllib` away. Doing only the second is not the same thing -- the
+ guard reads sys.version_info, not the module table.
+
+ The backport is supplied rather than required. `tests-security` installs only pytest
+ and PyYAML, so a test that leaned on a real `tomli` being importable would
+ `importorskip` its way to green there and never once execute the branch it exists to
+ cover. Registering the stdlib parser under the name the fallback looks for keeps this
+ load-bearing on every interpreter and in CI, while still proving the fallback is what
+ gets consulted, because `import tomllib` is made to fail for the duration.
+ """
+ import builtins
+ import importlib
+
+ # Read the REAL version before it is patched, and take whichever parser this
+ # interpreter genuinely has. On 3.11+ that is stdlib tomllib, which is always
+ # there, so the branch runs in CI; on a real 3.9/3.10 it is the tomli the
+ # requirements already pin, and only a machine missing both ever skips.
+ parser = (
+ importlib.import_module("tomllib")
+ if sys.version_info >= (3, 11)
+ else pytest.importorskip("tomli")
+ )
+ monkeypatch.setattr(sys, "version_info", (3, 10, 0, "final", 0))
+ monkeypatch.setitem(sys.modules, "tomli", parser)
+ real_import = builtins.__import__
+
+ def without_tomllib(name, *args, **kwargs):
+ if name == "tomllib":
+ raise ModuleNotFoundError("No module named 'tomllib'", name = "tomllib")
+ return real_import(name, *args, **kwargs)
+
+ monkeypatch.setattr(builtins, "__import__", without_tomllib)
+
+ assert _supported_python_versions(REPO_ROOT)[0] == "3.9"
+ assert any(source == "pyproject.toml" for source, _ in _audited_requirements(REPO_ROOT))