Success Response Code Undefined for Get Operation (v3)

  • Query id: b2f275be-7d64-4064-b418-be6b431363a7
  • Query name: Success Response Code Undefined for Get Operation (v3)
  • Platform: OpenAPI
  • Severity: Low
  • Category: Networking and Firewall
  • CWE: 665
  • URL: Github

Description

Get should define at least one success response (200 or 202)
Documentation

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API",
    "version": "1.0.0"
  },
  "paths": {
    "/item": {
      "get": {
        "operationId": "getItem",
        "summary": "Get item",
        "responses": {
          "default": {
            "description": "Error"
          }
        }
      }
    }
  }
}
Positive test num. 2 - yaml file
swagger: "2.0"
info:
  title: Simple API
  version: 1.0.0
paths:
  "/item":
    get:
      operationId: getItem
      summary: Get item
      responses:
        default:
          description: Error
Positive test num. 3 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API",
    "version": "1.0.0"
  },
  "paths": {
    "/item": {
      "get": {
        "operationId": "getItem",
        "summary": "Get item",
        "responses": {
          "default": {
            "description": "Error"
          }
        }
      }
    }
  }
}

Positive test num. 4 - yaml file
openapi: 3.0.0
info:
  title: Simple API
  version: 1.0.0
paths:
  "/item":
    get:
      operationId: getItem
      summary: Get item
      responses:
        default:
          description: Error

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API",
    "version": "1.0.0"
  },
  "paths": {
    "/item": {
      "get": {
        "operationId": "getItem",
        "summary": "Get item",
        "responses": {
          "200": {
            "description": "success"
          },
          "default": {
            "description": "Success"
          }
        }
      },
      "patch": {
        "operationId": "updateItem",
        "summary": "Update item",
        "responses": {
          "default": {
            "description": "Error"
          }
        }
      }
    }
  }
}
Negative test num. 2 - yaml file
swagger: "2.0"
info:
  title: Simple API
  version: 1.0.0
paths:
  "/item":
    get:
      operationId: getItem
      summary: Get item
      responses:
        "200":
          description: success
        default:
          description: Success
    patch:
      operationId: updateItem
      summary: Update item
      responses:
        default:
          description: Error
Negative test num. 3 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API",
    "version": "1.0.0"
  },
  "paths": {
    "/item": {
      "get": {
        "operationId": "getItem",
        "summary": "Get item",
        "responses": {
          "200": {
            "description": "success"
          },
          "default": {
            "description": "Success"
          }
        }
      },
      "patch": {
        "operationId": "updateItem",
        "summary": "Update item",
        "responses": {
          "default": {
            "description": "Error"
          }
        }
      }
    }
  }
}

Negative test num. 4 - yaml file
openapi: 3.0.0
info:
  title: Simple API
  version: 1.0.0
paths:
  "/item":
    get:
      operationId: getItem
      summary: Get item
      responses:
        "200":
          description: success
        default:
          description: Success
    patch:
      operationId: updateItem
      summary: Update item
      responses:
        default:
          description: Error
Negative test num. 5 - json file
{
    "swagger": "2.0",
    "info": {
      "title": "Simple API",
      "version": "1.0.0"
    },
    "paths": {
      "/item": {
        "get": {
          "operationId": "getItem",
          "summary": "get item",
          "responses": {
            "2XX": {
              "description": "Item getd successfully"
            },
            "default": {
              "description": "Error"
            }
          }
        },
        "patch": {
          "operationId": "updateItem",
          "summary": "Update item",
          "responses": {
            "default": {
              "description": "Error"
            }
          }
        }
      }
    }
  }
Negative test num. 6 - yaml file
swagger: "2.0"
info:
  title: Simple API
  version: 1.0.0
paths:
  "/item":
    get:
      operationId: getItem
      summary: get item
      responses:
        "2XX":
          description: Item getd successfully
        default:
          description: Error
    patch:
      operationId: updateItem
      summary: Update item
      responses:
        default:
          description: Error