Files
cgm-remote-monitor/lib/server/purifier.js
T
Sulka HaroandGitHub 914ba78f36 Security improvement batch (#6622)
* Adds a new method for the server to push notifies to the client, which require administration privileges from the user. If there are messages in queue but user is not privileged, she is notified of pending messages

* Fix unit tests

* Increase timeouts on tests

* Add translations

* * Aggregate admin messages
* Send admin message on auth fail
* Sending messages over bus
* XSS filtering of objects sent over the REST API

* Warn users if their instance is world readable

* Fix adminnotifies init()

* Fix couple issues from Codacy
2021-01-07 22:46:55 +02:00

37 lines
768 B
JavaScript

'use strict';
const createDOMPurify = require('dompurify');
const { JSDOM } = require('jsdom');
const window = new JSDOM('').window;
const DOMPurify = createDOMPurify(window);
function init (env, ctx) {
const purifier = {};
function iterate (obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
if (typeof obj[property] == 'object')
iterate(obj[property]);
else
if (isNaN(obj[property])) {
const clean = DOMPurify.sanitize(obj[property]);
if (obj[property] !== clean) {
obj[property] = clean;
}
}
}
}
}
purifier.purifyObject = function purifyObject (obj) {
return iterate(obj);
}
return purifier;
}
module.exports = init;