fix: [security] eval() 제거 — SafeMathEvaluator로 교체

- FormulaParser의 eval() 2곳 제거 (executeSimpleMath, evaluateCondition)
- FormulaEvaluatorService의 eval() 1곳 제거 (calculateExpression)
- Shunting-yard 알고리즘 기반 SafeMathEvaluator 신규 추가
- 사칙연산, 비교연산, 단항 마이너스, 괄호, 나머지 연산 지원
This commit is contained in:
김보곤
2026-03-15 10:20:39 +09:00
parent 9d95b2c373
commit d8560d889c
3 changed files with 315 additions and 5 deletions

View File

@@ -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);
}
/**