Array Items Has No Type (v3)

  • Query id: be0e0df7-f3d9-42a1-9b6f-d425f94872c4
  • Query name: Array Items Has No Type (v3)
  • Platform: OpenAPI
  • Severity: Low
  • Category: Insecure Configurations
  • CWE: 665
  • URL: Github

Description

Schema array items type should be 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"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "$ref": "#/components/schemas/MyObject"
          },
          "201": {
            "description": "201 response",
            "content": {
              "application/x-www-form-urlencoded": {
                "schema": {
                  "type": "array",
                  "items": {
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/MyObject"
                      },
                      {
                        "type": "integer"
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "quantity": {
            "type": "integer",
            "format": "int32"
          },
          "percentage": {
            "type": "number",
            "format": "float"
          },
          "result": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "MyIntArray": {
        "type": "array",
        "items": {}
      }
    }
  }
}
Positive test num. 2 - 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": {
            "$ref": "#/components/schemas/MyObject"
          },
          "201": {
            "description": "201 response",
            "content": {
              "application/x-www-form-urlencoded": {
                "schema": {
                  "type": "array",
                  "items": {
                    "oneOf": []
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "quantity": {
            "type": "integer",
            "format": "int32"
          },
          "percentage": {
            "type": "number",
            "format": "float"
          },
          "result": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "MyIntArray": {
        "type": "array",
        "items": {
          "type": "integer"
        }
      }
    }
  }
}
Positive test num. 3 - 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": {
            "$ref": "#/components/schemas/MyObject"
          },
          "201": {
            "description": "201 response",
            "content": {
              "application/x-www-form-urlencoded": {
                "schema": {
                  "items": {
                    "oneOf": [
                      {
                        "type": "integer"
                      },
                      {
                        "format": "int32"
                      }
                    ]
                  },
                  "type": "array"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "quantity": {
            "type": "integer",
            "format": "int32"
          },
          "percentage": {
            "type": "number",
            "format": "float"
          },
          "result": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "MyIntArray": {
        "type": "array",
        "items": {
          "type": "integer"
        }
      }
    }
  }
}

Positive test num. 4 - 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":
          "$ref": "#/components/schemas/MyObject"
        "201":
          description: 201 response
          content:
            "application/x-www-form-urlencoded":
              schema:
                type: array
                items:
                  oneOf:
                    - "$ref": "#/components/schemas/MyObject"
                    - type: integer
components:
  schemas:
    MyObject:
      type: object
      properties:
        id:
          type: integer
          format: int64
        quantity:
          type: integer
          format: int32
        percentage:
          type: number
          format: float
        result:
          type: number
          format: double
    MyIntArray:
      type: array
      items: {}
Positive test num. 5 - 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":
          "$ref": "#/components/schemas/MyObject"
        "201":
          description: 201 response
          content:
            "application/x-www-form-urlencoded":
              schema:
                type: array
                items:
                  oneOf: []
components:
  schemas:
    MyObject:
      type: object
      properties:
        id:
          type: integer
          format: int64
        quantity:
          type: integer
          format: int32
        percentage:
          type: number
          format: float
        result:
          type: number
          format: double
    MyIntArray:
      type: array
      items:
        type: integer
Positive test num. 6 - 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":
          "$ref": "#/components/schemas/MyObject"
        "201":
          description: 201 response
          content:
            "application/x-www-form-urlencoded":
              schema:
                type: array
                items:
                  oneOf:
                    - type: integer
                    - format: int32
components:
  schemas:
    MyObject:
      type: object
      properties:
        id:
          type: integer
          format: int64
        quantity:
          type: integer
          format: int32
        percentage:
          type: number
          format: float
        result:
          type: number
          format: double
    MyIntArray:
      type: array
      items:
        type: integer
Positive test num. 7 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "201": {
            "description": "201 response"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "body",
            "description": "ID of pet to use",
            "required": true,
            "schema": {
              "type": "array",
              "items": {}
            }
          }
        ]
      }
    }
  }
}
Positive test num. 8 - yaml file
swagger: "2.0"
info:
  title: Simple API Overview
  version: 1.0.0
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "201":
          description: 201 response
      parameters:
        - name: id
          in: body
          description: ID of pet to use
          required: true
          schema:
            type: array
            items: {}

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": {
            "$ref": "#/components/schemas/MyObject"
          },
          "201": {
            "description": "201 response",
            "content": {
              "application/x-www-form-urlencoded": {
                "schema": {
                  "type": "array",
                  "items": {
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/MyObject"
                      },
                      {
                        "type": "integer"
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "quantity": {
            "type": "integer",
            "format": "int32"
          },
          "percentage": {
            "type": "number",
            "format": "float"
          },
          "result": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "MyIntArray": {
        "type": "array",
        "items": {
          "type": "integer"
        }
      }
    }
  }
}
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":
          "$ref": "#/components/schemas/MyObject"
        "201":
          description: 201 response
          content:
            "application/x-www-form-urlencoded":
              schema:
                type: array
                items:
                  oneOf:
                    - "$ref": "#/components/schemas/MyObject"
                    - type: integer
components:
  schemas:
    MyObject:
      type: object
      properties:
        id:
          type: integer
          format: int64
        quantity:
          type: integer
          format: int32
        percentage:
          type: number
          format: float
        result:
          type: number
          format: double
    MyIntArray:
      type: array
      items:
        type: integer
Negative test num. 3 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "201": {
            "description": "201 response"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "body",
            "description": "ID of pet to use",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ]
      }
    }
  }
}

Negative test num. 4 - yaml file
swagger: "2.0"
info:
  title: Simple API Overview
  version: 1.0.0
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "201":
          description: 201 response
    parameters:
      - name: id
        in: body
        description: ID of pet to use
        required: true
        schema:
          type: array
          items:
            type: string