如果沒有適當的 access control,就會執行一個包含用戶控制主鍵的 SQL 指令,從而允許攻擊者訪問未經授權的記錄。
Database access control 錯誤在以下情況下發生:
1. 數據從一個不可信賴的數據源進入程序。
2. 這個數據用來指定 SQL 查詢中主鍵的值。
例 1: 以下代碼用到一個參數化指令,這個指令轉義了元字符,以防止 SQL injection 漏洞,并構建和執行一個 SQL 查詢。該 SQL 查詢指令可以搜索與指定標識符 [1] 相匹配的清單。您可以從與當前被授權用戶有關的所有清單中選擇這些標識符。
procedure get_item (
itm_cv IN OUT ItmCurTyp,
id in varchar2)
is
open itm_cv for ' SELECT * FROM items WHERE ' ||
'invoiceID = :invid' ||
using id;
end get_item;
id 值。雖然接口生成了一個當前用戶的標識符清單,但是攻擊者可以繞過這個接口,從而獲取所需的任何清單。因為此例中的代碼沒有執行檢查,確保用戶有權訪問需要的清單,所以代碼會顯示所有清單,即使這些清單并不屬于當前用戶。
[1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A2 Broken Access Control
[2] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A4 Insecure Direct Object Reference
[3] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A4 Insecure Direct Object References
[4] Standards Mapping - FIPS200 - (FISMA) AC
[5] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3510 CAT I
[6] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3510 CAT I
[7] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 566
[8] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) Insufficient Authorization
[9] Standards Mapping - SANS Top 25 2011 - (SANS Top 25 2011) Porous Defenses - CWE ID 863
[10] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.2
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.5.4
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.8
[13] S. J. Friedl SQL Injection Attacks by Example