Project: KICS (Provisioning / Security & Compliance)
File: 23a9e2d9-8738-4556-a71c-2802b6ffa022.md

title: Undefined Scope 'securityScheme' On Global 'security' Field hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 23a9e2d9-8738-4556-a71c-2802b6ffa022 Query name: Undefined Scope 'securityScheme' On Global 'security' Field Platform: OpenAPI Severity: <span style="color:#edd57e">Low</span> Category: Access Control URL: Using an scope on global security field that is undefined on 'securityScheme' can be defined by an attacker<br> ```json title="Positive test num. 1 - json file" hl_lines="24" { "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": null } } } } } }, "security": { "oAuth2AuthCodeNeg2": [ "read:api", "error:api" ] }, "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="25" { "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": null } } } } } }, "security": [ { "oAuth2AuthCodeNeg2": [ "error:api", "write:api" ] } ], "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="16" 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: security: oAuth2AuthCodeNeg2: read:api error:api 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="16" openapi: 3.0.0 info: title: Simple API overview version:

paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: '200': description: 200 response content: application/json: security: oAuth2AuthCodeNeg2: error:api write:api 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", "responses": { "200": { "description": "200 response", "content": { "application/json": null } } } } } }, "security": [ { "oAuth2AuthCodeNeg2": [ "read:api", "write:api" ] } ], "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", "responses": { "200": { "description": "200 response", "content": { "application/json": null } } } } } }, "security": { "oAuth2AuthCodeNeg2": [ "read:api", "write:api" ] }, "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 responses: '200': description: 200 response content: application/json: security: oAuth2AuthCodeNeg2: read:api write:api 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>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 responses: '200': description: 200 response content: application/json: security: oAuth2AuthCodeNeg2: read:api write:api 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>