PVedagiri182134 (Community Member) asked a question.

Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) (CWE ID 80) on ActionResult.ExecuteResult

Static scan on veracode results basic XSS flaw.

 

Attack Vector: system_web_mvc_dll.System.Web.Mvc.ActionResult.ExecuteResult

 

Number of Modules Affected: 1

 

Description: This call to system_web_mvc_dll.System.Web.Mvc.ActionResult.ExecuteResult() contains a cross-site scripting (XSS) flaw. The application populates the HTTP response with untrusted input, allowing an attacker to embed malicious content, such as Javascript code, which will be executed in the context of the victim's browser. XSS vulnerabilities are commonly exploited to steal or manipulate cookies, modify presentation of content, and compromise confidential information, with new attack vectors being discovered on a regular basis. ExecuteResult() was called on the result object, which contains tainted data. The tainted data originated from an earlier call to system_web_mvc_dll.System.Web.Mvc.UrlHelper.GenerateContentUrl.

 

 

  public class MyCustomRedirectResult : RedirectResult

  {

    private bool UnauthorizedRedirect { get; set; }

     

    public MyCustomRedirectResult(string url): base(url) { }

     

    public MyCustomRedirectResult(string url, bool unauthorizedRedirect) : base(url)

    {

      this.UnauthorizedRedirect = unauthorizedRedirect;

    }

 

    public override void ExecuteResult(ControllerContext context)

    {

      try

      {

        if (context!=null && context.RequestContext.HttpContext.Request.IsAjaxRequest())

        {

          string destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);

 

          if (this.UnauthorizedRedirect)

          {

            context.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.Unauthorized;

            HttpStatusCodeResult result1 = new HttpStatusCodeResult(401);

            result1.ExecuteResult(context);

          }

          else

          {

            JavaScriptResult result = new JavaScriptResult()

            {

              Script = "window.location='" + destinationUrl + "';"

            };

            result.ExecuteResult(context); // Basic XSS flaw 

          }

        }

        else

        {

          base.ExecuteResult(context);

        }

      }

      catch (System.Exception)

      {

        throw;

      }

    }

  }

 

Calling Method is

 

    [HttpPost]

    public ActionResult RedirectContact(CustomData data)

    {

      return new MyCustomRedirectResult(Url.Action("Contact", "Home", new

      {

        Controller = "Home",

        Action = "Contact",

        Name = data.Value,

      }));

    }

 

I tried with some tainted inputs against data.Value and it result encoded parameter

 

/Home/Contact?Name=_ALL%26javascript%3Aalert%281%29%3B%3Cscript%3Eaasd%3C%2Fscript%3E

 

/Home/Contact?Name=_ALL%27%3B%20window.alert%281%29%3B%20%27

 

/Home/Contact?Name=https%3A%2F%2Fwww.google.com

 

But scanning with veracode finds basic xss flaw. Please help me on how to fix this.


Topics (3)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.