Project: KICS (Provisioning / Security & Compliance)
File: 12a7210b-f4b4-47d0-acac-0a819e2a0ca3.md

title: Response on operations that should not have a body has declared content (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 12a7210b-f4b4-47d0-acac-0a819e2a0ca3 Query name: Response on operations that should not have a body has declared content (v3) Platform: OpenAPI Severity: <span style="color:#edd57e">Low</span> Category: Networking and Firewall URL: If a response is head or its code is 204 or 304, it shouldn't have a content defined<br> ```json title="Positive test num. 1 - json file" hl_lines="29" { "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" } } }, "delete": { "operationId": "deleteVersion", "summary": "Deletes API versions", "responses": { "204": { "description": "has content", "content": { "application/json": { "schema": { "$ref": "#/components/ApiVersion" } } } } } } } }, "components": { "schemas": { "ApiVersion": { "type": "object", "discriminator": { "propertyName": "ApiVersion" }, "properties": { "code": { "type": "integer", "format": "int32" }, "version": { "type": "string" } } } } } } ``` ```json title="Positive test num. 2 - json file" hl_lines="20" { "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": { "/": { "head": { "operationId": "headers", "summary": "headers", "responses": { "200": { "description": "has content", "content": { "application/json": { "schema": { "$ref": "#/components/ApiVersion" } } } } } } } }, "components": { "schemas": { "ApiVersion": { "type": "object", "discriminator": { "propertyName": "ApiVersion" }, "properties": { "code": { "type": "integer", "format": "int32" }, "version": { "type": "string" } } } } } } ``` ```yaml title="Positive test num. 3 - yaml file" hl_lines="23" 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 delete: operationId: deleteVersion summary: Deletes API versions responses: "204": description: wrong example content: application/json: schema: "$ref": "#/components/ApiVersion" components: schemas: ApiVersion: type: object discriminator: propertyName: ApiVersion properties: code: type: integer format: int32 version: type: string ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="17" openapi: 3.0.0 info: title: Simple API Overview version:

contact: name: contact url: https://www.google.com/ email: user@gmail.com paths: "/": head: operationId: headers summary: headers responses: "200": description: wrong example content: application/json: schema: "$ref": "#/components/ApiVersion" components: schemas: ApiVersion: type: object discriminator: propertyName: ApiVersion properties: code: type: integer format: int32 version: type: string ``` </details> <details><summary>Positive test num. 5 - yaml file</summary> ```yaml hl_lines="13" swagger: "2.0" info: title: Simple API Overview version: 1.0.0 paths: "/": head: operationId: headers summary: headers responses: "200": description: wrong example schema: type: object discriminator: propertyName: ApiVersion properties: code: type: integer format: int32 version: type: string ``` </details> <details><summary>Positive test num. 6 - json file</summary> ```json hl_lines="15" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "head": { "operationId": "headers", "summary": "headers", "responses": { "200": { "description": "wrong example", "schema": { "type": "object", "discriminator": { "propertyName": "ApiVersion" }, "properties": { "code": { "type": "integer", "format": "int32" }, "version": { "type": "string" } } } } } } } } } ``` </details> ```json title="Negative test num. 1 - 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": { "/": { "delete": { "operationId": "deleteVersion", "summary": "Deletes API versions", "responses": { "204": { "description": "no content" } } }, "head": { "operationId": "headers", "summary": "headers", "responses": { "200": { "description": "no content" } } } } } } ``` ```yaml title="Negative test num. 2 - yaml 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: "/": delete: operationId: deleteVersion summary: Deletes API versions responses: "204": description: no content head: operationId: headers summary: headers responses: "200": description: no content ``` ```json title="Negative test num. 3 - json file" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "delete": { "operationId": "deleteVersion", "summary": "Deletes API versions", "responses": { "204": { "description": "no content" } } }, "head": { "operationId": "headers", "summary": "headers", "responses": { "200": { "description": "no content" } } } } } } ``` <details><summary>Negative test num. 4 - yaml file</summary> ```yaml swagger: "2.0" info: title: Simple API Overview version: 1.0.0 paths: "/": delete: operationId: deleteVersion summary: Deletes API versions responses: "204": description: no content head: operationId: headers summary: headers responses: "200": description: no content ``` </details>