generator-angular-fullstack icon indicating copy to clipboard operation
generator-angular-fullstack copied to clipboard

How to prevent params injection?

Open Daniel-Xu opened this issue 11 years ago • 3 comments

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?

Daniel-Xu avatar Mar 01 '15 18:03 Daniel-Xu

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

equero-old avatar Jun 24 '15 13:06 equero-old

If you look here, you'll see that role is always set to user.

Awk34 avatar Jun 24 '15 14:06 Awk34

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.

bastiwasni avatar Jun 24 '15 20:06 bastiwasni