Server Object Variable Not Used

  • Query id: 8aee4754-970d-4c5f-8142-a49dfe388b1a
  • Query name: Server Object Variable Not Used
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • URL: Github

Description

Every defined Server Variable Object should be used in a Service URL.
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": {
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "the user being returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uuid": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            },
            "links": {
              "address": {
                "server": {
                  "url": "https://development.{server}.com/{base}",
                  "variables": {
                    "base": {
                      "default": "v2"
                    },
                    "server": {
                      "default": "gigant-server"
                    },
                    "another": {
                      "default": "another"
                    }
                  }
                }
              }
            }
          }
        },
        "operationId": "listVersionsv2"
      }
    }
  }
}
Positive 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": "the user being returned",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "uuid": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "type": "object"
                }
              }
            }
          }
        },
        "servers": [
          {
            "url": "https://development.gigant-server.com/v2",
            "description": "Development server",
            "variables": {
              "base": {
                "default": "v2"
              }
            }
          }
        ]
      }
    }
  }
}
Positive test num. 3 - 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: the user being returned
          content:
            application/json:
              schema:
                type: object
                properties:
                  uuid: # the unique user id
                    type: string
                    format: uuid
          links:
            address:
              server:
                url: https://development.{server}.com/{base}
                variables:
                  base:
                    default: v2
                  server:
                    default: gigant-server
                  another:
                    default: another

Positive test num. 4 - 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: the user being returned
          content:
            application/json:
              schema:
                type: object
                properties:
                  uuid: # the unique user id
                    type: string
                    format: uuid
      servers:
        - url: https://development.gigant-server.com/v2
          description: Development server
          variables:
            base:
              default: v2

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": {
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "the user being returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uuid": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            },
            "links": {
              "address": {
                "server": {
                  "url": "https://development.{server}.com/{base}",
                  "variables": {
                    "base": {
                      "default": "v2"
                    },
                    "server": {
                      "default": "gigant-server"
                    }
                  }
                }
              }
            }
          }
        },
        "operationId": "listVersionsv2"
      }
    }
  }
}
Negative 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": "the user being returned",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "uuid": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "type": "object"
                }
              }
            }
          }
        },
        "servers": [
          {
            "url": "https://development.{server}.com/{base}",
            "description": "Development server",
            "variables": {
              "base": {
                "default": "v2"
              },
              "server": {
                "default": "gigant-server"
              }
            }
          }
        ]
      }
    }
  }
}
Negative test num. 3 - 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: the user being returned
          content:
            application/json:
              schema:
                type: object
                properties:
                  uuid: # the unique user id
                    type: string
                    format: uuid
          links:
            address:
              server:
                url: https://development.{server}.com/{base}
                variables:
                  base:
                    default: v2
                  server:
                    default: gigant-server

Negative test num. 4 - 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: the user being returned
          content:
            application/json:
              schema:
                type: object
                properties:
                  uuid: # the unique user id
                    type: string
                    format: uuid
      servers:
        - url: https://development.{server}.com/{base}
          description: Development server
          variables:
            base:
              default: v2
            server:
              default: gigant-server