xss.js 977 B

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