xss.js 817 B

123456789101112131415161718192021222324252627282930313233343536
  1. class Xss {
  2. constructor(xssOption) {
  3. const xss = require('xss');
  4. xssOption = xssOption || {};
  5. const tagWhiteList = xssOption.tagWhiteList || [];
  6. const attrWhiteList = xssOption.attrWhiteList || [];
  7. let whiteListContent = {};
  8. // default
  9. let option = {
  10. stripIgnoreTag: true,
  11. stripIgnoreTagBody: false, // see https://github.com/weseek/growi/pull/505
  12. css: false,
  13. whiteList: whiteListContent,
  14. escapeHtml: (html) => html, // resolve https://github.com/weseek/growi/issues/221
  15. };
  16. tagWhiteList.forEach(tag => {
  17. whiteListContent[tag] = attrWhiteList;
  18. });
  19. // create the XSS Filter instance
  20. this.myxss = new xss.FilterXSS(option);
  21. }
  22. process(document) {
  23. return this.myxss.process(document);
  24. }
  25. }
  26. module.exports = Xss;