Description
An OpenAPI 3.0 API key declared with in: query travels in the request URL and may appear in logs.
Potential impact
Anyone with a disclosed key may call the operations its permissions allow.
Remediation
To keep API key authentication, configure clients and the server to use a header over HTTPS and set in: header in the specification. Redact keys from logs and revoke and replace exposed keys.
Examples
The example uses OAuth2 for delegated access. Its global oauthAuth: [] requires no specific scope. Set and enforce the scopes your API needs.
Before
json
{
"openapi": "3.0.0",
"security": [
{
"apiKeyAuth": []
}
],
"components": {
"securitySchemes": {
"apiKeyAuth": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
}
After
json
{
"openapi": "3.0.0",
"security": [
{
"oauthAuth": []
}
],
"components": {
"securitySchemes": {
"oauthAuth": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/api/oauth/dialog",
"tokenUrl": "https://example.com/api/oauth/token",
"scopes": {
"read:pets": "read your pets"
}
}
}
}
}
}
}