Default Response Undefined On Operations (v3)
- Query id: 86e3702f-c868-44b2-b61d-ea5316c18110
- Query name: Default Response Undefined On Operations (v3)
- Platform: OpenAPI
- Severity: Medium
- Category: Networking and Firewall
- URL: Github
Description¶
Operations responses should have a default response defined
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Positive test num. 1 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API",
"version": "1.0.0"
},
"paths": {
"/item": {
"patch": {
"operationId": "updateItem",
"summary": "Updated item",
"responses": {
"204": {
"description": "Item deleted successfully"
}
}
}
}
},
"components": {
"schemas": {
"Error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"code",
"message"
]
}
}
}
}
Positive test num. 2 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API",
"version": "1.0.0"
},
"paths": {
"/item": {
"delete": {
"operationId": "deleteItem",
"summary": "Delete item",
"responses": {
"204": {
"description": "Item deleted successfully"
}
}
},
"patch": {
"operationId": "updateItem",
"summary": "Update item",
"responses": {
"204": {
"description": "Item updated successfully"
}
}
}
}
},
"components": {
"schemas": {
"Error": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"code",
"message"
]
}
}
}
}
Positive test num. 3 - yaml file
openapi: 3.0.0
info:
title: Simple API
version: 1.0.0
paths:
"/item":
patch:
operationId: updateItem
summary: Updated item
responses:
'204':
description: Item deleted successfully
components:
schemas:
Error:
type: object
properties:
code:
type: string
message:
type: string
required:
- code
- message
Positive test num. 4 - yaml file
openapi: 3.0.0
info:
title: Simple API
version: 1.0.0
paths:
"/item":
delete:
operationId: deleteItem
summary: Delete item
responses:
'204':
description: Item deleted successfully
patch:
operationId: updateItem
summary: Update item
responses:
'204':
description: Item updated successfully
components:
schemas:
Error:
type: object
properties:
code:
type: string
message:
type: string
required:
- code
- message
Positive test num. 5 - json file
{
"swagger": "20",
"info": {
"title": "Simple API",
"version": "1.0.0"
},
"paths": {
"/item": {
"delete": {
"operationId": "deleteItem",
"summary": "Delete item",
"responses": {
"204": {
"description": "Item deleted successfully"
}
}
},
"patch": {
"operationId": "updateItem",
"summary": "Update item",
"responses": {
"204": {
"description": "Item updated successfully"
}
}
}
}
}
}
Positive test num. 6 - yaml file
Code samples without security vulnerabilities¶
Negative test num. 1 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API",
"version": "1.0.0"
},
"paths": {
"/item": {
"delete": {
"operationId": "deleteItem",
"summary": "Delete item",
"responses": {
"204": {
"description": "Item deleted successfully"
},
"default": {
"description": "Error"
}
}
},
"patch": {
"operationId": "updateItem",
"summary": "Update item",
"responses": {
"204": {
"description": "Item updated successfully"
},
"default": {
"description": "Error"
}
}
}
}
}
}
Negative test num. 2 - yaml file
openapi: 3.0.0
info:
title: Simple API
version: 1.0.0
paths:
"/item":
delete:
operationId: deleteItem
summary: Delete item
responses:
"204":
description: Item deleted successfully
default:
description: Error
patch:
operationId: updateItem
summary: Update item
responses:
"204":
description: Item updated successfully
default:
description: Error
Negative test num. 3 - json file
{
"swagger": "2.0",
"info": {
"title": "Simple API",
"version": "1.0.0"
},
"paths": {
"/item": {
"delete": {
"operationId": "deleteItem",
"summary": "Delete item",
"responses": {
"204": {
"description": "Item deleted successfully"
},
"default": {
"description": "Error"
}
}
},
"patch": {
"operationId": "updateItem",
"summary": "Update item",
"responses": {
"204": {
"description": "Item updated successfully"
},
"default": {
"description": "Error"
}
}
}
}
}
}
Negative test num. 4 - yaml file
swagger: "2.0"
info:
title: Simple API
version: 1.0.0
paths:
"/item":
delete:
operationId: deleteItem
summary: Delete item
responses:
"204":
description: Item deleted successfully
default:
description: Error
patch:
operationId: updateItem
summary: Update item
responses:
"204":
description: Item updated successfully
default:
description: Error