Dynamic Code Execution (ARCH4131)
هذا المحتوى غير متوفر بلغتك بعد.
Key java.security.dynamic-code-execution · Severity critical · Category security · CWE CWE-95
Running a string from user input through a script engine (ScriptEngine) leads directly to remote code execution (RCE). Use a safe construct that interprets data, not code.
Incorrect
Section titled “Incorrect”ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");Object result = engine.eval(request.getParameter("expr")); // executes user codeCorrect
Section titled “Correct”// Do not run user input as code; use a constrained expression evaluatorExpression expr = new SpelExpressionParser().parseExpression(allowedFormula);Object result = expr.getValue(new StandardEvaluationContext(safeRoot));Never evaluate user input as code; use a constrained rule/expression evaluator or allowlisted operations.