Scrubs xss content in a JavaScript object
npm install xss-scrubberjavascript
const JsonScrubber = require("xss-scrubber");
...
...
console.log(JsonScrubber(obj));
`Examples
`javascript
String
console.log(JsonScrubber(''));
// <script>alert("xss");</script> Array
console.log(JsonScrubber(['
hi! this is @ test', 123, '', 'a']));
// [ '<img>hi! this is @ test</img>',123,'<script>alert("xss");</script>','a' ]
Object
console.log(JsonScrubber({
"entry":[{
"comments":"Test REST API Comments.",
"color":"color10",
"@name": {
"first": [{
"second": "rn_tag "
}]
}
}]
}));
// {
"entry":[{
"comments":"<script>alert('xss');</script>Test REST API Comments.",
"color":"color10",
"@name": {
"first": [{
"second": "<alert>rn_tag</alert>"
}]
}
}]
}
``