xss.js 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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: false,
  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. }
  22. else {
  23. option['stripIgnoreTag'] = false;
  24. }
  25. // create the XSS Filter instance
  26. this.myxss = new xss.FilterXSS(option);
  27. }
  28. process(markdown) {
  29. return this.myxss.process(markdown);
  30. }
  31. }
  32. module.exports = Xss;