no-electron-node-integration.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) Microsoft Corporation.
  2. // Licensed under the MIT License.
  3. /**
  4. * @fileoverview Rule to disallow enabling Node.js integration in Electron apps
  5. */
  6. "use strict";
  7. //------------------------------------------------------------------------------
  8. // Rule Definition
  9. //------------------------------------------------------------------------------
  10. module.exports = {
  11. meta: {
  12. type: "suggestion",
  13. fixable: "code",
  14. schema: [],
  15. docs: {
  16. category: "Security",
  17. description: "[Node.js Integration](https://www.electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content) must not be enabled in any renderer that loads remote content to avoid remote code execution attacks.",
  18. url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-electron-node-integration.md"
  19. },
  20. messages: {
  21. default: "Do not enable Node.js Integration for Remote Content"
  22. }
  23. },
  24. create: function(context) {
  25. return {
  26. "NewExpression[callee.name=/BrowserWindow|BrowserView/] > ObjectExpression.arguments > Property.properties[key.name=webPreferences] > ObjectExpression.value > Property.properties[key.name=/nodeIntegration|nodeIntegrationInWorker|nodeIntegrationInSubFrames/][value.value='true']"(node) {
  27. context.report(
  28. {
  29. node: node,
  30. messageId: "default"
  31. });
  32. }
  33. };
  34. }
  35. };