Azure OpenAI / AI Foundry resource key
ID |
azure_openai_key |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
high |
Remediation Effort |
low |
Vendor |
Azure OpenAI |
Family |
API Token |
Description
Azure OpenAI, now part of Microsoft Foundry (Azure AI Foundry), serves OpenAI and other foundation models from a resource deployed in your own Azure subscription. The resource is authenticated with one of two interchangeable keys, or with Microsoft Entra ID.
The legacy resource key is a bare 32 hex-digit string. Nothing in the value identifies the vendor, so this detector also requires the variable name to name the service. A key passed under an unrelated name is reported by the generic API key detectors instead.
When the resource endpoint (https://<resource>.openai.azure.com) appears in the same
file, it is used to check whether the key is still live.
Security
A leaked Azure OpenAI key grants an attacker the same access as the application that owns it:
-
Unauthorized usage is billed to your account, and automated high-volume calls can run up a large charge before anyone notices.
-
Whatever is sent through the leaked key — prompts, documents, query results — is exposed to whoever holds it.
-
The key does not expire on its own, so the exposure lasts until it is revoked.
Examples
The following is a leak of an Azure OpenAI key:
AZURE_OPENAI_ENDPOINT=https://my-resource.openai.azure.com/ AZURE_OPENAI_API_KEY=1a2b...5c6d
Mitigation / Fix
-
Follow your policy for handling leaked secrets, which normally requires revoking the key. In the Azure portal, open the Azure OpenAI / AI Foundry resource and go to [Resource Management > Keys and Endpoint]. Switch the application to the key that did not leak, then click "Regenerate" on the leaked one. Prefer Entra ID (keyless) authentication where the workload supports it.
Revoke the leaked key, do not merely disable it. -
Remove the leaked key from the source code or committed configuration file, and replace its usages with the new value. Environment variables, local files or secret vaults could be used for passing the key, instead of hardcoding the value, as documented in How to Prevent Hard-Coded Secrets.
-
Review the usage and audit logs for the key, to confirm that it was not used by unintended actors while it was exposed.
-
Apply the usual precautions for API keys: never commit them, pass them through environment variables or a secret manager, use a separate key per environment, monitor usage for unusual spikes, and rotate them periodically.
|
You should consider any sensitive data in commits with secrets as compromised. Remember that secrets may be removed from history in your projects, but not in other users' cloned or forked repositories. |