llm 0.37.2 patches bug that could send OpenAI API keys to other providers
The llm 0.37.2 release fixes a security issue that could accidentally send a configured OpenAI API key to other OpenAI-compatible API providers.
Simon Willison's llm 0.37.2, released on 11 November, fixes two security advisories. Both describe separate ways a configured OpenAI API key could be sent to a third-party, OpenAI-compatible endpoint. Both advisories are rated Moderate and classified as CWE-201 (insertion of sensitive information into sent data). Neither has a CVE.
llm lets users point models at other providers through an extra-openai-models.yaml file. Version 0.37 added an llm openai endpoint add command to manage that file. Each entry can set an api_base, the endpoint URL, and an api_key_name, the name under which a key is stored with llm keys set.
The first bug lies in how that key name is resolved. According to the advisory for GHSA-v9h7-jj4g-f862, register_models() sets the model's needs_key to the api_key_name but leaves the class's key_env_var as OPENAI_API_KEY. When no key is stored under the alias, get_key() falls back to that environment variable, which holds the OpenAI key, and the request sends it as a bearer token to api_base. A typo in the name, a skipped llm keys set, or a fresh machine with only OPENAI_API_KEY exported is enough to trigger it. The advisory's reproduction sets the variable to a canary string and shows a third-party host receiving it in the Authorization header. It says every release from 0.6, in July 2023, when api_key_name was added, through 0.37.1 is affected. In versions 0.6 through 0.7.1 the problem was broader, because the environment variable overrode stored keys. That behaviour was fixed in 0.8 under issue #158. The advisory notes that the documentation presents api_key_name as the way to send a different key and says the OpenAI key is not sent when api_base is set.
In 0.37.2, a model in this configuration fails with a No key found error instead of sending the environment key. The advisory's suggested patch clears key_env_var whenever api_base is set. The advisory admits this is a behaviour change. Anyone who relied on OPENAI_API_KEY holding a third-party key for such a model would need to run llm keys set with that name. It proposes an alternative, a key_env_var setting in the YAML file, which was discussed in closed issue #566.
The second bug, GHSA-r639-rr7r-x72w, involves models marked responses: true that also have an api_base. Running one with -o chat_completions 1 sends the user's stored OpenAI key, or OPENAI_API_KEY, to that endpoint. The advisory traces this to construction order. register_models() sets needs_key to None after the model is built when api_base is set. The Responses model then builds a sibling Chat model from its delegate keyword arguments. But needs_key is not a constructor argument, so the delegate keeps the class default of openai. The outer model passes no key, and the delegate's get_client() then calls get_key(None), which returns the OpenAI key. The leak happens only when no api_key_name is set, the case the advisory says the documentation describes as safe. The docs in other-models.md say the existing OpenAI key will not be sent by default when api_base is set. The advisory gives an affected range of 0.32a2 through 0.37.1. It says that from 0.32rc2, the llm openai endpoint URL --responses command, run without --key and with -o chat_completions 1, leaked the key in the same way.
The advisory's evidence is a test modelled on the project's existing endpoint tests. It runs the same request with a stored key and with an environment key. On the unpatched code, the Authorization header carries the OpenAI key. The author reports that a grid of 12 combinations of model type, api_key_name use and key source fails in only these two cases. The suggested patch copies needs_key onto the delegate in both the synchronous and asynchronous Responses methods. With the patch, the 12-case grid passes, the full suite passes with 1319 tests, and mypy is clean. The author did not add the parameter to Chat.__init__ because plugins import that class.
The advisory author describes the impact as disclosure of the user's OpenAI key to whatever server api_base points at. That could be a third-party provider, a proxy or a self-hosted gateway, and the user gets no indication that the key was sent. The advisory for the first bug likewise says nothing shows the OpenAI key was sent instead. Both reports say they were found during an AI-assisted documentation review. The author reproduced each issue, tested the patch locally against main, and says the bugs have not been disclosed elsewhere. The advisories do not say whether any real user keys have been sent to third parties in practice.
What changed
llm 0.37.2 stops sending a configured OpenAI API key to third-party OpenAI-compatible api_base endpoints, fixing two bugs that could leak it.
Type: Security · Applies to: llm 0.37.2
Why it matters
Teams that point llm at third-party OpenAI-compatible endpoints could have leaked OpenAI credentials to those providers without intending to.
What you can do
Upgrade llm to 0.37.2 and review configured OpenAI-compatible endpoints, rotating the OpenAI key if an unintended endpoint may have received it.
Original source
Where we saw it
Simon Willison
AI wrote this summary from the sources listed, and nobody reviewed it individually before publication. Check the original source before you rely on it. How it works