You must Sign In to post a response.
  • Category: ASP.NET

    Cross Site Scripting issue

    The below line when scanned using SAST scan (Coding Standards Scan for finding any security violation) gives a Cross Site Scripting issue.

    line 220 : lblBussinessPurpose.Text = dtPrimaryDelegation.Rows(0).Item("Business_Purpose").ToString

    Issue abstract:
    The method FillPrimarydelegation() in ApproverAndValidatorPage.aspx.vb sends unvalidated data to a web browser on line 220, which can result in the browser executing malicious code.


    Please help us in resolving the issue.

    Explanation:

    Cross-site scripting (XSS) vulnerabilities occur when:

    1. Data enters a web application through an untrusted source. In the case of Persistent (also known as Stored) XSS, the untrusted source is typically a database or other back-end datastore, while in the case of Reflected XSS it is typically a web request.


    In this case the data enters at Fill() in CommonDAL.vb at line 1538.

    2. The data is included in dynamic content that is sent to a web user without being validated.

    In this case the data is sent at set_Text() in ApproverAndValidatorPage.aspx.vb at line 220.

    The malicious content sent to the web browser often takes the form of a segment of JavaScript, but may also include HTML, Flash or any other type of code that the browser may execute. The variety of attacks based on XSS is almost limitless, but they commonly include transmitting private data like cookies or other session information to the attacker, redirecting the victim to web content controlled by the attacker, or performing other malicious operations on the user's machine under the guise of the vulnerable site.

    Example 1: The following ASP.NET Web Form queries a database for an employee with a given employee ID and prints the name corresponding with the ID.


    <script runat="server">
    ...
    string query = "select * from emp where id=" + eid;
    sda = new SqlDataAdapter(query, conn);
    DataTable dt = new DataTable();
    sda.Fill(dt);
    string name = dt.Rows[0]["Name"];
    ...
    EmployeeName.Text = name;
    </script>


    Where EmployeeName is a form control defined as follows:


    <form runat="server">
    ...
    <asp:Label id="EmployeeName" runat="server">
    ...
    </form>



    Example 2: The following ASP.NET code segment is functionally equivalent to Example 1 above, but implements all of the form elements programmatically.


    protected System.Web.UI.WebControls.Label EmployeeName;
    ...
    string query = "select * from emp where id=" + eid;
    sda = new SqlDataAdapter(query, conn);
    DataTable dt = new DataTable();
    sda.Fill(dt);
    string name = dt.Rows[0]["Name"];
    ...
    EmployeeName.Text = name;



    These code examples function correctly when the values of name are well-behaved, but they do nothing to prevent exploits if they are not. This code can appear less dangerous because the value of name is read from a database, whose contents are apparently managed by the application. However, if the value of name originates from user-supplied data, then the database can be a conduit for malicious content. Without proper input validation on all data stored in the database, an attacker can execute malicious commands in the user's web browser. This type of exploit, known as Persistent (or Stored) XSS, is particularly insidious because the indirection caused by the data store makes it more difficult to identify the threat and increases the possibility that the attack will affect multiple users. XSS got its start in this form with web sites that offered a "guestbook" to visitors. Attackers would include JavaScript in their guestbook entries, and all subsequent visitors to the guestbook page would execute the malicious code.
  • #763042
    Hello Padeda,

    This is not the right place to post an resource or an article or an explanation of codes.

    You can post your article or resource here :
    http://www.dotnetspider.com/resources/PostResource.aspx?CategoryId=&Accepted=true

    This is the right the place to post your resource.

    Where you have posted the thread now it is just for discussion purpose or problem solving.

    Hope you understand.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments