输入验证与表示问题是由元字符、交替编码和数字表示引起的。安全问题源于信任输入。这些问题包括:“Buffer Overflows”、“Cross-Site Scripting”攻击、“SQL Injection”等其他问题。
select()
查询,该查询可搜索与用户指定产品类别相匹配的清单。用户还可以指定对结果进行排序的列。假定在执行此代码片段之前已正确验证了应用程序并设置了 customerID
的值。
...
String customerID = getAuthenticatedCustomerID(customerName, customerCredentials);
...
AmazonSimpleDBClient sdbc = new AmazonSimpleDBClient(appAWSCredentials);
String query = "select * from invoices where productCategory = '"
+ productCategory + "' and customerID = '"
+ customerID + "' order by '"
+ sortColumn + "' asc";
SelectResult sdbResult = sdbc.select(new SelectRequest(query));
...
select * from invoices
where productCategory = 'Fax Machines'
and customerID = '12345678'
order by 'price' asc
productCategory
和 price
不包含单引号字符时,才会正确执行这一查询。但是,如果攻击者为 productCategory
提供了字符串“Fax Machines' or productCategory = \"
”,并为 sortColumn
提供了字符串“\" order by 'price
”,则查询将变为如下所示:
select * from invoices
where productCategory = 'Fax Machines' or productCategory = "'
and customerID = '12345678'
order by '" order by 'price' asc
select * from invoices
where productCategory = 'Fax Machines'
or productCategory = "' and customerID = '12345678' order by '"
order by 'price' asc
customerID
所要求的 Authentication,并查看与 'Fax Machines'
相匹配的所有客户清单记录。customerID
的值。
...
productCategory = this.getIntent().getExtras().getString("productCategory");
sortColumn = this.getIntent().getExtras().getString("sortColumn");
customerID = getAuthenticatedCustomerID(customerName, customerCredentials);
c = invoicesDB.query(Uri.parse(invoices), columns, "productCategory = '" + productCategory + "' and customerID = '" + customerID + "'", null, null, null, "'" + sortColumn + "'asc", null);
...
select * from invoices
where productCategory = 'Fax Machines'
and customerID = '12345678'
order by 'price' asc
productCategory
连在一起形成。因此只有在 productCategory
与 sortColumn
不包含单引号字符时,这一查询才能正确执行。如果攻击者为 productCategory
提供了字符串“Fax Machines' or productCategory = \"
”,并为 sortColumn
提供了字符串“\" order by 'price
”,则查询将变为如下所示:
select * from invoices
where productCategory = 'Fax Machines' or productCategory = "'
and customerID = '12345678'
order by '" order by 'price' asc
select * from invoices
where productCategory = 'Fax Machines'
or productCategory = "' and customerID = '12345678' order by '"
order by 'price' asc
customerID
所要求的 authentication,并查看与 'Fax Machines'
相匹配的所有客户清单记录。HttpRequest
类可通过编程的方式利用数组(例如 Request["myParam"]
)访问 QueryString
、Form
、Cookies
或 ServerVariables
集合中的变量。如果多个变量使用相同的名称,.NET 框架将返回按以下顺序搜索这些集合时最先显示的变量值:QueryString
、Form
、Cookies
、ServerVariables
。由于 QueryString
会首先搜索,因此 QueryString
参数可能会取代 Form、Cookies 和 ServerVariables 变量的值。同样,Form 值可能会取代 Cookies
和 ServerVariables
集合中的变量,Cookies
集合中的变量可能会取代 ServerVariables
中的变量。
...
String toAddress = Request["email"]; //Expects cookie value
Double balance = GetBalance(userID);
SendAccountBalance(toAddress, balance);
...
http://www.example.com/GetBalance.aspx
时执行Example 1
中的代码。如果攻击者能够使经过身份验证的用户单击请求 http://www.example.com/GetBalance.aspx?email=evil%40evil.com
的链接,则会将包含该用户的帐户余额的电子邮件发送到 evil@evil.com
。HttpRequest
类可通过编程的方式利用数组(例如 Request["myParam"]
)访问 QueryString
、Form
、Cookies
或 ServerVariables
集合中的变量。如果多个变量使用相同的名称,.NET 框架将返回按以下顺序搜索这些集合时最先显示的变量值:QueryString
、Form
、Cookies
、ServerVariables
。由于 QueryString
会首先搜索,因此 QueryString
参数可能会取代 Form、Cookies 和 ServerVariables 变量的值。同样,Form 值可能会取代 Cookies
和 ServerVariables
集合中的变量,Cookies
集合中的变量可能会取代 ServerVariables
中的变量。www.example.com
。
...
if (Request["HTTP_REFERER"].StartsWith("http://www.example.com"))
ServeContent();
else
Response.Redirect("http://www.example.com/");
...
http://www.example.com/ProtectedImages.aspx
时执行Example 1
中的代码。如果攻击者直接请求该 URL,则不会设置相应的 referer 标头,并且该请求将失败。然而,如果攻击者提交具有所需值的假冒 HTTP_REFERER
参数,例如 http://www.example.com/ProtectedImages.aspx?HTTP_REFERER=http%3a%2f%2fwww.example.com
,则查找将从 QueryString
而不是 ServerVariables
返回值,并且此检查将成功。