ASP.NET Form Authentication安全漏洞及对策

NT-Bugtraq的邮件列表上首先报告的Security bug in .NET Forms Authentication适用于ASP.NET 1.0 (RTM, SP1, SP2, SP3)ASP.NET 1.1 (RTM, SP1).

 

Form Authentication被使用时,匿名用户在试图访问被保护的页面如http://localhost/WebApplication2/secret.aspx时会被redirect到登录网页如http://localhost/WebApplication2/login.aspx?ReturnUrl=%2fWebApplication2%2fsecret.aspx.

 

但是如果使用Mozilla,匿名用户可以这样未经认证就访问被保护的页面:http://localhost/WebApplication2/secret.aspx;对IE,可以使用%5C达到类似的效果:http://localhost/WebApplication2%5Csecret.aspx

 

微软在105日发布了What You Should Know About a Reported Vulnerability in Microsoft ASP.NET网页以提供针对此安全漏洞的对策。当前的对策主要是如KB887459所描述的那样在Global.asax或其Code-Behind中在Application_BeginRequest中增加检查

 

    if (Request.Path.IndexOf('//') >= 0 ||
        System.IO.Path.GetFullPath(Request.PhysicalPath) != Request.PhysicalPath)
{
        throw new HttpException(404, "not found");
    }

显然每个Application都需要有这样的检查以应对此安全漏洞。微软还会提供其他的对策,请关注What You Should Know About a Reported Vulnerability in Microsoft ASP.NET网页更新。

 

ASP.NET 2.0 Beta1,并没有此漏洞而是得到404错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET身份验证是一种用于验证用户身份的机制,它可以确保只有经过身份验证的用户才能访问应用程序的受保护部分。ASP.NET Core提供了多种身份验证方式,包括Cookie身份验证、JWT身份验证、OpenID Connect身份验证等。其中,Cookie身份验证是最常用的一种方式。 以下是ASP.NET Core中使用Cookie身份验证的示例代码: 1. 在Startup.cs文件的ConfigureServices方法中添加身份验证服务: ```csharp services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logout"; }); ``` 2. 在Startup.cs文件的Configure方法中启用身份验证中间件: ```csharp app.UseAuthentication(); ``` 3. 在需要进行身份验证的Controller或Action上添加[Authorize]特性: ```csharp [Authorize] public class HomeController : Controller { // ... } ``` 4. 在登录Controller中使用SignInAsync方法进行登录: ```csharp public async Task<IActionResult> Login(LoginViewModel model) { // 验证用户名和密码 if (/* 验证通过 */) { // 创建用户标识 var claims = new List<Claim> { new Claim(ClaimTypes.Name, model.UserName) }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); // 登录 await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)); // 跳转到首页 return RedirectToAction("Index", "Home"); } // 验证失败,返回登录页面 return View(model); } ``` 5. 在注销Controller中使用SignOutAsync方法进行注销: ```csharp public async Task<IActionResult> Logout() { await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); return RedirectToAction("Index", "Home"); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值