Project: KICS (Provisioning / Security & Compliance)
File: 37140f7f-724a-4c87-a536-e9cee1d61533.md

title: Security Requirement Object With Wrong Scopes hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 37140f7f-724a-4c87-a536-e9cee1d61533 Query name: Security Requirement Object With Wrong Scopes Platform: OpenAPI Severity: <span style="color:#5bc0de">Info</span> Category: Structure and Semantics URL: Security Requirement Object should only have scopes defined for security schemes of type 'oauth2' and 'openIdConnect'<br> ```json title="Positive test num. 1 - json file" hl_lines="9" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "security": [ { "api_key": [ "write:api", "read:api" ] }, { "petstore_auth": [ "write:pets", "read:pets" ] } ], "paths": {}, "components": { "securitySchemes": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "flows": { "implicit": { "authorizationUrl": "http://example.org/api/oauth/dialog", "scopes": { "write:pets": "modify pets in your account", "read:pets": "read your pets" } } } } } } } ``` ```yaml title="Positive test num. 2 - yaml file" hl_lines="6" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 security: api_key: write:pets read:pets petstore_auth: write:pets read:pets paths: {} components: securitySchemes: api_key: type: apiKey name: api_key in: header petstore_auth: type: oauth2 flows: implicit: authorizationUrl: http://example.org/api/oauth/dialog scopes: write:pets: modify pets in your account read:pets: read your pets ``` ```json title="Positive test num. 3 - json file" hl_lines="28" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/pets": { "get": { "description": "Returns all pets from the system that the user has access to", "responses": { "200": { "description": "A list of pets.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/pet" } } } } } }, "security": [ { "api_key": [ "write:pets", "read:pets" ] }, { "petstore_auth": [ "write:pets", "read:pets" ] } ] } } }, "components": { "securitySchemes": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "flows": { "implicit": { "authorizationUrl": "http://example.org/api/oauth/dialog", "scopes": { "write:pets": "modify pets in your account", "read:pets": "read your pets" } } } } } } } ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="19" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/pets": get: description: Returns all pets from the system that the user has access to responses: "200": description: A list of

content: application/json: schema: type: array items: "$ref": "#/components/schemas/pet" security: api_key: write:pets read:pets petstore_auth: write:pets read:pets components: securitySchemes: api_key: type: apiKey name: api_key in: header petstore_auth: type: oauth2 flows: implicit: authorizationUrl: http://example.org/api/oauth/dialog scopes: write:pets: modify pets in your account read:pets: read your pets ``` </details> ```json title="Negative test num. 1 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "security": [ { "api_key": [] }, { "petstore_auth": [ "write:pets", "read:pets" ] } ], "paths": {}, "components": { "securitySchemes": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "flows": { "implicit": { "authorizationUrl": "http://example.org/api/oauth/dialog", "scopes": { "write:pets": "modify pets in your account", "read:pets": "read your pets" } } } } } } } ``` ```yaml title="Negative test num. 2 - yaml file" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 security: api_key: [] petstore_auth: write:pets read:pets paths: {} components: securitySchemes: api_key: type: apiKey name: api_key in: header petstore_auth: type: oauth2 flows: implicit: authorizationUrl: http://example.org/api/oauth/dialog scopes: write:pets: modify pets in your account read:pets: read your pets ``` ```json title="Negative test num. 3 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/pets": { "get": { "description": "Returns all pets from the system that the user has access to", "responses": { "200": { "description": "A list of pets.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/pet" } } } } } }, "security": [ { "api_key": [] }, { "petstore_auth": [ "write:pets", "read:pets" ] } ] } } }, "components": { "securitySchemes": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "flows": { "implicit": { "authorizationUrl": "http://example.org/api/oauth/dialog", "scopes": { "write:pets": "modify pets in your account", "read:pets": "read your pets" } } } } } } } ``` <details><summary>Negative test num. 4 - yaml file</summary> ```yaml openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/pets": get: description: Returns all pets from the system that the user has access to responses: "200": description: A list of pets. content: application/json: schema: type: array items: "$ref": "#/components/schemas/pet" security: api_key: [] petstore_auth: write:pets read:pets components: securitySchemes: api_key: type: apiKey name: api_key in: header petstore_auth: type: oauth2 flows: implicit: authorizationUrl: http://example.org/api/oauth/dialog scopes: write:pets: modify pets in your account read:pets: read your pets ``` </details>