Additional properties are too permissive (OpenAPI 3.0)

An object intended to accept only defined fields permits additional properties

Description

OpenAPI 3.0 allows undeclared object fields when additionalProperties is true or omitted.

Potential impact

A server may store unexpected request fields. Clients may receive response fields the contract does not describe.

Remediation

For a fixed set of fields, set additionalProperties: false and enforce it during validation. For dynamic keys, specify a schema for their values if they need constraints.

Examples

This response excerpt omits info and the response description. After the change, only id and name are allowed. Both are optional.

Before

json
{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string" },
                    "name": { "type": "string" }
                  },
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string" },
                    "name": { "type": "string" }
                  },
                  "additionalProperties": false
                }
              }
            }
          }
        }
      }
    }
  }
}

References