OGNL 삽입 (OGNL Injection)
Expression Injection (OGNL Injection)
Last updated
Expression Injection (OGNL Injection)
Last updated
import com.opensymphony.xwork2.ognl.OgnlUtil;
@RequestMapping("/executeOgnl")
public String executeOgnl(@RequestParam String expression) throws Exception {
Object result = OgnlUtil.getValue(expression, null, null);
return "Executed";
}import org.apache.struts2.util.StrutsUtil;
@RequestMapping("/safeExecute")
public String safeExecute(@RequestParam String expression) {
// 허용된 안전한 입력 값만 처리
if (!isValidExpression(expression)) {
return "Invalid expression";
}
return "Safe execution completed";
}
private boolean isValidExpression(String expression) {
// 허용된 OGNL 표현식만 허용하는 방식으로 제한
return expression.matches("^[a-zA-Z0-9_]+$");
}