From ff28509d0d93719577ec90acfc4863e0d0daef1a Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 25 Feb 2021 19:41:36 -0500 Subject: [PATCH] ui: fix race in unsafe confirmation modal dialog --- .../ui/src/components/pages/ConfigurePage.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index dc054ffce..53dcdf27c 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -86,9 +86,9 @@ class ConfigurePageComponent extends AuthComponent { {unsafeOptionsConfirmed: true, showUnsafeOptionsConfirmation: false}, () => { if (this.state.lastAction == 'submit_attempt') { - this.onSubmit(); + this.attemptConfigSubmit(); } else if (this.state.lastAction == 'import_attempt') { - this.setConfigFromCandidateJson(this.state.candidateConfigJson); + this.attemptSetConfigFromCandidateJson(this.state.candidateConfigJson); } } ); @@ -107,7 +107,7 @@ class ConfigurePageComponent extends AuthComponent { if (this.state.selectedSection === 'attack') { this.matrixSubmit() } else { - this.configSubmit() + this.attemptConfigSubmit() } }; @@ -180,11 +180,13 @@ class ConfigurePageComponent extends AuthComponent { }); }; - configSubmit = () => { - // Submit monkey configuration - this.setState({lastAction: 'submit_attempt'}); + attemptConfigSubmit() { this.updateConfigSection(); + this.setState({lastAction: 'submit_attempt'}, this.configSubmit()); + } + configSubmit() { + // Submit monkey configuration if (!this.canSafelySubmitConfig(this.state.configuration)) { this.setState({showUnsafeOptionsConfirmation: true}); return; @@ -348,7 +350,13 @@ class ConfigurePageComponent extends AuthComponent { } setConfigOnImport = (event) => { - this.setConfigFromCandidateJson(event.target.result); + this.attemptSetConfigFromCandidateJson(event.target.result); + } + + attemptSetConfigFromCandidateJson(newConfigCandidateJson){ + this.setState({lastAction: 'import_attempt', candidateConfigJson: newConfigCandidateJson}, + this.setConfigFromCandidateJson(newConfigCandidateJson) + ); } setConfigFromCandidateJson(newConfigCandidateJson){