如何解决如何清理和验证用户输入以在 asp.net c# 中通过 Checkmarx 扫描
在 Checkmarx 扫描中,我收到易受攻击的异常,
获取dr 元素 的用户输入。这个元素的值然后流经代码而没有经过适当的清理或验证,最终在方法中显示给用户
List<survey_bene> surveybenelist = new List<survey_bene>();
cmd = new sqlCommand("SELECT ResondantCode FROM Respondant");
DataTable dtdetails = vdm.SelectQuery(cmd).Tables[0];
if (dtdetails.Rows.Count > 0)
{
foreach (DaTarow dr in dtdetails.Rows)
{
survey_bene survey = new survey_bene();
survey.resondantcode = dr["ResondantCode"].ToString();
surveybenelist.Add(survey);
}
}
解决方法
我在评论中的问题没有得到确切回答,但我假设这是一个 XSS 漏洞。如果不是,那么我会相应地更新我的答案。
基于此假设,您应该从 HtmlEncode 或 HtmlServerUtility 类调用 HttpUtility 函数:
List<survey_bene> surveybenelist = new List<survey_bene>();
cmd = new SqlCommand("SELECT ResondantCode FROM Respondant");
DataTable dtdetails = vdm.SelectQuery(cmd).Tables[0];
if (dtdetails.Rows.Count > 0)
{
foreach (DataRow dr in dtdetails.Rows)
{
survey_bene survey = new survey_bene();
survey.resondantcode = HttpUtility.HtmlEncode(dr["ResondantCode"].ToString());
surveybenelist.Add(survey);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。