Parameter Object Content With Multiple Entries

  • Query id: 8bfed1c6-2d59-4924-bc7f-9b9d793ed0df
  • Query name: Parameter Object Content With Multiple Entries
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • URL: Github

Description

The map content property of the parameter object should only contain one entry
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": {
        "summary": "List API versions",
        "parameters": [
          {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                },
                "examples": {
                  "user": {
                    "summary": "User Example",
                    "externalValue": "http://foo.bar/examples/user-example.json"
                  }
                }
              },
              "application/xml": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                },
                "examples": {
                  "user": {
                    "summary": "User Example in XML",
                    "externalValue": "http://foo.bar/examples/user-example.xml"
                  }
                }
              }
            },
            "name": "id",
            "in": "path",
            "description": "ID of the API version",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "rel": "self",
                              "href": "http://127.0.0.1:8774/v2/"
                            }
                          ],
                          "status": "CURRENT"
                        }
                      ]
                    }
                  }
                }
              }
            },
            "description": "200 response"
          }
        },
        "operationId": "listVersionsv2"
      }
    },
    "/user/{id}": {
      "parameters": [
        {
          "description": "ID of the API version",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/User"
              },
              "examples": {
                "user": {
                  "summary": "User Example",
                  "externalValue": "http://foo.bar/examples/user-example.json"
                }
              }
            },
            "application/xml": {
              "schema": {
                "$ref": "#/components/schemas/User"
              },
              "examples": {
                "user": {
                  "summary": "User Example in XML",
                  "externalValue": "http://foo.bar/examples/user-example.xml"
                }
              }
            }
          },
          "name": "id",
          "in": "path"
        }
      ]
    }
  }
}
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": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "idParam": {
        "name": "id",
        "in": "path",
        "description": "ID of the API version",
        "required": true,
        "schema": {
          "type": "int"
        },
        "content": {
          "application/xml": {
            "examples": {
              "user": {
                "externalValue": "http://foo.bar/examples/user-example.xml",
                "summary": "User Example in XML"
              }
            },
            "schema": {
              "$ref": "#/components/schemas/User"
            }
          },
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/User"
            },
            "examples": {
              "user": {
                "externalValue": "http://foo.bar/examples/user-example.json",
                "summary": "User Example"
              }
            }
          }
        }
      }
    }
  }
}
Positive test num. 3 - yaml file
openapi: 3.0.0
info:
  title: Simple API overview
  version: 1.0.0
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      parameters:
        - name: id
          in: path
          description: ID of the API version
          required: true
          schema:
            type: integer
          content:
            "application/json":
              schema:
                $ref: "#/components/schemas/User"
              examples:
                user:
                  summary: User Example
                  externalValue: "http://foo.bar/examples/user-example.json"
            "application/xml":
              schema:
                $ref: "#/components/schemas/User"
              examples:
                user:
                  summary: User Example in XML
                  externalValue: "http://foo.bar/examples/user-example.xml"
      responses:
        "200":
          description: 200 response
          content:
            application/json:
              examples:
                foo:
                  value:
                    versions:
                      - status: CURRENT
                        updated: "2011-01-21T11:33:21Z"
                        id: v2.0
                        links:
                          - href: http://127.0.0.1:8774/v2/
                            rel: self
  /user/{id}:
    parameters:
      - name: id
        in: path
        description: ID of the API version
        required: true
        schema:
          type: integer
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/User"
            examples:
              user:
                summary: User Example
                externalValue: "http://foo.bar/examples/user-example.json"
          "application/xml":
            schema:
              $ref: "#/components/schemas/User"
            examples:
              user:
                summary: User Example in XML
                externalValue: "http://foo.bar/examples/user-example.xml"

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":
          description: 200 response
          content:
            application/json:
              examples:
                foo:
                  value:
                    versions:
                      - status: CURRENT
                        updated: "2011-01-21T11:33:21Z"
                        id: v2.0
                        links:
                          - href: http://127.0.0.1:8774/v2/
                            rel: self
components:
  parameters:
    idParam:
      name: id
      in: path
      description: ID of the API version
      required: true
      schema:
        type: int
      content:
        "application/json":
          schema:
            $ref: "#/components/schemas/User"
          examples:
            user:
              summary: User Example
              externalValue: "http://foo.bar/examples/user-example.json"
        "application/xml":
          schema:
            $ref: "#/components/schemas/User"
          examples:
            user:
              summary: User Example in XML
              externalValue: "http://foo.bar/examples/user-example.xml"

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": {
        "summary": "List API versions",
        "parameters": [
          {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                },
                "examples": {
                  "user": {
                    "summary": "User Example",
                    "externalValue": "http://foo.bar/examples/user-example.json"
                  }
                }
              }
            },
            "name": "id",
            "in": "path",
            "description": "ID of the API version",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "rel": "self",
                              "href": "http://127.0.0.1:8774/v2/"
                            }
                          ],
                          "status": "CURRENT"
                        }
                      ]
                    }
                  }
                }
              }
            },
            "description": "200 response"
          }
        },
        "operationId": "listVersionsv2"
      }
    },
    "/user/{id}": {
      "parameters": [
        {
          "description": "ID of the API version",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/User"
              },
              "examples": {
                "user": {
                  "summary": "User Example",
                  "externalValue": "http://foo.bar/examples/user-example.json"
                }
              }
            }
          },
          "name": "id",
          "in": "path"
        }
      ]
    }
  }
}
Negative 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": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "idParam": {
        "name": "id",
        "in": "path",
        "description": "ID of the API version",
        "required": true,
        "schema": {
          "type": "int"
        },
        "content": {
          "application/xml": {
            "examples": {
              "user": {
                "externalValue": "http://foo.bar/examples/user-example.xml",
                "summary": "User Example in XML"
              }
            },
            "schema": {
              "$ref": "#/components/schemas/User"
            }
          }
        }
      }
    }
  }
}
Negative test num. 3 - yaml file
openapi: 3.0.0
info:
  title: Simple API overview
  version: 1.0.0
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      parameters:
        - name: id
          in: path
          description: ID of the API version
          required: true
          schema:
            type: integer
          content:
            "application/json":
              schema:
                $ref: "#/components/schemas/User"
              examples:
                user:
                  summary: User Example
                  externalValue: "http://foo.bar/examples/user-example.json"
      responses:
        "200":
          description: 200 response
          content:
            application/json:
              examples:
                foo:
                  value:
                    versions:
                      - status: CURRENT
                        updated: "2011-01-21T11:33:21Z"
                        id: v2.0
                        links:
                          - href: http://127.0.0.1:8774/v2/
                            rel: self
  /user/{id}:
    parameters:
      - name: id
        in: path
        description: ID of the API version
        required: true
        schema:
          type: integer
        content:
          "application/json":
            schema:
              $ref: "#/components/schemas/User"
            examples:
              user:
                summary: User Example
                externalValue: "http://foo.bar/examples/user-example.json"

Negative 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":
          description: 200 response
          content:
            application/json:
              examples:
                foo:
                  value:
                    versions:
                      - status: CURRENT
                        updated: "2011-01-21T11:33:21Z"
                        id: v2.0
                        links:
                          - href: http://127.0.0.1:8774/v2/
                            rel: self
components:
  parameters:
    idParam:
      name: id
      in: path
      description: ID of the API version
      required: true
      schema:
        type: int
      content:
        "application/json":
          schema:
            $ref: "#/components/schemas/User"
          examples:
            user:
              summary: User Example
              externalValue: "http://foo.bar/examples/user-example.json"