If operation has security defined, the 401 response should be defined

Description

If the security field defines security requirements for an API operation, you should define 401 and 403 responses for the operation. The 401 response is missing.

For more details, see RFC 7235.

Example

The following is an example of how this type of risk could look in your API definition. The global security field defines authentication for all API operations, but the 401 response is missing from the operation:

{
  "security": [
   {
     "regularSecurity": []
    }
  ]
}
...
  "post": {
     "description": "Add a new lock combination",
     ...
     "responses": {
       "200": {
         "description": "OK"
       }
       "403": {
         "description": "Forbidden",
         "schema": {
           "$ref": "#/definitions/403"
         }
       }
      }
    }
  }
}

Possible exploit scenario

Attackers strive to make your APIs behave in an unexpected way to learn more about your system or to cause a data breach. We highly recommend that you minimize any risks and clearly specify the data that your API operations can return for each possible response code.

Remediation

Define 401 responses for all operations that have security defined for them.

{
  "security": [
   {
     "regularSecurity": []
    }
  ]
}
...
  "post": {
     "description": "Add a new lock combination",
     ...
     "responses": {
       "200": {
         "description": "OK"
       },
       "401": {
         "description": "Unauthorized",
         "schema": {
           "$ref": "#/definitions/401"
         }
       },
       "403": {
         "description": "Forbidden",
         "schema": {
           "$ref": "#/definitions/403"
         }
        }
      }
    }
  }
}