no-angular-bypass-sanitizer.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) Microsoft Corporation.
  2. // Licensed under the MIT License.
  3. /**
  4. * @fileoverview Rule to disallow bypassing Angular's built-in sanitizer
  5. * @author Antonios Katopodis
  6. */
  7. "use strict";
  8. //------------------------------------------------------------------------------
  9. // Rule Definition
  10. //------------------------------------------------------------------------------
  11. module.exports = {
  12. meta: {
  13. type: "suggestion",
  14. fixable: "code",
  15. schema: [],
  16. docs: {
  17. category: "Security",
  18. description: "Calls to bypassSecurityTrustHtml, bypassSecurityTrustScript and similar methods bypass DomSanitizer in Angular and need to be reviewed.",
  19. url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angular-bypass-sanitizer.md"
  20. },
  21. messages: {
  22. noBypass: "Do not bypass Angular's built-in sanitizer"
  23. }
  24. },
  25. create: function(context) {
  26. return {
  27. "CallExpression[arguments!=''][callee.property.name=/bypassSecurityTrust(Html|ResourceUrl|Script|Style|Url)/]"(node) {
  28. context.report(
  29. {
  30. node: node,
  31. messageId: "noBypass"
  32. });
  33. }
  34. };
  35. }
  36. };