避免在asp.net中使用Cross Side脚本

时间:2018-06-14 14:00:00

标签: sql asp.net vb.net xss

我目前正在编写注册模块。基本上,它是一个注册模块,它从asp.net站点获取用户信息并将它们发送到SQL服务器。我进行了重大更改,但在使用acunetix进行扫描时仍然存在XSS问题。注册模块工作得很好,但我想避免使用XSS。因为它显然很脆弱,并且没有通过acunetix扫描。 我想出的最后一个代码如下。它是一个按钮点击事件。

        Dim connQuery As String = "Data Source=myserver;Initial Catalog=mydatabase;Integrated Security=True"
    Dim cs As SqlConnection = New SqlConnection(connQuery)
    Dim da As SqlDataAdapter = New SqlDataAdapter()
    Dim table As String = "[mydatabase].[dbo].[users]"
    Dim query As String = "INSERT INTO " & table & "(passwd, FName, LName, Organization, TelNo, FaxNo, Title, Email, User_type, GroupID, Activated, request_num, FirstLogin, LastLogin, IsLoggedin, IsOutsideInv, WI, study_type) VALUES (@passwd, @FName, @LName, @Organization, @TelNo, @FaxNo, @Title, @Email, @User_type, @GroupID, @Activated, @request_num, @FirstLogin, @LastLogin, @IsLoggedin, @IsOutsideInv, @WI, @study_type)"

    Try

        da.InsertCommand = New SqlCommand(query, cs)

        ' da.InsertCommand.Parameters.Add("@passwd", SqlDbType.NVarChar).Value = txtPassword.Text
        da.InsertCommand.Parameters.Add("@passwd", SqlDbType.NVarChar).Value = encode(txtPassword.Text)
        da.InsertCommand.Parameters.Add("@FName", SqlDbType.NVarChar).Value = txtFirstName.Text
        da.InsertCommand.Parameters.Add("@LName", SqlDbType.NVarChar).Value = txtLastName.Text
        da.InsertCommand.Parameters.Add("@Organization", SqlDbType.NVarChar).Value = txtOrg.Text
        da.InsertCommand.Parameters.Add("@TelNo", SqlDbType.NVarChar).Value = txtPhone.Text
        da.InsertCommand.Parameters.Add("@FaxNo", SqlDbType.NVarChar).Value = txtFax.Text
        da.InsertCommand.Parameters.Add("@Title", SqlDbType.NVarChar).Value = txtTitle.Text
        da.InsertCommand.Parameters.Add("@Email", SqlDbType.NVarChar).Value = txtEmail.Text
        da.InsertCommand.Parameters.Add("@User_type", SqlDbType.Int).Value = 0
        da.InsertCommand.Parameters.Add("@GroupID", SqlDbType.NVarChar).Value = 0
        da.InsertCommand.Parameters.Add("@Activated", SqlDbType.Bit).Value = 0 
        da.InsertCommand.Parameters.Add("@request_num", SqlDbType.Int).Value = 0
        da.InsertCommand.Parameters.Add("@FirstLogin", SqlDbType.DateTime).Value = DateAndTime.Now
        da.InsertCommand.Parameters.Add("@LastLogin", SqlDbType.NVarChar).Value = DateAndTime.Now
        da.InsertCommand.Parameters.Add("@IsLoggedin", SqlDbType.Bit).Value = 0
        da.InsertCommand.Parameters.Add("@IsOutsideInv", SqlDbType.NVarChar).Value = 0
        da.InsertCommand.Parameters.Add("@WI", SqlDbType.NVarChar).Value = txtInves.Text
        da.InsertCommand.Parameters.Add("@study_type", SqlDbType.NVarChar).Value = 0 

        cs.Open()
        da.InsertCommand.ExecuteNonQuery()
        cs.Close()
    Catch ex As Exception
        Labelmessage.Text = "Error while adding record to the database ==> " & ex.Message.ToString()
    Finally
        cs.Close()
    End Try

通过此扫描的理想方法是什么?我将不胜感激任何帮助。

0 个答案:

没有答案