Answer the question
In order to leave comments, you need to log in
Do I need to filter values written to MongoDB?
Currently filtering everything that should get into MongoDB using validator.js
var value = sanitizer.sanitize('возможный xss');
db.collection.update({"_id": ObjectId(...)}, {"name": value});
var HTML_CHARS = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`'
}
var escapeHTML = function (html) {
return html.replace(/[&<>"'\/`]/g, function (match) {
return HTML_CHARS[match];
});
};
var cleaned = escapeHTML("возможный xss");
Answer the question
In order to leave comments, you need to log in
Checking for xss should be done when generating html. Checking on save is just an added bonus. And about checking for xss https://github.com/chriso/validator.js#deprecations
For Mongo, as for any DBMS, injection checking is important. You can start with an article on Habré and an article on null byte
You can use ORM Waterline, where validators already exist.
In general, it's better to do checks on both the client and the server - that's right :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question