SBoova646688 (Community Member) asked a question.

How to fix CWE 601 in Web Forms

I am looking for an acceptable way to redirect inside my application. In my research I have seen suggestions of using isurllocaltohost, however this does not seem to be available in VB .NET web forms. Below is the code i have tried to fix but is still flagged.

 

    Dim url2 = New Uri(HttpContext.Current.Request.Url.AbsoluteUri)

    If Session("RoleOfUser").ToString() = "SMA" Then

      Dim redirectUrl As String = url2.Scheme & "://" & url2.Authority & "/Payroll/TimeTracking.aspx?dt=" & txtFrom.Text & "&PrTimeTrackingId=" & PRTimeTrackingTimeId.Value & "&plantid=" & ddlPlantJobs.SelectedValue & "&PRTimeTrackingHoursID=" & PRTimeTrackingHoursID.Value & "&UserID=" & UserID & "&PlantjobId=" & PlantSysID

      Dim url = New Uri(redirectUrl)

      Dim ctx = HttpContext.Current

      If url.Host.Equals(ctx.Request.Url.Host) AndAlso url.Port.Equals(ctx.Request.Url.Port) Then

        If Not url.ToString().Contains("returnUrl") Then

          Response.Redirect(url.ToString())

        End If

      End If

      Else

      Dim redirectUrl As String = url2.Scheme & "://" & url2.Authority & "/Payroll/TimeTracking.aspx?dt=" & txtFrom.Text & "&PrTimeTrackingId=" & PRTimeTrackingTimeId.Value & "&plantid=" & ddlPlantJobs.SelectedValue & "&PRTimeTrackingHoursID=" & PRTimeTrackingHoursID.Value

      Dim url = New Uri(redirectUrl)

      Dim ctx = HttpContext.Current

      If url.Host.Equals(ctx.Request.Url.Host) AndAlso url.Port.Equals(ctx.Request.Url.Port) Then

        Response.Redirect(redirectUrl)

      End If

 

    End If


  • Veracode Static Analysis detects CWE-601: URL Redirection to Untrusted Site ('Open Redirect') when it can detect data from outside of the application (for example from an HTTP request, but also from a file, database query or webservice) going into a URL.

    It does not parse the URL or detect at what place this data is placed (as this is very difficult). What we typically recommend is:

    1. Ensure that the scheme (https), authority and path part of the URL (for example: https://analysiscenter.veracode.com:443/auth/index.jsp ) are (in order of preference):
      1. hardcoded
      2. use only trusted configuration data
      3. are strictly validated with a allow list approach ( e.g. in /product/123 ensure the product id is numeric )
    2. Ensure the query data contains only hardcoded query parameters and URL encode any dynamic values.

     

    In the given example I would recommend getting from trusted configuration or a hardcoded value the host and scheme and applying URL encoding to all dynamic query parameters.

    Please note that URL encoding, while recommended for query parameters, is not appropriate for the host and path part of a URL and as such is not automatically recognized by Veracode Static Analysis and will require a mitigation proposal ( https://help.veracode.com/r/improve_mitigation ) which you will need to get reviewed by your security team.

     

    Thank you,

    Boy Baukema

     

    Expand Post

Topics (4)

No articles found
Loading

Ask the Community

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