설명
작업의 security에서 API 키를 요구한다면 클라이언트가 해당 작업을 HTTPS로 호출하도록 설정하세요.
잠재적 영향
평문으로 전송하거나 URL 로그에 남긴 키가 노출되면 다른 사람이 키에 허용된 작업을 호출할 수 있습니다.
해결 방법
키는 HTTPS 헤더로 보내고 로그에 기록하지 마세요. 문서에 지정한 헤더와 HTTPS 주소가 실제 서버 및 클라이언트 설정과 일치하는지 확인하세요. 노출된 키는 폐기하고 재발급하세요.
예시
예시의 POST /pets는 API 키에서 OAuth2로 전환합니다. 최상위 servers의 HTTPS 주소는 별도 서버를 지정하지 않은 다른 작업에도 적용됩니다.
변경 전
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"
}
}
}
}
변경 후
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"
}
}
}
}
}
}
}