I was looking for a patch code that also took into account user-entered formulas.
What you are doing seems to prevent any malicious user code from running on your server, since they will only be allowed letters m, numbers, and mathematical operators.
However, this requires only one bright spark to find a way around it to compromise your system, and I think most will agree that letting the user enter the rating is probably not good practice, no matter how you make it check.
When I studied my problem, I started looking for formula processing libraries, such as those used in spreadsheets. An Excel library, like a library, will accept mathematical expressions and be able to evaluate them safely.
I never went around to verify this, but hopefully if you can find the right option, you can even get backward compatibility with your existing formulas.
Good luck.
source share