Additional Properties Too Restrictive

  • Query id: a19c3bbd-c056-40d7-9e1c-eeb0634e320d
  • Query name: Additional Properties Too Restrictive
  • Platform: OpenAPI
  • Severity: Low
  • Category: Insecure Configurations
  • URL: Github

Description

Objects should accept 'additionalProperties' if it is allOf or an object with anyOf or oneOf
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": {
            "schema": {
              "allOf": [
                {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": "true"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "additionalProperties": "false"
          },
          {
            "type": "string",
            "additionalProperties": "false"
          }
        ]
      }
    }
  }
}
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':
          schema:
            allOf:
            - type: object
              properties:
                id:
                  type: string
                name:
                  type: string
              additionalProperties: 'true'
            - type: string
components:
  schemas:
    MyObject:
      oneOf:
      - type: object
        properties:
          id:
            type: string
          name:
            type: string
        additionalProperties: 'false'
      - type: string
        additionalProperties: 'false'
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": {
            "schema": {
              "allOf": [
                {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": "false"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "additionalProperties": "true"
          },
          {
            "type": "string",
            "additionalProperties": "false"
          }
        ]
      }
    }
  }
}

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':
          schema:
            allOf:
            - type: object
              properties:
                id:
                  type: string
                name:
                  type: string
              additionalProperties: 'false'
            - type: string
components:
  schemas:
    MyObject:
      oneOf:
      - type: object
        properties:
          id:
            type: string
          name:
            type: string
        additionalProperties: 'true'
      - type: string
        additionalProperties: 'false'

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": {
            "schema": {
              "allOf": [
                {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  },
                  "additionalProperties": "true"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MyObject": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "additionalProperties": "true"
          },
          {
            "type": "string",
            "additionalProperties": "false"
          }
        ]
      }
    }
  }
}
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':
          schema:
            allOf:
            - type: object
              properties:
                id:
                  type: string
                name:
                  type: string
              additionalProperties: 'true'
            - type: string
components:
  schemas:
    MyObject:
      oneOf:
      - type: object
        properties:
          id:
            type: string
          name:
            type: string
        additionalProperties: 'true'
      - type: string
        additionalProperties: 'false'