Project: KICS (Provisioning / Security & Compliance)
File: 663c442d-f918-4f62-b096-0bf5dcbeb655.md

title: Security Field On Operations Has An Empty Array (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 663c442d-f918-4f62-b096-0bf5dcbeb655 Query name: Security Field On Operations Has An Empty Array (v3) Platform: OpenAPI Severity: <span style="color:#bb2124">High</span> Category: Access Control URL: Security object for operations, if defined, must define a security scheme, otherwise it should be considered an error<br> ```json title="Positive test num. 1 - json file" hl_lines="12" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [], "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": [ "read" ] } ] } ``` ```json title="Positive test num. 2 - json file" hl_lines="17" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0", "contact": { "name": "contact", "url": "https://www.google.com/", "email": "user@gmail.com" } }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [], "responses": { "200": { "description": "200 response", "schema": { "type": "object", "properties": { "code": { "type": "integer", "format": "int32" }, "message": { "type": "string" } }, "required": [ "code", "message" ] } } } } } } } ``` ```json title="Positive test num. 3 - json file" hl_lines="51" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [ { "OAuth2": [ "admin" ] } ], "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" } ] } ] } } } } } } } }, "patch": { "operationId": "validateVersionsPathv2", "summary": "Validate operation", "security": [], "responses": { "204": { "description": "204 response" } } } } }, "security": [ { "OAuth2": [ "read" ] } ] } ``` <details><summary>Positive test num. 4 - json file</summary> ```json hl_lines="51" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version":

}, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [ { "OAuth2": [ "admin" ] } ], "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" } ] } ] } } } } } } } }, "patch": { "operationId": "validateVersionsPathv2", "summary": "Validate operation", "security": [], "responses": { "204": { "description": "204 response" } } } } }, "security": [ { "OAuth2": [ "read" ] } ] } ``` </details> <details><summary>Positive test num. 5 - json file</summary> ```json hl_lines="53" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [ { "OAuth2": [ "admin" ] } ], "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" } ] } ] } } } } } } } } }, "/apis": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [], "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": [ "read" ] } ] } ``` </details> <details><summary>Positive test num. 6 - yaml file</summary> ```yaml hl_lines="10" openapi: 3.0.0 info: title: Simple API overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: [] 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: read ``` </details> <details><summary>Positive test num. 7 - yaml file</summary> ```yaml hl_lines="31" openapi: 3.0.0 info: title: Simple API overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: OAuth2: admin 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 patch: operationId: validateVersionsPathv2 summary: Validate operation security: [] responses: '204': description: 204 response security: OAuth2: read ``` </details> <details><summary>Positive test num. 8 - yaml file</summary> ```yaml hl_lines="31" openapi: 3.0.0 info: title: Simple API overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: OAuth2: admin 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 patch: operationId: validateVersionsPathv2 summary: Validate operation security: [] responses: '204': description: 204 response security: OAuth2: read ``` </details> <details><summary>Positive test num. 9 - yaml file</summary> ```yaml hl_lines="32" openapi: 3.0.0 info: title: Simple API overview version:

paths: "/": get: operationId: listVersionsv2 summary: List API versions security: OAuth2: admin 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 "/apis": get: operationId: listVersionsv2 summary: List API versions security: [] 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: read ``` </details> <details><summary>Positive test num. 10 - yaml file</summary> ```yaml hl_lines="14" swagger: "2.0" info: title: Simple API Overview version: 1.0.0 contact: name: contact url: https://www.google.com/ email: user@gmail.com paths: "/": get: operationId: listVersionsv2 summary: List API versions security: [] responses: "200": description: 200 response schema: type: object properties: code: type: integer format: int32 message: type: string required: code message ``` </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": [ { "OAuth2": [ "write" ] } ], "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": [ "read" ] } ] } ``` ```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 security: OAuth2: write 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: read ``` ```yaml title="Negative test num. 3 - yaml file" swagger: "2.0" info: title: Simple API Overview version: 1.0.0 contact: name: contact url: https://www.google.com/ email: user@gmail.com paths: "/": get: operationId: listVersionsv2 summary: List API versions security: OAuth2: write responses: "200": description: 200 response schema: type: object properties: code: type: integer format: int32 message: type: string required: code message ``` <details><summary>Negative test num. 4 - json file</summary> ```json { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0", "contact": { "name": "contact", "url": "https://www.google.com/", "email": "user@gmail.com" } }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [ { "OAuth2": [ "write" ] } ], "responses": { "200": { "description": "200 response", "schema": { "type": "object", "properties": { "code": { "type": "integer", "format": "int32" }, "message": { "type": "string" } }, "required": [ "code", "message" ] } } } } } } } ``` </details>