Implicit Flow in OAuth2 (v3)
- Query id: 4a1f3d75-ab73-41b2-83e7-06a93dc3a75a
- Query name: Implicit Flow in OAuth2 (v3)
- Platform: OpenAPI
- Severity: Medium
- Category: Access Control
- URL: Github
Description¶
There is a 'securityScheme' using implicit flow on OAuth2, which is deprecated
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": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCode": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"implicit": {
"authorizationUrl": "https://api.invalid.company.com/oauth/authorize",
"scopes": {
"write:api": "modify apis in your account",
"read:api": "read your apis"
}
}
}
}
}
}
}
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": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCode": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.my.company.com/oauth/authorize",
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"write:api": "modify apis in your account",
"read:api": "read your apis"
}
},
"implicit": {
"authorizationUrl": "https://api.invalid.company.com/oauth/authorize",
"scopes": {
"write:api": "modify apis in your account",
"read:api": "read your apis"
}
}
}
}
}
}
}
Positive test num. 3 - 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": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCode": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.my.company.com/oauth/authorize",
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"write:api": "modify apis in your account",
"read:api": "read your apis"
}
}
}
},
"oAuth2AuthCode2": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"implicit": {
"authorizationUrl": "https://api.invalid.company.com/oauth/authorize",
"scopes": {
"write:api": "modify apis in your account",
"read:api": "read your apis"
}
}
}
}
}
}
}
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: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCode:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
implicit:
authorizationUrl: https://api.invalid.company.com/oauth/authorize
scopes:
write:api: modify apis in your account
read:api: read your apis
Positive test num. 5 - 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: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCode:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
authorizationCode:
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
write:api: modify apis in your account
read:api: read your apis
implicit:
authorizationUrl: https://api.invalid.company.com/oauth/authorize
scopes:
write:api: modify apis in your account
read:api: read your apis
Positive test num. 6 - 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: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCode:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
authorizationCode:
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
write:api: modify apis in your account
read:api: read your apis
oAuth2AuthCode2:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
implicit:
authorizationUrl: https://api.invalid.company.com/oauth/authorize
scopes:
write:api: modify apis in your account
read:api: read your apis
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": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCodeNeg2": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.my.company.com/oauth/authorize",
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"write:api": "modify apis in your account",
"read:api": "read your apis"
}
}
}
}
}
}
}
Negative test num. 2 - 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: 200 response
content:
application/json:
examples:
foo:
value:
versions:
- status: CURRENT
updated: '2011-01-21T11:33:21Z'
id: v2.0
links:
- href: http://127.0.0.1:8774/v2/
rel: self
components:
securitySchemes:
oAuth2AuthCodeNeg2:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
authorizationCode:
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
write:api: modify apis in your account
read:api: read your apis