no-v-html.js 823 B

1234567891011121314151617181920212223242526272829303132
  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. module.exports = {
  8. meta: {
  9. type: 'suggestion',
  10. docs: {
  11. description: 'disallow use of v-html to prevent XSS attack',
  12. categories: ['vue3-recommended', 'recommended'],
  13. url: 'https://eslint.vuejs.org/rules/no-v-html.html'
  14. },
  15. fixable: null,
  16. schema: []
  17. },
  18. /** @param {RuleContext} context */
  19. create(context) {
  20. return utils.defineTemplateBodyVisitor(context, {
  21. /** @param {VDirective} node */
  22. "VAttribute[directive=true][key.name.name='html']"(node) {
  23. context.report({
  24. node,
  25. loc: node.loc,
  26. message: "'v-html' directive can lead to XSS attack."
  27. })
  28. }
  29. })
  30. }
  31. }