Project: KICS (Provisioning / Security & Compliance)
File: aecee30b-8ea1-4776-a99c-d6d600f0862f.md

title: API Key Exposed In Global Security (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: aecee30b-8ea1-4776-a99c-d6d600f0862f Query name: API Key Exposed In Global Security (v3) Platform: OpenAPI Severity: <span style="color:#edd57e">Low</span> Category: Access Control URL: API Keys should be transported using a secure method such as HTTPS. Define a security scheme that uses a secure method to transport the API key.<br> ```json title="Positive test num. 1 - json file" hl_lines="45 46 47" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "examples": { "foo": { "value": { "versions": [ { "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "id": "v2.0", "links": [ { "href": "http://127.0.0.1:8774/v2/", "rel": "self" } ] } ] } } } } } } } } } }, "security": [ { "apiKey2": [], "apiKey3": [], "apiKey1": [] } ], "components": { "securitySchemes": { "apiKey1": { "type": "apiKey", "name": "X-API-Key", "in": "header" }, "apiKey2": { "type": "apiKey", "name": "X-API-Key", "in": "cookie" }, "apiKey3": { "name": "X-API-Key", "in": "query", "type": "apiKey" } } } } ``` ```yaml title="Positive test num. 2 - yaml file" hl_lines="26 27 28" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response content: application/json: examples: foo: value: versions: status: CURRENT updated: "2011-01-21T11:33:21Z" id: v2.0 links: href: http://127.0.0.1:8774/v2/ rel: self security: apiKey1: [] apiKey2: [] apiKey3: [] components: securitySchemes: apiKey1: type: apiKey name: X-API-Key in: header apiKey2: type: apiKey name: X-API-Key in: cookie apiKey3: type: apiKey name: X-API-Key in: query ``` ```json title="Positive test num. 3 - json file" hl_lines="22 23" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response" } } } } }, "security": [ { "apiKey3": [], "apiKey1": [] } ], "securityDefinitions": { "apiKey1": { "type": "apiKey", "name": "X-API-Key", "in": "header" }, "apiKey3": { "in": "query", "type": "apiKey", "name": "X-API-Key" } } } ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="14 15" swagger: "2.0" info: title: Simple API Overview version:

paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response security: apiKey1: [] apiKey3: [] securityDefinitions: apiKey1: type: apiKey name: X-API-Key in: header apiKey3: type: apiKey name: X-API-Key in: query ``` </details> ```json title="Negative test num. 1 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "examples": { "foo": { "value": { "versions": [ { "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "id": "v2.0", "links": [ { "href": "http://127.0.0.1:8774/v2/", "rel": "self" } ] } ] } } } } } } } } } }, "security": [ { "OAuth2": [ "write", "read" ] } ], "components": { "securitySchemes": { "OAuth2": { "type": "oauth2", "flows": { "authorizationCode": { "scopes": { "read": "read objects in your account", "write": "modify objects in your account" }, "authorizationUrl": "https://example.com/oauth/authorize", "tokenUrl": "https://example.com/oauth/token" } } } } } } ``` ```yaml title="Negative test num. 2 - yaml file" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response content: application/json: examples: foo: value: versions: status: CURRENT updated: "2011-01-21T11:33:21Z" id: v2.0 links: href: http://127.0.0.1:8774/v2/ rel: self components: securitySchemes: OAuth2: type: oauth2 flows: authorizationCode: scopes: write: modify objects in your account read: read objects in your account authorizationUrl: https://example.com/oauth/authorize tokenUrl: https://example.com/oauth/token security: OAuth2: write read ``` ```json title="Negative test num. 3 - json file" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response" } } } } }, "securityDefinitions": { "OAuth2": { "type": "oauth2", "flow": "accessCode", "authorizationUrl": "https://example.com/oauth/authorize", "tokenUrl": "https://example.com/oauth/token", "scopes": { "read": "Grants read access", "write": "Grants write access" } } }, "security": [ { "OAuth2": [ "write", "read" ] } ] } ``` <details><summary>Negative test num. 4 - yaml file</summary> ```yaml swagger: "2.0" info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response securityDefinitions: OAuth2: type: oauth2 flow: accessCode authorizationUrl: https://example.com/oauth/authorize tokenUrl: https://example.com/oauth/token scopes: read: Grants read access write: Grants write access security: OAuth2: write read ``` </details> <details><summary>Negative test num. 5 - yaml file</summary> ```yaml openapi: "3.0.1" info: title: "test" version: "1.0" servers: url: "https://@API-GW-ID.execute-api.us-east-1.amazonaws.com/{basePath}" variables: basePath: default: "/api" paths: /address: get: summary: test description: test responses: '200': description: test content: text/plain: schema: type: string security: authorizer: [ ] components: securitySchemes: authorizer: type: "apiKey" name: "authorization" in: "header" ``` </details>