This whitelist seems safe for me, but it is not such an easy question. In some browsers, for example, the same line:
/.(.)/(34)
equivalent to this:
new RegExp('.(.)').exec('34')
and therefore returns an array ['34','4'] . It's safe"?
Thus, although the approach can probably be made secure, it can be a very complex proposition. If you go ahead with this idea, I think you should use a much more aggressive approach to validate your inputs. Your principle should be "this is a member of a well-defined rowset that is known to be" safe ", and not" this is a member of a poorly defined rowset that excludes all rows that are known to be "unsafe" "". In addition, in order to avoid the risk that the operators looked in that you did not consider (for example, ++ or += or something else), I think you should insert a space before each character other than a digit, and to avoid the risk the occurrence of parentheses that cause the function to be called, I think you should deal with them yourself by repeatedly replacing (...) space plus an evaluation result ... (after confirming that this result is a number) plus a space.
(By the way, how did it happen = in your whitelist? I just canβt understand that this is useful!)
ruakh Mar 31 '12 at 16:15 2012-03-31 16:15
source share