How to prevent params injection?
exports.create = function (req, res, next) {
var newUser = new User(req.body);
here we use req.body to create a new user, but what if I use curl to post a request with {role: admin} added to params, will this be a bug? is there any whitelist mechanism in ExpressJS?
If you have admin roles, you're screwed... But, to prevent human fails, you can make a security token system.
The token is sent only when the user click a button ( for example, create account) and it uses the clock time (Still being an example) and ip adress to generate the token code.
Greetings
PD: You must create the validator in the backend too. Dont make it impossible or NSA cool stuff, rsa algorithm.... be logic
If you look here, you'll see that role is always set to user.
Or...you just create a new user with fixed data. For example:
var newUser = new User({
email: req.body.email,
password: req.body.password,
username: req.body.username
});
But Awk34 is right. It's always set to user.