在 Amazon Cognito 中启用 Prevent User Existence Errors(防止用户存在错误)设置会产生什么影响?

2 分钟阅读
0

我想进一步了解 Amazon Cognito 中的 Prevent User Existence Errors(防止用户存在错误)设置。

简短描述

用户枚举是一个 Web 应用程序漏洞,恶意攻击者使用暴力技术来猜测或确认系统中的有效用户。Amazon Cognito 提供了一项安全功能,可阻止不良攻击者在 Amazon Cognito 用户群体中寻找有效用户。此安全功能适用于发生用户枚举的最常见区域:

  • 用户身份验证
  • 用户确认
  • 密码恢复
  • 用户注册

解决方法

用户身份验证

当输入不存在用户的用户名和密码时,Amazon Cognito 会以名为 UserNotFoundException 的异常进行响应。此用户存在错误明确指出输入的用户名不存在。根据这种错误响应,恶意攻击者可以执行暴力攻击来猜测用户群体中的有效用户。

启用 Prevent User Existence Errors(防止用户存在错误)设置,以便您的 Amazon Cognito 应用程序客户端会针对不存在用户登录请求返回通用消息。通用消息指明用户名或密码不正确。Prevent User Existence Errors(防止用户存在错误)设置有助于防范凭证猜测攻击,因为错误消息并未显示用户的存在。

不存在的用户登录尝试的错误响应示例

以下是不存在用户登录尝试的错误响应示例。

$ aws cognito-idp initiate-auth --client-id 12ab34cd56ef78gh91ij23kl45m --auth-flow USER_PASSWORD_AUTH --auth-parameters USERNAME="myuser",PASSWORD="password"

关闭 Prevent User Existence Errors(防止用户存在错误)设置后:“An error occurred (UserNotFoundException) when calling the InitiateAuth operation: User does not exist.”(调用 initiateAuth 操作时出现错误 (UserNotFoundException):用户不存在。)

启用 Prevent User Existence Errors(防止用户存在错误)设置后:“An error occurred (NotAuthorizedException) when calling the InitiateAuth operation: Incorrect username or password.”(调用 InitiateAuth 操作时出现错误 (NotAuthorizedException):用户名或密码不正确。)

用户确认

Prevent User Existence Errors(防止用户存在错误)设置处于启用状态且用户被停用或找不到时,Amazon Cognito 会返回 CodeDeliveryDetails。代码传送详细信息将通过模拟传送介质返回给用户,而不是返回名为 UserNotFoundException 的异常。当用户群体中存在用户时,Amazon Cognito 会向该用户的现有电子邮件地址或电话号码发送确认码。模拟传送介质由用户名的输入格式和用户群体的验证设置决定。

不存在用户重新发送确认码的错误响应示例

以下是向用户群体中不存在的用户重新发送确认码的错误响应示例:

$ aws cognito-idp resend-confirmation-code --client-id 12ab34cd56ef78gh91ij23kl45m --username "myuser"

关闭 Prevent User Existence Errors(防止用户存在错误)设置后:“An error occurred (UserNotFoundException) when calling the ResendConfirmationCode operation: Username/client id combination not found.”(调用 ResendConfirmationCode 操作时出现错误 (UserNotFoundException):找不到用户名/客户端 ID 组合。)

启用 Prevent User Existence Errors(防止用户存在错误)设置后,其中电子邮件地址是随机的,传送介质是模拟的:

{
  "CodeDeliveryDetails": {
    "Destination": "n****@g****.com",
    "DeliveryMedium": "Email",
    "AttributeName": "email"
  }
}

密码恢复

Prevent User Existence Errors(防止用户存在错误)设置处于启用状态且用户被停用、找不到或无法恢复密码时,Amazon Cognito 会返回 CodeDeliveryDetails。代码传送详细信息为用户提供了模拟传送介质,而不是返回名为 UserNotFoundException 的异常。模拟传送介质由用户名的输入格式和用户群体的恢复设置决定。

通过代码恢复详细信息,您可以看到恢复代码已发送到随机的模拟电子邮件地址或电话号码。这种模拟传送介质使攻击者难以区分有效用户和无效用户。

Amazon Cognito 在密码重置流程中使用模拟传送介质返回 CodeDeliveryDetails。但是,密码重置代码实际上并未发送到模拟传送介质。这是一项安全措施,可避免向未经验证的电子邮件地址和电话号码发送垃圾邮件。

不存在用户密码恢复的错误响应示例

以下是用户群体中不存在的用户的密码恢复错误响应示例:

$ aws cognito-idp forgot-password --client-id 12ab34cd56ef78gh91ij23kl45m --username "myuser"

关闭 Prevent User Existence Errors(防止用户存在错误)设置后:“An error occurred (UserNotFoundException) when calling the ForgotPassword operation: Username/client id combination not found.”(调用 ForgotPassword 操作时出现错误 (UserNotFoundException):找不到用户名/客户端 ID 组合。)

启用 Prevent User Existence Errors(防止用户存在错误)设置后,其中电话号码是随机的,传送介质是模拟的:

{
  "CodeDeliveryDetails": {
    "Destination": "+*******0874",
    "DeliveryMedium": "SMS",
    "AttributeName": "phone_number"
  }
}

用户注册

当用户名已被使用时,SignUp 操作会返回 UsernameExistsException。为防止在注册期间电子邮件地址或电话号码出现 UsernameExistsException 错误,请使用基于验证的别名。

当电子邮件地址或电话号码作为别名从已在使用的其他账户提供时,注册成功。当用户尝试使用此电子邮件地址或电话号码以及有效的验证码确认账户时,将返回 AliasExistException 错误。该错误向用户表明存在使用此电子邮件地址或电话号码的账户。

由于只有在输入有效代码后才会显示用户存在错误,因此此过程消除了不良攻击者识别有效用户的潜在风险。要了解有关基于验证的别名的更多信息,请参阅用户群体属性并选择 Customizing sign-in attributes(自定义登录属性)选项卡。

如何修改 Amazon Cognito 中的 Prevent User Existence Errors(防止用户存在错误)设置?

按照以下步骤修改 Prevent User Existence Errors(防止用户存在错误)设置:

  1. 登录 Amazon Cognito 控制台
  2. 从列表中选择现有用户群体。
  3. 选择 App integration(应用程序集成)部分。
  4. App clients(应用程序客户端)下,从列表中选择一个应用程序客户端。
  5. App client information(应用程序客户端信息)部分下,选择 Edit(编辑)按钮。
  6. 滚动到底部,找到 Advanced security configurations(高级安全配置)下的 Prevent user existence errors setting(防止用户存在错误)设置。选择或清除此选项。
  7. 保存所做更改。

有关错误响应的更多信息,请参阅管理错误响应


AWS 官方
AWS 官方已更新 1 年前