xss.js 771 B

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