界: Input Validation and Representation

輸入驗證和表示法問題是由中繼字元、替代編碼和數值表示法引起的。信任輸入會導致安全問題。問題包括:「Buffer Overflows」、「Cross-Site Scripting」攻擊、「SQL Injection」及其他許多問題。

Same-Origin Method Execution

Abstract
應用程式可將使用者可以控制的參數反映為將由瀏覽器執行的 JavaScript 回呼函數,而這可能會讓攻擊者得以在相同端點的網域上的任何頁面中執行任意 JavaScript 函數。
Explanation
應用程式將由攻擊者控制的參數用作瀏覽器將要執行之 JavaScript 函數的名稱。 攻擊者可能會建立惡意網站,其首先會在應用程式所在相同網域上建立目標頁面的框架,然後參照易受攻擊的頁面,以便在目標頁面上執行任意 JavaScript 函數。 雖然存在一些重要的攻擊限制,但此攻擊的影響與 Cross-Site Scripting 的影響類似。 如果允許將英數字元和點字元用作回呼名稱,則攻擊者將能夠參照頁面上的元素並與之互動。

範例 1: 以下程式碼建構 JSONP 回應,其中回呼函數名稱可由使用者控制。


@ControllerAdvice
public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {
public JsonpAdvice() {
super("callback");
}
}


對於諸如 GET /api/latest.json?callback=myCallbackFunction 的要求,控制項方法會產生一個諸如以下內容的回應:


HTTP/1.1 200 Ok
Content-Type: application/json; charset=utf-8
Date: Tue, 12 Dec 2017 16:16:04 GMT
Server: nginx/1.12.1
Content-Length: 225
Connection: Close

myCallbackFunction({<json>})


攻擊者可以使用 JavaScript Script 標籤從 JSONP 端點載入回應,其會變成執行 myCallbackFunction 函數。 攻擊者可以使用不同的回呼名稱來導覽 DOM 並與之互動。 例如,opener.document.body.someElemnt.firstChild.nextElementSibling.submit 可用來在目標頁面中尋找表單並進行提交。
References
[1] Ben Hayak Same Origin Method Execution (SOME)
[2] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001310
[3] Standards Mapping - NIST Special Publication 800-53 Revision 4 SI-10 Information Input Validation (P1)
[4] Standards Mapping - NIST Special Publication 800-53 Revision 5 SI-10 Information Input Validation
[5] Standards Mapping - OWASP Mobile 2024 M4 Insufficient Input/Output Validation
[6] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection, Control Objective 5.4 - Authentication and Access Control
[7] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection, Control Objective 5.4 - Authentication and Access Control, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation
[8] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection, Control Objective 5.4 - Authentication and Access Control, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation, Control Objective C.3.2 - Web Software Attack Mitigation
[9] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002530 CAT II
[10] Standards Mapping - Security Technical Implementation Guide Version 6.1 APSC-DV-002530 CAT II
desc.semantic.java.same_origin_method_execution
Abstract
應用程式可將使用者可以控制的參數反映為將由瀏覽器執行的 JavaScript 回呼函數,而這可能會讓攻擊者得以在相同端點的網域上的任何頁面中執行任意 JavaScript 函數。
Explanation
應用程式將由攻擊者控制的參數用作瀏覽器將要執行之 JavaScript 函數的名稱。 攻擊者可能會建立惡意網站,其首先會在應用程式所在相同網域上建立目標頁面的框架,然後參照易受攻擊的頁面,以便在目標頁面上執行任意 JavaScript 函數。 雖然存在一些重要的攻擊限制,但此攻擊的影響與 Cross-Site Scripting 的影響類似。 如果允許將英數字元和點字元用作回呼名稱,則攻擊者將能夠參照頁面上的元素並與之互動。

範例 1: 以下程式碼建構 JSONP 回應,其中回呼函數名稱可由使用者控制。


def myJSONPService(callback: String) = Action {
val json = getJSONToBeReturned()
Ok(Jsonp(callback, json))
}


對於諸如 GET /api/latest.json?callback=myCallbackFunction 的要求,Example 1 中所述的控制項方法會產生一個諸如以下內容的回應:


HTTP/1.1 200 Ok
Content-Type: application/json; charset=utf-8
Date: Tue, 12 Dec 2017 16:16:04 GMT
Server: nginx/1.12.1
Content-Length: 225
Connection: Close

myCallbackFunction({<json>})


攻擊者可以使用 JavaScript Script 標籤從 JSONP 端點載入回應,其會變成執行 myCallbackFunction 函數。 攻擊者可以使用不同的回呼名稱來導覽 DOM 並與之互動。 例如,opener.document.body.someElemnt.firstChild.nextElementSibling.submit 可用來在目標頁面中尋找表單並進行提交。
References
[1] Ben Hayak Same Origin Method Execution (SOME)
[2] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001310
[3] Standards Mapping - NIST Special Publication 800-53 Revision 4 SI-10 Information Input Validation (P1)
[4] Standards Mapping - NIST Special Publication 800-53 Revision 5 SI-10 Information Input Validation
[5] Standards Mapping - OWASP Mobile 2024 M4 Insufficient Input/Output Validation
[6] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection, Control Objective 5.4 - Authentication and Access Control
[7] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection, Control Objective 5.4 - Authentication and Access Control, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation
[8] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection, Control Objective 5.4 - Authentication and Access Control, Control Objective B.3.1 - Terminal Software Attack Mitigation, Control Objective B.3.1.1 - Terminal Software Attack Mitigation, Control Objective C.3.2 - Web Software Attack Mitigation
[9] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002530 CAT II
[10] Standards Mapping - Security Technical Implementation Guide Version 6.1 APSC-DV-002530 CAT II
desc.dataflow.scala.same_origin_method_execution