security - 保护 .NET Core MVC 网站免受暴力登录尝试(通过内置方式)
问题描述
我正在使用OWasp 安全备忘单来检查/加强我创建的 .net 核心网站的安全性。
A2 节有一部分是关于防止暴力登录尝试的。
它指出一个解决方案是在登录操作上添加以下属性(但它适用于 MVC5)
[AllowXRequestsEveryXSecondsAttribute(
Name = "LogOn",
Message = "You have performed this action more than {x} times in the last {n} seconds.",
Requests = 3,
Seconds = 60)]
.net 核心脚手架将登录部分创建为一个page
而不是一个 MVC 控制器,我似乎无法访问该属性(或制定一个类似的)。
显然,我可以使用诸如this和this之类的帖子来推出我自己的解决方案,但我宁愿使用可用的标准工具。
如果可以的话,我宁愿不使用锁定功能,因为这会增加支持。
.NET Core 是否有我可以使用的内置功能?
解决方案
几个月后以新的眼光回到这个问题,发现微软的一篇帖子,其中包括用于防止暴力攻击的帐户锁定,这将是一个安全层,虽然不像旧的 MVC5AllowXRequestsEveryXSecondsAttribute
启用的那样提供全面的保护。
它会阻止针对一封电子邮件的多次尝试,但不会阻止针对多封电子邮件的多次尝试。
即它会阻止某人做
- 用户名:user1@test.com,密码:Password121
- 用户名:user1@test.com,密码:Password122
- 用户名:user1@test.com,密码:Password123
但这不会阻止某人这样做:
- 用户名:user1@test.com,密码:Password123
- 用户名:user2@test.com,密码:Password123
- 用户名:user3@test.com,密码:Password123
这是来自 Microsoft 的代码摘录(它们是关键options.Lockout
部分):
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.Configure<IdentityOptions>(options =>
{
options.Lockout.MaxFailedAccessAttempts = 10;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10);
});
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.Configure<SMSoptions>(Configuration);
}
更新(与核心团队讨论后)
我在 Github 上向 .NET Core 团队提出了这个问题。
AllowXRequestsEveryXSecondsAttribute
OWasp 检查表中提到的属性来自外部库,他们认为可以将其转换为 .NET Core,但他们并不认为将某些内容作为框架的一部分包含在内是优先事项。他们的建议是研究 Azure 解决方案“AAD 或 B2C”或“Auth0”。
推荐阅读
- javascript - 如何获取系统配置设置 Magento 2
- python - 多进程线生成,但在 main 中绘图
- ios - 从结构中删除重复项
- flutter - Flutter:为什么要在 Stream 上使用 Future?
- java - circleci 图像中的后缀“-stretch”是什么意思?
- php - PHP中函数的参数长度限制是多少?
- python - 请求 + s3 非常缓慢
- android - ConactMap 以进度进行序列 API 调用
- android - 如何修复此错误:org.json.JSONException: Expected literal value at character 0
- postgresql - 是否可以在 Ubuntu 14.04 上安装 postgresql 11?