Invalid Content Type For Multiple Files Upload

  • Query id: 26f06397-36d8-4ce7-b993-17711261d777
  • Query name: Invalid Content Type For Multiple Files Upload
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • CWE: 20
  • URL: Github

Description

Content Type should be set to 'multipart/form-data' in case of uploading an arbitrary number of files (array)
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",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "filename": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Positive test num. 2 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "email": "user@gmail.com"
    }
  },
  "components": {
    "requestBodies": {
      "CreateCustomer": {
        "description": "Create a new customer",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "filename": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Positive test num. 3 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: "contact"
    email: "user@gmail.com"
paths:
  "/":
    get:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                filename:
                  type: array
                  items:
                    type: string
                    format: binary

Positive test num. 4 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: "contact"
    email: "user@gmail.com"
components:
  requestBodies:
    CreateCustomer:
      description: Create a new customer
      content:
        application/json:
          schema:
            type: object
            properties:
              filename:
                type: array
                items:
                  type: string
                  format: binary

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",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "filename": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Negative test num. 2 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "email": "user@gmail.com"
    }
  },
  "components": {
    "requestBodies": {
      "CreateCustomer": {
        "description": "Create a new customer",
        "content": {
          "multipart/form-data": {
            "schema": {
              "type": "object",
              "properties": {
                "filename": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Negative test num. 3 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: "contact"
    email: "user@gmail.com"
paths:
  "/":
    get:
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                filename:
                  type: array
                  items:
                    type: string
                    format: binary

Negative test num. 4 - yaml file
openapi: 3.0.0
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: "contact"
    email: "user@gmail.com"
components:
  requestBodies:
    CreateCustomer:
      description: Create a new customer
      content:
        multipart/form-data:
          schema:
            type: object
            properties:
              filename:
                type: array
                items:
                  type: string
                  format: binary