Project: KICS (Provisioning / Security & Compliance)
File: 9d967a2b-9d64-41a6-abea-dfc4960299bd.md

title: JSON Object Schema Without Properties (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 9d967a2b-9d64-41a6-abea-dfc4960299bd Query name: JSON Object Schema Without Properties (v3) Platform: OpenAPI Severity: <span style="color:#ff7213">Medium</span> Category: Insecure Configurations URL: Schema of the JSON object should have properties defined and 'additionalProperties' set to false.<br> ```json title="Positive test num. 1 - json file" hl_lines="67" { "openapi": "3.0.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", "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": { "schemas": { "GeneralError": { "type": "object", "discriminator": { "propertyName": "petType" }, "required": [ "petType" ] } }, "requestBodies": { "NewItem": { "description": "A JSON object containing item data", "required": true, "content": { "multipart/form-data": { "schema": { "$ref": "#/components/schemas/GeneralError" } } } } } } } ``` ```json title="Positive test num. 2 - json file" hl_lines="16" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "responses": { "200": { "description": "200 response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GeneralError" }, "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" } ] } ] } } } } } } }, "operationId": "listVersionsv2", "summary": "List API versions" } } }, "components": { "schemas": { "GeneralError": { "discriminator": { "propertyName": "petType" }, "required": [ "petType" ], "type": "object" } } } } ``` ```yaml title="Positive test num. 3 - yaml file" hl_lines="40" 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 components: schemas: GeneralError: type: object discriminator: propertyName: petType required: petType requestBodies: NewItem: description: A JSON object containing item data required: true content: multipart/form-data: schema: $ref: "#/components/schemas/GeneralError" ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml 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: schema: $ref: "#/components/schemas/GeneralError" 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: schemas: GeneralError: type: object discriminator: propertyName: petType required: petType ``` </details> <details><summary>Positive test num. 5 - json file</summary> ```json hl_lines="16" { "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/GeneralError" } } } } } }, "definitions": { "GeneralError": { "type": "object", "discriminator": "petType", "required": [ "petType" ] } } } ``` </details> <details><summary>Positive test num. 6 - yaml file</summary> ```yaml hl_lines="14" 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/GeneralError" definitions: GeneralError: type: object discriminator: petType required: petType ``` </details> ```json title="Negative test num. 1 - json file" { "openapi":

"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", "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": { "schemas": { "GeneralError": { "type": "object", "discriminator": { "propertyName": "petType" }, "additionalProperties": false, "properties": { "code": { "type": "string", "format": "int32" }, "message": { "type": "string" } }, "required": [ "petType" ] } }, "requestBodies": { "NewItem": { "description": "A JSON object containing item data", "required": true, "content": { "multipart/form-data": { "schema": { "$ref": "#/components/schemas/GeneralError" } } } } } } } ``` ```json title="Negative test num. 2 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0", "contact": { "name": "contact", "url": "https://www.google.com/", "email": "user@gmail.com" } }, "paths": { "/": { "get": { "responses": { "200": { "description": "200 response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GeneralError" }, "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" } ] } ] } } } } } } }, "operationId": "listVersionsv2", "summary": "List API versions" } } }, "components": { "schemas": { "GeneralError": { "discriminator": { "propertyName": "petType" }, "additionalProperties": false, "properties": { "code": { "type": "string", "format": "int32" }, "message": { "type": "string" } }, "required": [ "petType" ], "type": "object" } } } } ``` ```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 components: schemas: GeneralError: type: object discriminator: propertyName: petType additionalProperties: false properties: code: type: string format: int32 message: type: string required: petType requestBodies: NewItem: description: A JSON object containing item data required: true content: multipart/form-data: schema: $ref: "#/components/schemas/GeneralError" ``` <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: schema: $ref: "#/components/schemas/GeneralError" 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: schemas: GeneralError: type: object discriminator: propertyName: petType additionalProperties: false properties: code: type: string format: int32 message: type: string required: petType ``` </details> <details><summary>Negative test num. 5 - 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/GeneralError" } } } } } }, "definitions": { "GeneralError": { "type": "object", "discriminator": "petType", "required": [ "petType" ], "properties": { "code": { "type": "string", "format": "int32" }, "message": { "type": "string" } } } } } ``` </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 responses: "200": description: 200 response schema: $ref: "#/definitions/GeneralError" definitions: GeneralError: type: object discriminator: petType required: petType properties: code: type: string format: int32 message: type: string ``` </details>