Response on operations that should have a body has undefined schema (v3)
- Query id: a92be1d5-d762-484a-86d6-8cd0907ba100
- Query name: Response on operations that should have a body has undefined schema (v3)
- Platform: OpenAPI
- Severity: Medium
- Category: Networking and Firewall
- CWE: 665
- URL: Github
Description¶
If a response is not head or its code is not 204 or 304, it should have a schema defined
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Positive 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": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
}
},
"delete": {
"operationId": "deleteVersion",
"summary": "Deletes API versions",
"responses": {
"204": {
"description": "no content"
}
}
}
}
},
"components": {
"schemas": {
"ApiVersion": {
"type": "object",
"discriminator": {
"propertyName": "ApiVersion"
},
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"version": {
"type": "string"
}
}
}
}
}
}
Positive test num. 2 - 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
responses:
"200":
description: 200 response
delete:
operationId: deleteVersion
summary: Deletes API versions
responses:
"204":
description: no content
Positive test num. 3 - 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": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {}
}
}
}
},
"delete": {
"operationId": "deleteVersion",
"summary": "Deletes API versions",
"responses": {
"204": {
"description": "no content"
}
}
}
}
},
"components": {
"schemas": {
"ApiVersion": {
"type": "object",
"discriminator": {
"propertyName": "ApiVersion"
},
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"version": {
"type": "string"
}
}
}
}
}
}
Positive test num. 4 - 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": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/pdf": {},
"application/json": {}
}
}
}
},
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiVersion"
}
}
}
}
}
},
"delete": {
"operationId": "deleteVersion",
"summary": "Deletes API versions",
"responses": {
"204": {
"description": "no content"
}
}
}
}
},
"components": {
"schemas": {
"ApiVersion": {
"type": "object",
"discriminator": {
"propertyName": "ApiVersion"
},
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"version": {
"type": "string"
}
}
}
}
}
}
Positive test num. 5 - 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": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {}
}
}
},
"delete": {
"operationId": "deleteVersion",
"summary": "Deletes API versions",
"responses": {
"204": {
"description": "no content"
}
}
}
}
},
"components": {
"schemas": {
"ApiVersion": {
"type": "object",
"discriminator": {
"propertyName": "ApiVersion"
},
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"version": {
"type": "string"
}
}
}
}
}
}
Positive test num. 6 - 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:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
delete:
operationId: deleteVersion
summary: Deletes API versions
responses:
"204":
description: no content
components:
schemas:
ApiVersion:
type: object
discriminator:
propertyName: ApiVersion
properties:
code:
type: integer
format: int32
version:
type: string
Positive test num. 7 - 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:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
content:
application/json: {}
delete:
operationId: deleteVersion
summary: Deletes API versions
responses:
"204":
description: no content
components:
schemas:
ApiVersion:
type: object
discriminator:
propertyName: ApiVersion
properties:
code:
type: integer
format: int32
version:
type: string
Positive test num. 8 - 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:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
content:
application/pdf: {}
application/json: {}
post:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
content:
application/json:
schema:
"$ref": "#/components/schemas/ApiVersion"
delete:
operationId: deleteVersion
summary: Deletes API versions
responses:
"204":
description: no content
components:
schemas:
ApiVersion:
type: object
discriminator:
propertyName: ApiVersion
properties:
code:
type: integer
format: int32
version:
type: string
Positive test num. 9 - 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:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
content: {}
delete:
operationId: deleteVersion
summary: Deletes API versions
responses:
"204":
description: no content
components:
schemas:
ApiVersion:
type: object
discriminator:
propertyName: ApiVersion
properties:
code:
type: integer
format: int32
version:
type: string
Positive test num. 10 - json 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",
"responses": {
"200": {
"description": "200 response"
}
}
},
"delete": {
"operationId": "deleteVersion",
"summary": "Deletes API versions",
"responses": {
"204": {
"description": "no content"
}
}
}
}
}
}
Code samples without security vulnerabilities¶
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": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiVersion"
}
}
}
}
}
},
"delete": {
"operationId": "deleteVersion",
"summary": "Deletes API versions",
"responses": {
"204": {
"description": "no content"
}
}
}
}
},
"components": {
"schemas": {
"ApiVersion": {
"type": "object",
"discriminator": {
"propertyName": "ApiVersion"
},
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"version": {
"type": "string"
}
}
}
}
}
}
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:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
content:
application/json:
schema:
"$ref": "#/components/schemas/ApiVersion"
delete:
operationId: deleteVersion
summary: Deletes API versions
responses:
"204":
description: no content
components:
schemas:
ApiVersion:
type: object
discriminator:
propertyName: ApiVersion
properties:
code:
type: integer
format: int32
version:
type: string
Negative test num. 3 - json 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",
"responses": {
"200": {
"description": "200 response",
"schema": {
"type": "object",
"discriminator": "ApiVersion",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"version": {
"type": "string"
}
}
}
}
}
},
"delete": {
"operationId": "deleteVersion",
"summary": "Deletes API versions",
"responses": {
"204": {
"description": "no content"
}
}
}
}
}
}
Negative test num. 4 - 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
responses:
"200":
description: 200 response
schema:
type: object
discriminator: ApiVersion
properties:
code:
type: integer
format: int32
version:
type: string
delete:
operationId: deleteVersion
summary: Deletes API versions
responses:
"204":
description: no content
Negative test num. 5 - json file
{
"openapi": "3.0.1",
"info": {
"title": "Test",
"description": "test",
"version": "1.0"
},
"servers": [
{
"url": "https://example.com",
"description": "Example"
}
],
"paths": {
"/Header/{SourceID}": {
"get": {
"summary": "Forecast Header Updates",
"description": "Get Forecast Header channel data from MDM for a given source.",
"operationId": "GetForecastHeader",
"parameters": [],
"responses": {
"200": {
"description": "",
"headers": {
"x-test-forecasts-ack-id": {
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForecastHeaders"
}
},
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ForecastHeaders"
},
"examples": {
"default": {
"value": null
}
}
}
}
},
"204": {
"description": "There are no more updates available."
}
}
}
},
"/Detail/{SourceID}": {
"get": {
"summary": "Forecast Detail Updates",
"description": "Get Forecast Header channel data from MDM for a given source.",
"operationId": "GetForecastDetail",
"parameters": [],
"responses": {
"200": {
"description": "",
"headers": {
"x-test-forecastdetails-ack-id": {
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForecastDetails"
}
},
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ForecastDetails"
},
"examples": {
"default": {
"value": null
}
}
}
}
},
"204": {
"description": "There are no more updates available."
}
}
}
}
},
"components": {
"schemas": {
},
"securitySchemes": {
"apiKeyHeader": {
"type": "apiKey",
"name": "Ocp-Apim-Subscription-Key",
"in": "header"
}
}
},
"security": [
{
"apiKeyHeader": []
},
{
"apiKeyQuery": []
}
]
}