no-v-html.js 1007 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * @fileoverview Restrict or warn use of v-html to prevent XSS attack
  3. * @author Nathan Zeplowitz
  4. */
  5. 'use strict'
  6. const utils = require('../utils')
  7. // ------------------------------------------------------------------------------
  8. // Rule Definition
  9. // ------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. type: 'suggestion',
  13. docs: {
  14. description: 'disallow use of v-html to prevent XSS attack',
  15. categories: ['vue3-recommended', 'recommended'],
  16. url: 'https://eslint.vuejs.org/rules/no-v-html.html'
  17. },
  18. fixable: null,
  19. schema: []
  20. },
  21. /** @param {RuleContext} context */
  22. create(context) {
  23. return utils.defineTemplateBodyVisitor(context, {
  24. /** @param {VDirective} node */
  25. "VAttribute[directive=true][key.name.name='html']"(node) {
  26. context.report({
  27. node,
  28. loc: node.loc,
  29. message: "'v-html' directive can lead to XSS attack."
  30. })
  31. }
  32. })
  33. }
  34. }