Callback Object With Incorrect Ref

  • Query id: ba066cda-e808-450d-92b6-f29109754d45
  • Query name: Callback Object With Incorrect Ref
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • URL: Github

Description

Callback Object reference must always point to '#/components/callbacks'
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/Success"
          }
        },
        "callbacks": {
          "myEvent": {
            "$ref": "#/components/callbaccgcks/inProgress"
          }
        }
      }
    }
  },
  "components": {
    "callbacks": {
      "inProgress": {
        "{$request.body#/inProgressUrl}": {
          "post": {
            "requestBody": {
              "$ref": "#/components/requestBodies/callbackMessage1"
            },
            "responses": {
              "200": {
                "description": "OK"
              }
            }
          }
        }
      }
    }
  }
}
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":
          $ref: "#/components/schemas/Success"
      callbacks:
        myEvent:
          $ref: "#/components/callbaccgcks/inProgress"
components:
  callbacks:
    inProgress:
      "{$request.body#/inProgressUrl}":
        post:
          requestBody:
            $ref: "#/components/requestBodies/callbackMessage1"
          responses:
            "200":
              description: OK

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/Success"
          }
        },
        "callbacks": {
          "myEvent": {
            "$ref": "#/components/callbacks/inProgress"
          }
        }
      }
    }
  },
  "components": {
    "callbacks": {
      "inProgress": {
        "{$request.body#/inProgressUrl}": {
          "post": {
            "requestBody": {
              "$ref": "#/components/requestBodies/callbackMessage1"
            },
            "responses": {
              "200": {
                "description": "OK"
              }
            }
          }
        }
      }
    }
  }
}
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/Success"
      callbacks:
        myEvent:
          $ref: "#/components/callbacks/inProgress"
components:
  callbacks:
    inProgress:
      "{$request.body#/inProgressUrl}":
        post:
          requestBody:
            $ref: "#/components/requestBodies/callbackMessage1"
          responses:
            "200":
              description: OK