HTTP 請求必須包含用戶特有的機密,以防止攻擊者發出未經授權的請求。
跨站點偽裝請求 (CSRF) 漏洞會在以下情況下發生:
1. Web 應用程序使用會話 cookie。
2. 應用程序未驗證請求是否經過用戶同意便處理 HTTP 請求。
如果該請求未包含證明其來源的 nonce,則處理該請求的代碼將易受到 CSRF 攻擊(除非它并未更改應用程序的狀態)。這意味著使用會話 cookie 的 Web 應用程序必須采取特殊的預防措施,確保攻擊者無法誘騙用戶提交偽請求。假設有一個 Web 應用程序,它允許管理員創建新帳戶,如下所示:
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "/new_user");
body = addToPost(body, new_username);
body = addToPost(body, new_passwd);
rb.sendRequest(body, new NewAccountCallback(callback));
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://www.example.com/new_user");
body = addToPost(body, "attacker";
body = addToPost(body, "haha");
rb.sendRequest(body, new NewAccountCallback(callback));
referer 的 HTTP 頭文件。referer 頭文件應該包含參考頁面的 URL,但攻擊者可以偽造,因此無法利用 referer 頭文件確定請求的來源。[1] OWASP 2007 OWASP Top 10
[2] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A5 Cross Site Request Forgery (CSRF)
[3] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A5 Cross-Site Request Forgery (CSRF)
[4] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3585 CAT II
[5] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3585 CAT II
[6] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) Cross-Site Request Forgery
[7] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 352
[8] A. Klein Divide and Conquer:HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
[9] Standards Mapping - SANS Top 25 2009 - (SANS 2009) Insecure Interaction - CWE ID 352
[10] Standards Mapping - SANS Top 25 2010 - (SANS 2010) Insecure Interaction - CWE ID 352
[11] Standards Mapping - SANS Top 25 2011 - (SANS Top 25 2011) Insecure Interaction - CWE ID 352
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.5.5
[13] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.9