OpenAPI 3.0 警告
在定义 API 时,您可以使用 Postman 来识别任何潜在的安全漏洞。
OpenAPI 3.0 的安全警告
对于 OpenAPI 3.0 中定义的所有 API,以下列表描述了可能的警告消息和可能的解决方法。
- 损坏的对象级授权
- 损坏的用户身份验证
- 过多的数据暴露
- API 接受来自 OAuth 身份验证的纯文本凭据
- API 接受来自 OpenID Connect 身份验证的纯文本凭证
- API 接受来自 OAuth 1.0 身份验证的纯文本凭据
- API 接受纯文本的 API 密钥
- API 接受纯文本的身份验证凭据
- 全局服务器 URL 使用 HTTP 协议
- 操作以纯文本形式接受来自 OAuth 身份验证的凭据
- 操作接受来自 OpenID Connect 身份验证的凭证作为纯文本
- 操作以纯文本形式接受来自 OAuth 1.0 身份验证的凭据
- 操作接受纯文本的 API 密钥
- 操作接受纯文本的身份验证凭据
- 操作的服务器 URL 使用 HTTP 协议
- 授权 URL 使用 HTTP 协议。凭证将作为纯文本传输
- 令牌 URL 使用 HTTP 协议
- 刷新 URL 使用 HTTP 协议
- OpenID Connect URL 使用 HTTP 协议
- 资产管理不当
损坏的对象级授权
securityScheme 声明中未定义安全字段中使用的 OAuth 方案的范围
严重性 | 问题描述 | 可能的修复 |
---|---|---|
低的 | 全局安全字段中使用的 OAuth2 范围应在安全方案字段中定义。否则,攻击者可以引入他们的范围来填补空白并利用系统。 | 确保使用的所有 OAuth2 范围都在 OAuth2 安全方案中定义。 |
解决:
security:
- OAuth2:
- read
- write
components:
securitySchemes:
OAuth2:
type: oauth2
flows:
authorizationCode:
scopes:
read: read objects in your account
write: write objects to your account
使用的 OAuth 方案的范围未在 securityScheme 声明中定义
严重性 | 问题描述 | 可能的修复 |
---|---|---|
低的 | 操作的安全字段中使用的 OAuth2 范围应在安全方案字段中定义。否则,攻击者可以引入他们的范围来填补空白并利用系统。 | 确保使用的所有 OAuth2 范围都在 OAuth2 安全方案中定义。 |
解决:
paths:
"/user":
get:
summary: 'Sample endpoint: Returns details about a particular user'
operationId: listUser
security:
- OAuth2:
- read
- write
components:
securitySchemes:
OAuth2:
type: oauth2
flows:
authorizationCode:
scopes:
read: read objects in your account
write: write objects to your account
损坏的用户身份验证
未定义安全字段
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | 如果未定义全局安全字段,则 API 默认不需要任何身份验证。任何人都可以访问未定义安全字段的 API 操作。 | 安全字段应该在模式中定义。 |
解决:
openapi: 3.0.0
info:
paths:
security:
- testAuth : []
安全字段不包含任何项目
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | 如果 security 字段包含一个空数组,则默认情况下不会对操作应用任何安全方案。 | 安全字段应至少包含数组中的一项。 |
解决:
openapi: 3.0.0
info:
paths:
security:
- testAuth : []
安全字段不包含任何方案
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | 安全字段中的空对象会完全停用身份验证。如果没有为每个操作定义安全字段,任何人都可以访问 API 操作而无需任何身份验证。 | 安全字段数组项不应包含空对象。 |
解决:
openapi: 3.0.0
info:
paths:
security:
- testAuth : []
未定义安全方案对象
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | API 的 components 对象没有声明任何可以在 API 的安全字段或单个操作中使用的安全方案。 | 安全方案应该在组件的模式中定义。 |
解决:
components:
securitySchemes:
testAuth:
type: http
scheme: basic
安全方案对象不包含任何方案
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | 可重用安全方案中的空对象意味着没有为每个操作定义身份验证方案,任何人都可以访问 API 操作而无需任何身份验证。 | 安全方案应在对象中至少包含一项。 |
解决:
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
安全方案中使用的方案未在安全方案对象中定义
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 全局或操作安全字段中使用的身份验证方案未在安全方案对象中定义。 | 安全字段中使用的方案应在安全方案对象中定义。 |
解决:
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
#...
security:
- BasicAuth: []
HTTP 身份验证方案正在使用未知方案
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | HTTP 身份验证方案的名称应在IANA 身份验证方案注册表中注册。 | 确保使用在 IANA 身份验证方案注册表中注册的 HTTP 身份验证方案。 |
解决:
servers:
- url: https://my.server.example.com/
description: API server
#...
components:
securitySchemes:
myAuth:
type: http
scheme: basic
#...
security:
- myAuth: []
操作的安全字段不包含任何项目
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 默认情况下,API 操作未应用任何安全方案。 | 任何操作中的安全字段都应至少包含数组中的一项。 |
解决:
openapi: 3.0.0
info:
title: Example API
version: '1.0'
paths:
/user:
get:
security:
- BasicAuth : []
responses:
default:
description: Example
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
操作的安全字段不包含任何方案
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 安全字段中的空对象会完全停用操作的身份验证。任何人无需任何身份验证即可访问 API 操作。 | 在操作中指定至少一项安全要求。 |
解决:
openapi: 3.0.0
info:
title: Example API
version: '1.0'
paths:
/user:
get:
security:
- BasicAuth : []
responses:
default:
description: Example
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
操作不强制执行任何安全方案
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 如果全局安全字段和操作的安全字段都没有定义,任何人都可以访问 API 而无需任何身份验证。 | 在操作中定义一个安全字段。 |
解决:
openapi: 3.0.0
info:
title: Example API
version: '1.0'
paths:
/user:
get:
security:
- BasicAuth : []
responses:
default:
description: Example
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
过多的数据暴露
API 接受来自 OAuth 身份验证的纯文本凭据
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | 访问令牌通过未加密的网络以纯文本形式发送。攻击者只需侦听公共 Wi-Fi 网络中的网络流量即可拦截访问令牌。 | 确保服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
解决:
servers:
- url: https://my.api.example.com/
description: API server
# ...
components:
securitySchemes:
OAuth2:
type: oauth2
# ...
security:
- OAuth2:
- write
- read
API 接受来自 OpenID Connect 身份验证的纯文本凭证
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 凭据通过未加密的网络以纯文本形式发送。攻击者只需侦听公共 Wi-Fi 网络中的网络流量即可拦截访问令牌。 | 确保服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
分辨率:
components:
securitySchemes:
OpenIdScheme:
type: openIdConnect
openIdConnectUrl: https://example.com/connect
paths:
"/pets":
post:
operationId: addPet
servers:
- url: https://example.com/
description: API server
security:
- OpenIdScheme: []
API 接受来自 OAuth 1.0 身份验证的纯文本凭据
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | 身份验证令牌通过未加密的通道以纯文本形式发送。攻击者可以通过监听公共 Wi-Fi 网络中的网络流量轻松拦截令牌。 | 确保服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
分辨率:
servers:
- url: https://my.api.example.com/
description: API server
#...
components:
securitySchemes:
OAuth1:
type: http
scheme: oauth
#...
security:
- OAuth1: []
API 接受纯文本的 API 密钥
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | API 密钥通过未加密的通道以纯文本形式发送。攻击者可以通过监听公共 Wi-Fi 网络中的网络流量轻松拦截 API 密钥。 | 确保服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
分辨率:
servers:
- url: https://my.api.example.com/
description: API server
#...
components:
securitySchemes:
AuthKeyAuth:
type: apiKey
name: api-key
in: header
#...
security:
- AuthKeyAuth: []
API 接受纯文本的身份验证凭据
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | 凭据通过未加密的网络以纯文本形式发送。攻击者只需侦听公共 Wi-Fi 网络中的网络流量即可拦截凭据。 | 确保服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
解决:
servers:
- url: https://example.com/
description: Example server
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
security:
- BasicAuth: []
全局服务器 URL 使用 HTTP 协议
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 服务器支持未加密的 HTTP 连接,所有请求和响应都将公开传输。任何在通话过程中监听网络流量的人都可以拦截它们。 | 确保服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
解决:
servers:
- url: https://my.api.example.com/
description: API server
# ...
components:
securitySchemes:
OAuth2:
type: oauth2
# ...
security:
- OAuth2:
- write
- read
操作以纯文本形式接受来自 OAuth 身份验证的凭据
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | API 操作接受来自通过未加密通道以纯文本形式传输的流的访问令牌。攻击者可以轻松拦截 API 调用并检索未加密的令牌。然后,他们可以使用令牌进行其他 API 调用。 | 确保操作的服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
解决:
components:
securitySchemes:
OAuth2:
type: oauth2
paths:
"/pets":
post:
operationId: addPet
servers:
- url: https://my.api.example.com/
description: API server
操作接受来自 OpenID Connect 身份验证的凭证作为纯文本
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 操作的凭据通过未加密的网络以纯文本形式发送。攻击者只需侦听公共 Wi-Fi 网络中的网络流量即可拦截访问令牌。 | 确保操作的服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
分辨率:
components:
securitySchemes:
OpenIdScheme:
type: openIdConnect
openIdConnectUrl: https://my.api.openidconnect.example.com/
paths:
"/pets":
post:
operationId: addPet
servers:
- url: https://my.api.example.com/
description: API server
操作以纯文本形式接受来自 OAuth 1.0 身份验证的凭据
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | API 操作接受通过未加密通道作为纯文本传输的授权令牌。攻击者可以轻松拦截 API 调用并检索未加密的令牌以进行其他 API 调用。 | 确保操作的服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
分辨率:
paths:
"/pets":
post:
servers:
- url: https://example.com/
description: Example server
#...
components:
securitySchemes:
OAuth1:
type: http
scheme: oauth
#...
security:
- OAuth1: []
操作接受纯文本的 API 密钥
严重性 | 问题描述 | 可能的修复 |
---|---|---|
高的 | API 操作接受通过未加密通道以纯文本形式传输的 API 密钥。攻击者可以轻松拦截 API 调用并检索 API 密钥以进行其他 API 调用。 | 确保操作的服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
分辨率:
paths:
"/pets":
post:
servers:
- url: https://example.com/
description: Example server
# ...
components:
securitySchemes:
AuthKeyAuth:
type: apiKey
name: api-key
in: header
# ...
security:
- AuthKeyAuth: []
操作接受纯文本的身份验证凭据
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | API 操作接受通过未加密通道以纯文本形式传输的凭证。攻击者可以轻松拦截 API 调用并检索未加密的令牌。然后,他们可以使用令牌进行其他 API 调用。 | 确保操作的服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
解决:
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
paths:
"/pets":
post:
operationId: addPet
servers:
- url: https://example.com/
description: Example server
security:
- BasicAuth: []
操作的服务器 URL 使用 HTTP 协议
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | API 操作支持未加密的 HTTP 连接,所有请求和响应都将公开传输。任何在通话过程中监听网络流量的人都可以拦截它们。 | 确保操作的服务器 URL 是有效 URL 并使用 HTTPS 协议。 |
解决:
get:
operationId: getPetsById
servers:
- url: https://my.api.example.com/
授权 URL 使用 HTTP 协议。凭证将作为纯文本传输
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | OAuth 授权凭证通过未加密的通道传输。任何在通话过程中监听网络流量的人都可以拦截它们。 | 确保授权 URL 是有效 URL 并遵循 HTTPS 协议。 |
解决:
components:
securitySchemes:
OauthScheme:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://my.auth.example.com/
令牌 URL 使用 HTTP 协议
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | OAuth 身份验证令牌通过未加密的通道传输。在发送令牌时监听网络流量的任何人都可以拦截它。 | 确保令牌 URL 是有效 URL 并遵循 HTTPS 协议。 |
解决:
components:
securitySchemes:
OauthScheme:
type: oauth2
flows:
authorizationCode:
tokenUrl: https://my.token.example.com/
刷新 URL 使用 HTTP 协议
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | OAuth 身份验证刷新令牌通过未加密的通道传输。在发送令牌时监听网络流量的任何人都可以拦截它。 | 确保刷新 URL 是有效 URL 并遵循 HTTPS 协议。 |
解决:
components:
securitySchemes:
OauthFlow:
type: oauth2
flows:
authorizationCode
authorizationUrl: https://my.auth.example.com/
tokenUrl: https://my.token.example.com/
refreshUrl: https://my.refresh.example.com/
scopes:
write: modify data
read: read data
OpenID Connect URL 使用 HTTP 协议
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | OpenID Connect 访问令牌和开放 ID 通过未加密的通道传输。任何在通话过程中监听网络流量的人都可以拦截它们。 | 确保 openID 连接 URL 是有效的 URL 并遵循 HTTPS 协议。 |
解决:
components:
securitySchemes:
OpenIdScheme:
type: openIdConnect
openIdConnectUrl: https://example.com/connect
#...
security:
- OpenIdScheme: []
资产管理不当
使用了已弃用的 OAuth 1.0 方案
严重性 | 问题描述 | 可能的修复 |
---|---|---|
低的 | 安全方案使用已被 OAuth 2.0 弃用并取代的 OAuth 1.0 身份验证。 | 确保安全方案未使用已弃用的 OAuth 1.0 身份验证。 |
解决:
components:
securitySchemes:
OauthFlow:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://my.auth.example.com/
tokenUrl: https://my.token.example.com/
scopes:
write: modify data
read: read data
OAuth 身份验证使用已弃用的隐式流程
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | 在 OAuth 隐式流程中,授权服务器在授权请求的响应中发出访问令牌。攻击者可以轻松拦截 API 调用并检索访问令牌以进行其他 API 调用。 | 推荐使用授权码流。确保 OAuth 身份验证方案未使用隐式流。 |
解决:
components:
securitySchemes:
OauthFlow:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://my.auth.example.com/
tokenUrl: https://my.token.example.com/
scopes:
write: modify data
read: read data
OAuth 身份验证使用已弃用的密码流程
严重性 | 问题描述 | 可能的修复 |
---|---|---|
中等的 | Oauth 密码授予流程使用用户的凭据来检索访问令牌。攻击者可以轻松拦截 API 调用并检索访问令牌以进行其他 API 调用。 | 推荐使用授权码流。确保 OAuth 身份验证方案未使用密码授予流程。 |
解决:
components:
securitySchemes:
OauthFlow:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://my.auth.example.com/
tokenUrl: https://my.token.example.com/
scopes:
write: modify data
read: read data