Description
In Swagger 2.0, an operation’s security replaces the global requirement. Define the scopes it needs under the corresponding OAuth2 scheme in securityDefinitions.
Potential impact
If an operation asks for an unavailable scope, legitimate clients may be unable to obtain a suitable token.
Remediation
Compare the operation’s required scopes with the scheme’s scopes and the authorization server. Correct stale names, retain required permissions and test the operation with the expected scope.
Examples
GET / keeps read:api and drops error:api. If it needs error:api too, define that scope and retain the requirement.
Before
yaml
swagger: "2.0"
paths:
/:
get:
security:
- oAuth2AuthCode:
- read:api
- error:api
securityDefinitions:
oAuth2AuthCode:
type: oauth2
flow: accessCode
authorizationUrl: https://api.example.com/oauth/authorize
tokenUrl: https://api.example.com/oauth/token
scopes:
read:api: read your apis
After
yaml
swagger: "2.0"
paths:
/:
get:
security:
- oAuth2AuthCode:
- read:api
securityDefinitions:
oAuth2AuthCode:
type: oauth2
flow: accessCode
authorizationUrl: https://api.example.com/oauth/authorize
tokenUrl: https://api.example.com/oauth/token
scopes:
read:api: read your apis