no-document-domain.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) Microsoft Corporation.
  2. // Licensed under the MIT License.
  3. /**
  4. * @fileoverview Rule to disallow document.domain property
  5. * @author Antonios Katopodis
  6. */
  7. "use strict";
  8. const astUtils = require("../ast-utils");
  9. //------------------------------------------------------------------------------
  10. // Rule Definition
  11. //------------------------------------------------------------------------------
  12. module.exports = {
  13. meta: {
  14. type: "suggestion",
  15. fixable: "code",
  16. schema: [],
  17. docs: {
  18. category: "Security",
  19. description: "Writes to [`document.domain`](https://developer.mozilla.org/en-US/docs/Web/API/Document/domain) property must be reviewed to avoid bypass of [same-origin checks](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#Changing_origin). Usage of top level domains such as `azurewebsites.net` is strictly prohibited.",
  20. url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-document-domain.md"
  21. },
  22. messages: {
  23. default: 'Do not write to document.domain property'
  24. }
  25. },
  26. create: function(context) {
  27. const fullTypeChecker = astUtils.getFullTypeChecker(context);
  28. return {
  29. "AssignmentExpression[operator='='][left.property.name='domain']"(node) {
  30. if (astUtils.isDocumentObject(node.left.object, context, fullTypeChecker)) {
  31. context.report(
  32. {
  33. node: node,
  34. messageId: "default"
  35. });
  36. }
  37. }
  38. };
  39. }
  40. };