Script Injection Attacks
If you are using JavaScript, make sure that any variables that cross the PHP-
to-JavaScript boundry are passed in the For example, suppose we have some JavaScript to greet a user in the database logs. We could do:
However, what if a malicious user passes in some JavaScript?
Now MongoDB executes the JavaScript string
This adds an argument to the JavaScript scope, which gets used as argument
for the Using arguments helps to prevent malicious input from being executed by the database. However, you must make sure that your code does not turn around and execute the input anyway! It is best to avoid executing any JavaScript on the server in the first place. You are strongly recommended to stay clear of the » $where clause with queries, as it impacts performance significantly. Where possible, use either normal query operators, or the » Aggregation Framework. As alternative to » MapReduce, which uses JavaScript, consider using the » Aggregation Framework. Unlike Map/Reduce, it uses an idiomatic language to construct queries, without having to write, and use, the slower JavaScript approach that Map/Reduce requires. The » eval command has been deprecated since MongoDB 3.0, and should also be avoided. |