[java] Dynamic code execution should not be vulnerable to injection attacks
Applications that execute code dynamically should neutralize any externally-provided values used to construct the code. Failure to do so could allow an attacker to execute arbitrary code. This could enable a wide range of serious attacks like accessing/modifying sensitive information or gain full system access.
The mitigation strategy should be based on whitelisting of allowed values or casting to safe types.
Noncompliant Code Example
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String input = req.getParameter("input");
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
engine.eval(input); // Noncompliant
}
Compliant Solution
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String input = req.getParameter("input");
// Match the input against a whitelist
if (!whiteList.contains(input))
throw new IOException();
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
engine.eval(input);
}
'Secure Coding' 카테고리의 다른 글
XPath 인젝션 공격 (0) | 2021.09.17 |
---|---|
데이터베이스에 연결 시 암호 보안 (0) | 2021.09.17 |
데이터베이스 쿼리 인젝션 공격 (0) | 2021.09.17 |
Reflected cross-site scripting (XSS) 공격 (0) | 2021.09.17 |
역직렬화 인젝셕 (0) | 2021.09.17 |
댓글