Components Header Definition Is Unused
- Query id: a68da022-e95a-4bc2-97d3-481e0bd6d446
- Query name: Components Header Definition Is Unused
- Platform: OpenAPI
- Severity: Info
- Category: Best Practices
- URL: Github
Description¶
Components headers definitions should be referenced or removed from Open API definition
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"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"headers": {
"xPages": {
"schema": {
"type": "integer",
"description": "number of pages"
}
}
}
}
}
Positive test num. 2 - 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: success
content:
application/json:
schema:
type: array
items:
"$ref": "#/components/schemas/MyObject"
components:
schemas:
MyObject:
type: object
properties:
id:
type: string
name:
type: string
headers:
xPages:
schema:
type: integer
description: number of pages
Code samples without security vulnerabilities¶
Negative test num. 1 - json 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": "success",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
},
"headers": {
"X-Pages": {
"$ref": "#/components/headers/xPages"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"headers": {
"xPages": {
"schema": {
"type": "integer",
"description": "number of pages"
}
}
}
}
}
Negative test num. 2 - 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: success
content:
application/json:
schema:
type: array
items:
"$ref": "#/components/schemas/MyObject"
headers:
X-Pages:
"$ref": "#/components/headers/xPages"
components:
schemas:
MyObject:
type: object
properties:
id:
type: string
name:
type: string
headers:
xPages:
schema:
type: integer
description: number of pages