Global security field has an empty object (v3)

  • Query id: 543e38f4-1eee-479e-8eb0-15257013aa0a
  • Query name: Global security field has an empty object (v3)
  • Platform: OpenAPI
  • Severity: High
  • Category: Access Control
  • URL: Github

Description

Global security definition must not have empty objects
Documentation

Code samples

Code samples with security vulnerabilities

Postitive 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": {
            "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {}
  ]
}
Postitive 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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {},
    {
      "exampleSecurity": []
    }
  ],
  "components": {
    "exampleSecurity": {
      "type": "http",
      "scheme": "basic"
    }
  }
}
Postitive 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": {
            "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "exampleSecurity": []
    },
    {}
  ],
  "components": {
    "exampleSecurity": {
      "type": "http",
      "scheme": "basic"
    }
  }
}

Postitive test num. 4 - 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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "security": {}
}
Postitive test num. 5 - 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
security:
- {}
Postitive test num. 6 - 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
security:
- {}
- exampleSecurity: []
components:
  exampleSecurity:
    type: http
    scheme: basic
Postitive test num. 7 - 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
security:
- exampleSecurity: []
- {}
components:
  exampleSecurity:
    type: http
    scheme: basic
Postitive test num. 8 - 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
security: {}
Postitive test num. 9 - yaml file
swagger: "2.0"
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          schema:
            type: object
            properties:
              code:
                type: integer
                format: int32
              message:
                type: string
            required:
              - code
              - message
          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
security:
  - exampleSecurity: []
  - {}
Postitive test num. 10 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "schema": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "integer",
                  "format": "int32"
                },
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "code",
                "message"
              ]
            },
            "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"
                        }
                      ]
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "exampleSecurity": []
    },
    {}
  ]
}
Postitive test num. 11 - yaml file
swagger: "2.0"
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          schema:
            type: object
            properties:
              code:
                type: integer
                format: int32
              message:
                type: string
            required:
              - code
              - message
          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
security: {}
Postitive test num. 12 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "schema": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "integer",
                  "format": "int32"
                },
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "code",
                "message"
              ]
            },
            "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"
                        }
                      ]
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "security": {}
}

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": {
            "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "security":[
    {
      "exampleSecurity": []
    }
  ],
  "components": {
    "exampleSecurity": {
      "type": "http",
      "scheme": "basic"
    }
  }
}
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':
          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
security:
- exampleSecurity: []
components:
  exampleSecurity:
    type: http
    scheme: basic
Negative test num. 3 - yaml file
swagger: "2.0"
info:
  title: Simple API Overview
  version: 1.0.0
  contact:
    name: contact
    url: https://www.google.com/
    email: user@gmail.com
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
          schema:
            type: object
            properties:
              code:
                type: integer
                format: int32
              message:
                type: string
            required:
              - code
              - message
          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
security:
  - exampleSecurity: []

Negative test num. 4 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0",
    "contact": {
      "name": "contact",
      "url": "https://www.google.com/",
      "email": "user@gmail.com"
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "schema": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "integer",
                  "format": "int32"
                },
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "code",
                "message"
              ]
            },
            "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"
                        }
                      ]
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "exampleSecurity": []
    }
  ]
}