operation-security-defined
Since 0.9.0 · In the rulesets: Recommended at warning, Strict at warning, All at error
This rule checks whether every operation of a Swagger 2.0 document is covered by a security requirement.
Rule details
Swagger 2.0 declares security schemes under securityDefinitions and applies
them with security requirements, either at the root of the document (for
every operation) or on individual operations. An operation without any
requirement is documented as publicly accessible, which is often an oversight.
When the root security list is not empty, every operation is covered and the
rule reports nothing. Otherwise the operation-security-defined rule reports
Security requirement is not defined for every operation whose own security
list is missing or empty. An explicit security: [] on an operation is
reported as well.
The OpenAPI linter has a rule of the same name, operation-security-defined, for OpenAPI 3.x documents.
Turn the rule off for public APIs, or disable it on the individual operations that are intentionally public.
Examples
Good. The root security requirement applies to every operation.
swagger: '2.0'
info:
title: Pet Store
version: 1.0.0
securityDefinitions:
apiKey:
type: apiKey
name: X-API-Key
in: header
security:
- apiKey: []
paths:
/pets:
get:
responses:
'200':
description: A list of pets.
Good. Each operation declares its own security requirement.
swagger: '2.0'
info:
title: Pet Store
version: 1.0.0
securityDefinitions:
basic:
type: basic
paths:
/pets:
get:
security:
- basic: []
responses:
'200':
description: A list of pets.
Bad. There is no root security requirement and the post operation has
none of its own.
swagger: '2.0'
info:
title: Pet Store
version: 1.0.0
securityDefinitions:
basic:
type: basic
paths:
/pets:
get:
security:
- basic: []
responses:
'200':
description: A list of pets.
post:
responses:
'201':
description: The pet was added.
Turn it off or change its severity
In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.swagger has the details.
commands:
lint:
swagger:
rules:
operation-security-defined: off