xss.js 892 B

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