no-v-html.js 904 B

1234567891011121314151617181920212223242526272829303132333435
  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. category: 'recommended',
  16. url: 'https://eslint.vuejs.org/rules/no-v-html.html'
  17. },
  18. fixable: null,
  19. schema: []
  20. },
  21. create (context) {
  22. return utils.defineTemplateBodyVisitor(context, {
  23. "VAttribute[directive=true][key.name='html']" (node) {
  24. context.report({
  25. node,
  26. loc: node.loc,
  27. message: "'v-html' directive can lead to XSS attack."
  28. })
  29. }
  30. })
  31. }
  32. }