如果沒有適當的 access control,執行一個包含用戶控制主鍵的 SQLite 指令會允許攻擊者訪問未經授權的記錄。
在以下情況下,SQLite 查詢會發生 access control 錯誤:
1. 數據從一個不可信賴的數據源進入程序。
2. 這個數據用來指定 SQLite 查詢中主鍵的值。
例 1: 以下代碼用到一個參數化指令,這個指令轉義了元字符和防止 query string injection 漏洞,并構建和執行一個 SQLite 查詢,以搜索與用戶指定標識符相匹配的清單。
...
id = this.getIntent().getExtras().getInt("id");
cursor = db.query(Uri.parse(invoices), columns, "id = ?", {id}, null, null, null);
...
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] Android Developers-Reference:SQLite Database
[6] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3510 CAT I
[7] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3510 CAT I
[8] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 566
[9] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) Insufficient Authorization
[10] Standards Mapping - SANS Top 25 2011 - (SANS Top 25 2011) Porous Defenses - CWE ID 863
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.2
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.5.4
[13] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.8
[14] S. J. Friedl SQL Injection Attacks by Example