Description
If an operation’s security requires an API key, configure clients to call that operation over HTTPS.
Potential impact
A key exposed over plaintext HTTP or recorded in URL logs can be reused with its assigned permissions.
Remediation
Send the key in a header over HTTPS and keep it out of logs. Match the documented header and HTTPS URL to the running server and clients. Revoke and replace exposed keys.
Examples
The example switches POST /pets from API key authentication to OAuth2. Its top-level HTTPS servers URL also applies to other operations that inherit it.
Before
json
{
"openapi": "3.0.0",
"servers": [{"url": "http://api.example.com"}],
"paths": {
"/pets": {
"post": {
"security": [
{
"apiKeyAuth": []
}
]
}
}
},
"components": {
"securitySchemes": {
"apiKeyAuth": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
}
After
json
{
"openapi": "3.0.0",
"servers": [{"url": "https://api.example.com"}],
"paths": {
"/pets": {
"post": {
"security": [
{
"OAuth2": [
"write",
"read"
]
}
]
}
}
},
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"write": "modify objects in your account",
"read": "read objects in your account"
}
}
}
}
}
}
}