xss.js 538 B

123456789101112131415161718192021222324252627
  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. };
  9. if (isAllowAllAttrs) {
  10. // allow all attributes
  11. option.onTagAttr = function(tag, name, value, isWhiteAttr) {
  12. return `${name}="${value}"`;
  13. }
  14. }
  15. // create the XSS Filter instance
  16. this.myxss = new xss.FilterXSS(option);
  17. }
  18. process(markdown) {
  19. return this.myxss.process(markdown);
  20. }
  21. }
  22. module.exports = Xss;