Project: KICS (Provisioning / Security & Compliance)
File: a599b0d1-ff89-4cb8-9ece-9951854c06f6.md

title: Security Requirement Not Defined In Security Definition hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: a599b0d1-ff89-4cb8-9ece-9951854c06f6 Query name: Security Requirement Not Defined In Security Definition Platform: OpenAPI Severity: <span style="color:#bb2124">High</span> Category: Structure and Semantics URL: All security requirement objects must be defined in 'securityDefinitions'<br> ```json title="Positive test num. 1 - json file" hl_lines="33" { "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" } }, "parameters": [ { "name": "limit2", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "object" } } ] } } }, "security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ], "securityDefinitions": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" } } } ``` ```yaml title="Positive test num. 2 - yaml file" hl_lines="21" 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 parameters: name: limit2 in: body description: max records to return required: true schema: type: object security: petstore_auth: write:pets read:pets securityDefinitions: api_key: type: apiKey name: api_key in: header ``` ```json title="Positive test num. 3 - json file" hl_lines="30" { "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" } }, "parameters": [ { "name": "limit2", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "object" } } ], "security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ] } } }, "securityDefinitions": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" } } } ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="21" 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 parameters: name: limit2 in: body description: max records to return required: true schema: type: object security: petstore_auth: write:pets read:pets securityDefinitions: api_key: type: apiKey name: api_key in: header ``` </details> ```json title="Negative test

1 - 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" } }, "parameters": [ { "name": "limit2", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "object" } } ] } } }, "security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ], "securityDefinitions": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "authorizationUrl": "http://swagger.io/api/oauth/dialog", "flow": "implicit", "scopes": { "write:pets": "modify pets in your account", "read:pets": "read your pets" } } } } ``` ```yaml title="Negative test num. 2 - yaml 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 parameters: name: limit2 in: body description: max records to return required: true schema: type: object security: petstore_auth: write:pets read:pets securityDefinitions: api_key: type: apiKey name: api_key in: header petstore_auth: type: oauth2 authorizationUrl: http://swagger.io/api/oauth/dialog flow: implicit scopes: write:pets: modify pets in your account read:pets: read your pets ``` ```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" } }, "parameters": [ { "name": "limit2", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "object" } } ], "security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ] } } }, "securityDefinitions": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "authorizationUrl": "http://swagger.io/api/oauth/dialog", "flow": "implicit", "scopes": { "write:pets": "modify pets in your account", "read:pets": "read your pets" } } } } ``` <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 parameters: name: limit2 in: body description: max records to return required: true schema: type: object security: petstore_auth: write:pets read:pets securityDefinitions: api_key: type: apiKey name: api_key in: header petstore_auth: type: oauth2 authorizationUrl: http://swagger.io/api/oauth/dialog flow: implicit scopes: write:pets: modify pets in your account read:pets: read your pets ``` </details>