Project: KICS (Provisioning / Security & Compliance)
File: 96729c6b-7400-4d9e-9807-17f00cdde4d2.md

title: No Global And Operation Security Defined (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 96729c6b-7400-4d9e-9807-17f00cdde4d2 Query name: No Global And Operation Security Defined (v3) Platform: OpenAPI Severity: <span style="color:#bb2124">High</span> Category: Access Control URL: All paths should have security scheme, if it is omitted, global security field should be defined<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" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "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" } ] } ] } } } } } } } } } } } ``` ```json title="Positive test num. 2 - json file" hl_lines="46" { "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [ { "exampleSecurity": [] } ], "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", "responses": { "204": { "description": "204 response" } } } } }, "components": { "exampleSecurity": { "type": "http", "scheme": "basic" } } } ``` ```yaml title="Positive test num. 3 - yaml file" hl_lines="7" openapi: 3.0.0 info: title: Simple API version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions 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 ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="27" openapi: 3.0.0 info: title: Simple API overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: exampleSecurity: [] 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 responses: '204': description: 204 response components: exampleSecurity: type: http scheme: basic ``` </details> <details><summary>Positive test num. 5 - yaml file</summary> ```yaml hl_lines="7" 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 schema: $ref: "#/definitions/User" ``` </details> <details><summary>Positive test num. 6 - json file</summary> ```json hl_lines="9" { "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", "schema": { "$ref": "#/definitions/User" } } } } } } } ``` </details> ```json title="Negative test num. 1 - json file" { "openapi":

"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": { "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":[ { "exampleSecurity": [] } ], "components": { "exampleSecurity": { "type": "http", "scheme": "basic" } } } ``` ```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": [ { "exampleSecurity": [] } ], "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" } ] } ] } } } } } } } } } }, "components": { "exampleSecurity": { "type": "http", "scheme": "basic" } } } ``` ```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: 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: exampleSecurity: [] components: exampleSecurity: type: http scheme: basic ``` <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: exampleSecurity: [] 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 components: exampleSecurity: type: http scheme: basic ``` </details> <details><summary>Negative test num. 5 - 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 schema: $ref: "#/definitions/User" security: exampleSecurity: [] ``` </details> <details><summary>Negative test num. 6 - yaml file</summary> ```yaml swagger: "2.0" info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions security: exampleSecurity: [] responses: "200": description: 200 response schema: $ref: "#/definitions/User" ``` </details> <details><summary>Negative test num. 7 - json file</summary> ```json { "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", "schema": { "$ref": "#/definitions/User" } } } } } }, "security": [ { "exampleSecurity": [] } ] } ``` </details> <details><summary>Negative test num. 8 - json file</summary> ```json { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "security": [ { "exampleSecurity": [] } ], "responses": { "200": { "description": "200 response", "schema": { "$ref": "#/definitions/User" } } } } } } } ``` </details>