How to avoid open-redirect vulnerability and safely redirect on successful login (HINT: ASP.NET MVC 2 default code is vulnerable)

前端 未结 4 2182
[愿得一人]
[愿得一人] 2021-02-04 03:06

Normally, when a site requires that you are logged in before you can access a certain page, you are taken to the login screen and after successfully authenticating yourself, you

4条回答
  •  孤独总比滥情好
    2021-02-04 03:31

    Jon Galloway wrote up an article with a solution for MVC 2 (and 1).

    Here's the snippet that should help with your issue:

    SECURED (original article updated 2014)

    private bool IsLocalUrl(string url)
    {
      return System.Web.WebPages.RequestExtensions.IsUrlLocalToHost(
          RequestContext.HttpContext.Request, url);
    }
    

提交回复
热议问题