fix: [security] eval() 제거 — SafeMathEvaluator로 교체
- FormulaParser의 eval() 2곳 제거 (executeSimpleMath, evaluateCondition) - FormulaEvaluatorService의 eval() 1곳 제거 (calculateExpression) - Shunting-yard 알고리즘 기반 SafeMathEvaluator 신규 추가 - 사칙연산, 비교연산, 단항 마이너스, 괄호, 나머지 연산 지원
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services\Calculation;
|
||||
|
||||
use App\Helpers\SafeMathEvaluator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FormulaParser
|
||||
@@ -230,8 +231,8 @@ protected function executeSimpleMath(string $formula, array $variables): float
|
||||
throw new \InvalidArgumentException("안전하지 않은 수학 표현식: {$expression}");
|
||||
}
|
||||
|
||||
// 계산 실행
|
||||
return eval("return {$expression};");
|
||||
// 안전한 산술 파서로 계산 실행
|
||||
return SafeMathEvaluator::calculate($expression);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,7 +277,7 @@ protected function evaluateCondition(string $condition, array $variables): bool
|
||||
throw new \InvalidArgumentException("안전하지 않은 조건식: {$expression}");
|
||||
}
|
||||
|
||||
return eval("return {$expression};");
|
||||
return SafeMathEvaluator::compare($expression);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user