У меня есть веб-сайт, на котором пользователь вводит математические уравнения (выражения), а затем эти уравнения оцениваются с данными (константами), предоставляемыми веб-сайтом. Необходимые математические операции включают символы, арифметические операции, min()
, max()
и некоторые другие основные функции. Образцовое уравнение может быть:
max(a * b + 100, a / b - 200)
Можно просто eval()
использовать Python, но, как мы все знаем, это приводит к компрометации сайта. Каким будет безопасный подход к оценке математического уравнения?
-
Какие механизмы анализа и оценки математического уравнения существуют для Python
-
Если кто-то хочет использовать сам Python для оценки выражения, есть ли какие-либо песочницы Python, которые ограничивали бы Python, так что доступны только операторы и функции поставщика. Полноценный Python, как и определение функций, должен быть полностью отключен. Подпроцессы в порядке (см. PyPy sandbox). Специально для циклов и других отверстий для использования памяти и использования ЦП необходимо закрыть.
-
Любые другие подходы, например. используя двоичный файл командной строки (bc)?