【发布时间】:2012-12-11 16:09:56
【问题描述】:
这个问题是关于安全威胁的。我想知道下面的用法可以在客户端更改 DropDownList 选择的值并影响服务器端吗?
这里的用法(aspx定义)
<asp:DropDownList AutoPostBack="true" ID="dropDownListDrawingArtists" CssClass="DropDownArtists"
runat="server">
</asp:DropDownList>
服务器端填充
if (IsPostBack == false)
{
if (srLang == "tr")
{
dropDownListDrawingArtists.Items.Add("Çizen Artist Filtresi: Bütün Çizen Artistler");
}
else
{
dropDownListDrawingArtists.Items.Add("Drawing Artist Filter: All Drawing Artists");
}
DataSet dsDrawingArtists = DbConnection.db_Select_Query("select DrawingArtist,COUNT(PokemonId) as Pokecount from tblPokedex group by DrawingArtist order by Pokecount desc,DrawingArtist asc");
for (int i = 0; i < dsDrawingArtists.Tables[0].Rows.Count; i++)
{
dropDownListDrawingArtists.Items.Add(dsDrawingArtists.Tables[0].Rows[i]["DrawingArtist"].ToString());
}
if (Session["FilterByArtist"] != null)
{
dropDownListDrawingArtists.SelectedIndex = Convert.ToInt32(Session["FilterByArtist"].ToString());
}
}
以及回发时的最终用法
if (dropDownListDrawingArtists.SelectedIndex > 0)
{
srFilterByDrawingArtist = " and DrawingArtist='" + dropDownListDrawingArtists.SelectedItem.ToString() + "'";
Session["FilterByArtist"] = dropDownListDrawingArtists.SelectedIndex.ToString();
}
如您所见,我在 SQL 查询中直接使用它。我在谷歌浏览器上测试了自己。更改了 dropDownListDrawingArtists 的值并进行了回发。服务器端的值没有受到影响。只是为了确定
感谢回答
asp.net 4.0 C# 4.0
【问题讨论】:
-
您正在接受 sql 注入。至少使用参数。此外,假设用户可以并且将向您的页面提供恶意数据。
-
As you can see i am directly using it at the SQL query你永远不应该在你编写的任何应用程序中这样说。您的 SQL 查询应使用参数化查询来合并通过用户输入提供的任何数据。 -
服务我完全知道。但如果数据无法更改,为什么还要麻烦?
-
@MonsterMMORPG 因为您重视数据的安全性,并且不希望创建小鲍比表可以破坏整个数据库的漏洞。除非你当然不关心这个,在这种情况下为什么要首先问。
标签: c# asp.net security drop-down-menu postback