Search code examples
asp.netsecuritycat.net

CAT.NET: vulnerability or false positive?


2nd in an occasional series: Here's the first one

Is CAT.NET correct that the following is a genuine vulnerability in ASP.NET or is it a false positive?

var myInt = Int32.Parse(txtUserInput.Text);

Response.Redirect(string.Format("myPage.aspx?myId={0}", myInt);

CAT.NET is reporting this as a redirect vulnerability needing remediation via encoding myInt.


Solution

  • I wouldn't call that dangerous but its not how I would write it myself

    int myInt;
    if(Int32.TryParse(txtUserInput.Text,out myInt)){
        Response.Redirect(string.Format("myPage.aspx?myId={0}", myInt);
       }
    

    Is to my mind cleaner as it wont throw an exception if the parse fails due to bad user input and we are explicitly typing the int.

    Any error handling code can be bundled into an else statement on the end.