Global Security Field Has An Empty Array (v3)

  • Query id: d674aea4-ba8b-454b-bb97-88a772ea33f0
  • Query name: Global Security Field Has An Empty Array (v3)
  • Platform: OpenAPI
  • Severity: High
  • Category: Access Control
  • URL: Github

Description

Security object need to have defined rules in its array and rules should be defined on securityScheme
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": {
            "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": []
}
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':
          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: []
Positive 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: []

Positive 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": []
}

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": {
    "securitySchemes": [
      {
        "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:
  securitySchemes:
  - 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": []
    }
  ]
}