Project: KICS (Provisioning / Security & Compliance)
File: 462d6a1d-fed9-4d75-bb9e-3de902f35e6e.md

title: Undefined Scope 'securityScheme' On 'security' Field On Operations hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 462d6a1d-fed9-4d75-bb9e-3de902f35e6e Query name: Undefined Scope 'securityScheme' On 'security' Field On Operations Platform: OpenAPI Severity: <span style="color:#edd57e">Low</span> Category: Access Control URL: Using an scope on security of operations that is undefined on 'securityScheme' can be defined by an attacker<br> ```json title="Positive test num. 1 - json file" hl_lines="13" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": { "oAuth2AuthCodeNeg2": [ "read:api", "error:api" ] }, "responses": { "200": { "description": "200 response", "content": { "application/json": null } } } } } }, "components": { "securitySchemes": { "oAuth2AuthCodeNeg2": { "type": "oauth2", "description": "For more information, see https://api.my.company.com/docs/oauth", "flows": { "authorizationCode": { "authorizationUrl": "https://api.my.company.com/oauth/authorize", "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "read:api": "read your apis", "admin:api": "admin scope" } }, "password": { "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "write:api": "write your apis" } } } } } } } ``` ```json title="Positive test num. 2 - json file" hl_lines="14" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [ { "oAuth2AuthCodeNeg2": [ "error:api", "write:api" ] } ], "responses": { "200": { "description": "200 response", "content": { "application/json": null } } } } } }, "components": { "securitySchemes": { "oAuth2AuthCodeNeg2": { "type": "oauth2", "description": "For more information, see https://api.my.company.com/docs/oauth", "flows": { "authorizationCode": { "authorizationUrl": "https://api.my.company.com/oauth/authorize", "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "read:api": "read your apis", "admin:api": "admin scope" } }, "password": { "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "write:api": "write your apis" } } } } } } } ``` ```yaml title="Positive test num. 3 - yaml file" hl_lines="11" openapi: 3.0.0 info: title: Simple API overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: oAuth2AuthCodeNeg2: read:api error:api responses: '200': description: 200 response content: application/json: components: securitySchemes: oAuth2AuthCodeNeg2: type: oauth2 description: For more information, see https://api.my.company.com/docs/oauth flows: authorizationCode: authorizationUrl: https://api.my.company.com/oauth/authorize tokenUrl: https://api.my.company.com/oauth/token scopes: read:api: read your apis admin:api: admin scope password: tokenUrl: https://api.my.company.com/oauth/token scopes: write:api: write your apis ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="11" openapi: 3.0.0 info: title: Simple API overview version:

paths: "/": get: operationId: listVersionsv2 summary: List API versions security: oAuth2AuthCodeNeg2: error:api write:api responses: '200': description: 200 response content: application/json: components: securitySchemes: oAuth2AuthCodeNeg2: type: oauth2 description: For more information, see https://api.my.company.com/docs/oauth flows: authorizationCode: authorizationUrl: https://api.my.company.com/oauth/authorize tokenUrl: https://api.my.company.com/oauth/token scopes: read:api: read your apis admin:api: admin scope password: tokenUrl: https://api.my.company.com/oauth/token scopes: write:api: write your apis ``` </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", "security": [ { "oAuth2AuthCodeNeg2": [ "read:api", "write:api" ] } ], "responses": { "200": { "description": "200 response", "content": { "application/json": null } } } } } }, "components": { "securitySchemes": { "oAuth2AuthCodeNeg2": { "type": "oauth2", "description": "For more information, see https://api.my.company.com/docs/oauth", "flows": { "authorizationCode": { "authorizationUrl": "https://api.my.company.com/oauth/authorize", "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "read:api": "read your apis", "admin:api": "admin scope" } }, "password": { "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "write:api": "write your apis" } } } } } } } ``` ```json title="Negative test num. 2 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": { "oAuth2AuthCodeNeg2": [ "read:api", "write:api" ] }, "responses": { "200": { "description": "200 response", "content": { "application/json": null } } } } } }, "components": { "securitySchemes": { "oAuth2AuthCodeNeg2": { "type": "oauth2", "description": "For more information, see https://api.my.company.com/docs/oauth", "flows": { "authorizationCode": { "authorizationUrl": "https://api.my.company.com/oauth/authorize", "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "read:api": "read your apis", "admin:api": "admin scope" } }, "password": { "tokenUrl": "https://api.my.company.com/oauth/token", "scopes": { "write:api": "write your apis" } } } } } } } ``` ```yaml title="Negative test num. 3 - yaml file" openapi: 3.0.0 info: title: Simple API overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: oAuth2AuthCodeNeg2: read:api responses: '200': description: 200 response content: application/json: components: securitySchemes: oAuth2AuthCodeNeg2: type: oauth2 description: For more information, see https://api.my.company.com/docs/oauth flows: authorizationCode: authorizationUrl: https://api.my.company.com/oauth/authorize tokenUrl: https://api.my.company.com/oauth/token scopes: read:api: read your apis ``` <details><summary>Negative test num. 4 - yaml file</summary> ```yaml openapi: 3.0.0 info: title: Simple API overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: oAuth2AuthCodeNeg2: read:api responses: '200': description: 200 response content: application/json: components: securitySchemes: oAuth2AuthCodeNeg2: type: oauth2 description: For more information, see https://api.my.company.com/docs/oauth flows: authorizationCode: authorizationUrl: https://api.my.company.com/oauth/authorize tokenUrl: https://api.my.company.com/oauth/token scopes: read:api: read your apis ``` </details>