설명
전역 security에서 API 키를 요구할 때는 해당 키를 보내는 모든 요청에 HTTPS를 사용하세요.
잠재적 영향
HTTP 요청에서는 키가 전송 중에 노출될 수 있습니다. URL에 넣은 키는 HTTPS를 사용해도 로그에 남을 수 있습니다.
해결 방법
서버와 클라이언트에서 HTTPS만 사용하고 키는 로그에서 가리는 헤더로 보내세요. OpenAPI 3.0은 servers에 HTTPS URL을, 2.0은 schemes에 https를 지정하세요.
예시
변경 후 예시는 HTTPS와 함께 read 스코프의 OAuth2를 사용합니다. API 키를 계속 사용할 때도 같은 HTTPS 설정이 필요합니다.
변경 전
json
{
"openapi": "3.0.0",
"servers": [{"url": "http://api.example.com"}],
"security": [
{
"apiKeyAuth": []
}
],
"components": {
"securitySchemes": {
"apiKeyAuth": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"servers": [{"url": "https://api.example.com"}],
"security": [
{
"OAuth2": [
"read"
]
}
],
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"read": "read objects in your account"
}
}
}
}
}
}
}