xss.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const logger = require('@alias/logger')('growi:service:XssSerivce'); // eslint-disable-line no-unused-vars
  2. const Xss = require('~/services/xss');
  3. const { tags, attrs } = require('~/services/xss/recommended-whitelist');
  4. /**
  5. * the service class of XssSerivce
  6. */
  7. class XssSerivce {
  8. constructor(configManager) {
  9. this.configManager = configManager;
  10. this.xss = new Xss();
  11. }
  12. process(value) {
  13. return this.xss.process(value);
  14. }
  15. getTagWhiteList() {
  16. const isEnabledXssPrevention = this.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
  17. const xssOpiton = this.configManager.getConfig('markdown', 'markdown:xss:option');
  18. if (isEnabledXssPrevention) {
  19. switch (xssOpiton) {
  20. case 1: // ignore all: use default option
  21. return [];
  22. case 2: // recommended
  23. return tags;
  24. case 3: // custom white list
  25. return this.configManager.getConfig('markdown', 'markdown:xss:tagWhiteList');
  26. default:
  27. return [];
  28. }
  29. }
  30. else {
  31. return [];
  32. }
  33. }
  34. getAttrWhiteList() {
  35. const isEnabledXssPrevention = this.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
  36. const xssOpiton = this.configManager.getConfig('markdown', 'markdown:xss:option');
  37. if (isEnabledXssPrevention) {
  38. switch (xssOpiton) {
  39. case 1: // ignore all: use default option
  40. return [];
  41. case 2: // recommended
  42. return attrs;
  43. case 3: // custom white list
  44. return this.configManager.getConfig('markdown', 'markdown:xss:attrWhiteList');
  45. default:
  46. return [];
  47. }
  48. }
  49. else {
  50. return [];
  51. }
  52. }
  53. }
  54. module.exports = XssSerivce;