From 508c562243fe667428f1781eeb596c7ee74a52fd Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Apr 2021 16:23:09 +0530 Subject: [PATCH 01/10] Fix singlequotes eslint warnings --- .../cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js | 2 +- .../report-components/security/issues/SharedPasswordsIssue.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js index 3a43f1a44..db8ca17f6 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js @@ -27,7 +27,7 @@ function RunOptions(props) { .then(res => { let commandServers = res.configuration.internal.island_server.command_servers; let ipAddresses = commandServers.map(ip => { - return ip.split(":", 1); + return ip.split(':', 1); }); setIps(ipAddresses); setInitialized(true); diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js b/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js index 2a09dbb83..5d114a520 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/security/issues/SharedPasswordsIssue.js @@ -3,11 +3,11 @@ import CollapsibleWellComponent from '../CollapsibleWell'; import {generateInfoBadges} from './utils'; export function sharedPasswordsIssueOverview() { - return (
  • Multiple users have the same password
  • ) + return (
  • Multiple users have the same password
  • ) } export function sharedAdminsDomainIssueOverview() { - return (
  • Shared local administrator account - Different machines have the same account as a local + return (
  • Shared local administrator account - Different machines have the same account as a local administrator.
  • ) } From f267e5bbc082864b2c9c67e3f38421d28e1c93f9 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Apr 2021 16:28:57 +0530 Subject: [PATCH 02/10] Fix unused variable eslint warnings --- .../cc/ui/src/components/reactive-graph/ReactiveGraph.js | 1 - .../ui/src/components/report-components/SecurityReport.js | 2 +- .../report-components/security/IssueDescriptor.js | 7 ------- 3 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 monkey/monkey_island/cc/ui/src/components/report-components/security/IssueDescriptor.js diff --git a/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js b/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js index 8d8611eb6..7ffe9ae7d 100644 --- a/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js +++ b/monkey/monkey_island/cc/ui/src/components/reactive-graph/ReactiveGraph.js @@ -1,6 +1,5 @@ import React from 'react'; import Graph from 'react-graph-vis'; -import Dimensions from 'react-dimensions' class GraphWrapper extends React.Component { diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js index 8486dd547..041e6384e 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js @@ -597,7 +597,7 @@ class ReportPageComponent extends AuthComponent { generateIssue = (issue) => { let issueDescriptor = this.IssueDescriptorEnum[issue.type]; - let reportFnc = (issue) => {}; + let reportFnc = {}; if (issue.hasOwnProperty('credential_type') && issue.credential_type !== null) { reportFnc = issueDescriptor[this.issueContentTypes.REPORT][issue.credential_type]; } else { diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/security/IssueDescriptor.js b/monkey/monkey_island/cc/ui/src/components/report-components/security/IssueDescriptor.js deleted file mode 100644 index 330bf3828..000000000 --- a/monkey/monkey_island/cc/ui/src/components/report-components/security/IssueDescriptor.js +++ /dev/null @@ -1,7 +0,0 @@ -class IssueDescriptor { - constructor(name, overviewComponent, reportComponent) { - this.name = name; - this.overviewComponent = overviewComponent; - this.reportComponent = reportComponent; - } -} From bbfc0d4130b534a173db7012f44934ec08f58f29 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Apr 2021 17:20:31 +0530 Subject: [PATCH 03/10] Fix "Component definition is missing display name" eslint warnings --- .../report-components/zerotrust/PrinciplesStatusTable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PrinciplesStatusTable.js b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PrinciplesStatusTable.js index 6b1d22f6f..1296c3086 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PrinciplesStatusTable.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PrinciplesStatusTable.js @@ -12,7 +12,7 @@ const columns = [ columns: [ { Header: 'Status', id: 'status', - accessor: x => { + accessor: function getAccessor (x) { return ; }, maxWidth: MAX_WIDTH_STATUS_COLUMN @@ -24,7 +24,7 @@ const columns = [ { Header: 'Monkey Tests', id: 'tests', style: {'whiteSpace': 'unset'}, // This enables word wrap - accessor: x => { + accessor: function getAccessor (x) { return ; } } From e74e20536892f756c934f31dd5f2ba1e4acbb8b1 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Apr 2021 17:21:38 +0530 Subject: [PATCH 04/10] Fix trailing comma eslint warnings --- .../cc/ui/src/components/report-components/SecurityReport.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js index 041e6384e..c95df5c84 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js @@ -58,7 +58,7 @@ class ReportPageComponent extends AuthComponent { credentialTypes = { PASSWORD: 'password', HASH: 'hash', - KEY: 'key', + KEY: 'key' } issueContentTypes = { @@ -152,7 +152,7 @@ class ReportPageComponent extends AuthComponent { [this.issueContentTypes.TYPE]: this.issueTypes.DANGER }, 'zerologon_pass_restore_failed': { - [this.issueContentTypes.OVERVIEW]: zerologonOverviewWithFailedPassResetWarning, + [this.issueContentTypes.OVERVIEW]: zerologonOverviewWithFailedPassResetWarning }, 'island_cross_segment': { [this.issueContentTypes.OVERVIEW]: crossSegmentIssueOverview, From c736560f09592fb88e60d5382ef6755aecf0462d Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Apr 2021 17:30:17 +0530 Subject: [PATCH 05/10] Fix "Do not access Object.prototype method 'hasOwnProperty' from target object" eslint warnings --- .../pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js | 2 +- .../src/components/report-components/SecurityReport.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js index eba4cf0f3..a1c3cb491 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js @@ -56,7 +56,7 @@ const getContents = (props) => { // update existing state, not run-over let prevRes = result; for (let key in result) { - if (result.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(result, key)) { prevRes[key] = result[key]; } } diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js index c95df5c84..c9fdd2c52 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/SecurityReport.js @@ -437,9 +437,9 @@ class ReportPageComponent extends AuthComponent { isIssuePotentialSecurityIssue(issueName) { let issueDescriptor = this.IssueDescriptorEnum[issueName]; - return issueDescriptor.hasOwnProperty(this.issueContentTypes.TYPE) && + return Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.TYPE) && issueDescriptor[this.issueContentTypes.TYPE] === this.issueTypes.WARNING && - issueDescriptor.hasOwnProperty(this.issueContentTypes.OVERVIEW); + Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.OVERVIEW); } getImmediateThreats() { @@ -476,9 +476,9 @@ class ReportPageComponent extends AuthComponent { isIssueImmediateThreat(issueName) { let issueDescriptor = this.IssueDescriptorEnum[issueName]; - return issueDescriptor.hasOwnProperty(this.issueContentTypes.TYPE) && + return Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.TYPE) && issueDescriptor[this.issueContentTypes.TYPE] === this.issueTypes.DANGER && - issueDescriptor.hasOwnProperty(this.issueContentTypes.OVERVIEW); + Object.prototype.hasOwnProperty.call(issueDescriptor, this.issueContentTypes.OVERVIEW); } getImmediateThreatsOverviews() { @@ -598,7 +598,7 @@ class ReportPageComponent extends AuthComponent { let issueDescriptor = this.IssueDescriptorEnum[issue.type]; let reportFnc = {}; - if (issue.hasOwnProperty('credential_type') && issue.credential_type !== null) { + if (Object.prototype.hasOwnProperty.call(issue, 'credential_type') && issue.credential_type !== null) { reportFnc = issueDescriptor[this.issueContentTypes.REPORT][issue.credential_type]; } else { reportFnc = issueDescriptor[this.issueContentTypes.REPORT]; From 2d8aef8bebcdf3535b449d02e7b1b3478cbff847 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Apr 2021 17:45:52 +0530 Subject: [PATCH 06/10] Add pre-commit hook for eslint --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43e62e2f3..8065df524 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,7 @@ repos: - id: detect-private-key - id: end-of-file-fixer - id: trailing-whitespace + - repo: https://github.com/eslint/eslint + rev: v7.24.0 + hooks: + - id: eslint From d01de96e950d24bfc08547729fd4f4e565ab60ee Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Apr 2021 18:43:37 +0530 Subject: [PATCH 07/10] Change max JS warnings limit to 0 in travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d57069c05..318045d68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,7 +71,7 @@ script: - cd monkey_island/cc/ui - npm ci # See https://docs.npmjs.com/cli/ci.html - eslint ./src --quiet # Test for errors -- JS_WARNINGS_AMOUNT_UPPER_LIMIT=7 +- JS_WARNINGS_AMOUNT_UPPER_LIMIT=0 - eslint ./src --max-warnings $JS_WARNINGS_AMOUNT_UPPER_LIMIT # Test for max warnings # Build documentation From 3cf538401687309d159584170fecae3afd82b15c Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 13 Apr 2021 12:00:43 +0530 Subject: [PATCH 08/10] Add arguments to eslint pre-commit hook --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8065df524..b06e9ce56 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,4 @@ repos: rev: v7.24.0 hooks: - id: eslint + args: ["monkey/monkey_island/cc/ui/src/", "--fix"] From 0961471e3860d84958abab5621e1e028850e8ce4 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 13 Apr 2021 12:39:55 +0530 Subject: [PATCH 09/10] Add pre-commit section to development setup documentation --- docs/content/development/setup-development-environment.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/content/development/setup-development-environment.md b/docs/content/development/setup-development-environment.md index d558b11ce..af4aa5e8a 100644 --- a/docs/content/development/setup-development-environment.md +++ b/docs/content/development/setup-development-environment.md @@ -23,3 +23,11 @@ This means setting up an environment with Linux 32/64-bit with Python installed The Monkey Island is a Python backend React frontend project. Similar to the agent, the backend's requirements are listed in the matching [`requirements.txt`](https://github.com/guardicore/monkey/blob/master/monkey/monkey_island/requirements.txt). To setup a working front environment, run the instructions listed in the [`readme.txt`](https://github.com/guardicore/monkey/blob/master/monkey/monkey_island/readme.txt) + +## Pre-commit + +Pre-commit is a multi-language package manager for pre-commit hooks. It will run a set of checks when you attempt to commit. If your commit does not pass all checks, it will be reformatted and/or you'll be given a list of errors and warnings that need to be fixed before you can commit. + +Our CI system runs the same checks when pull requests are submitted. This system may report that the build has failed if the pre-commit hooks have not been run or all issues have not been resolved. + +To install and configure pre-commit, run `pip install --user pre-commit`. Next, go to the top level directory of this repository and run `pre-commit install`. Pre-commit will now run automatically whenever you `git commit`. From 905b095dd8decaeb14ab60691d98a40f46206a14 Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 15 Apr 2021 16:11:09 +0530 Subject: [PATCH 10/10] Add --max-warnings=0 to eslint precommit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b06e9ce56..2bceacbcc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,4 +32,4 @@ repos: rev: v7.24.0 hooks: - id: eslint - args: ["monkey/monkey_island/cc/ui/src/", "--fix"] + args: ["monkey/monkey_island/cc/ui/src/", "--fix", "--max-warnings=0"]