xss.js 572 B

12345678910111213141516171819202122232425262728
  1. class Xss {
  2. constructor(isAllowAllAttrs) {
  3. const xss = require('xss');
  4. // create the option object
  5. let option = {
  6. stripIgnoreTag: true,
  7. css: false,
  8. escapeHtml: (html) => html,
  9. };
  10. if (isAllowAllAttrs) {
  11. // allow all attributes
  12. option.onTagAttr = function(tag, name, value, isWhiteAttr) {
  13. return `${name}="${value}"`;
  14. }
  15. }
  16. // create the XSS Filter instance
  17. this.myxss = new xss.FilterXSS(option);
  18. }
  19. process(markdown) {
  20. return this.myxss.process(markdown);
  21. }
  22. }
  23. module.exports = Xss;