Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attack config unsafe warning #1006

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import {Modal, Button} from 'react-bootstrap';

function UnsafeOptionsConfirmationModal(props) {
return (
<Modal show={props.show}>
<Modal.Body>
<h2>
<div className='text-center'>Warning</div>
</h2>
<p className='text-center' style={{'fontSize': '1.2em', 'marginBottom': '2em'}}>
Some of the selected options could cause systems to become unstable or malfunction.
</p>
<div className='text-center'>
<Button type='button'
className='btn btn-danger'
size='lg'
style={{margin: '5px'}}
onClick={props.onContinueClick}>
Continue
</Button>
</div>
</Modal.Body>
</Modal>
)
}

export default UnsafeOptionsConfirmationModal;
33 changes: 28 additions & 5 deletions monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {formValidationFormats} from '../configuration-components/ValidationForma
import transformErrors from '../configuration-components/ValidationErrorMessages';
import InternalConfig from '../configuration-components/InternalConfig';
import UnsafeOptionsConfirmationModal from '../configuration-components/UnsafeOptionsConfirmationModal.js';
import UnsafeOptionsWarningModal from '../configuration-components/UnsafeOptionsWarningModal.js';
import isUnsafeOptionSelected from '../utils/SafeOptionValidator.js';

const ATTACK_URL = '/api/attack';
Expand All @@ -38,7 +39,8 @@ class ConfigurePageComponent extends AuthComponent {
sections: [],
selectedSection: 'attack',
showAttackAlert: false,
showUnsafeOptionsConfirmation: false
showUnsafeOptionsConfirmation: false,
showUnsafeAttackOptionsWarning: false
};
}

Expand Down Expand Up @@ -92,12 +94,17 @@ class ConfigurePageComponent extends AuthComponent {
}
}

updateConfig = () => {
onUnsafeAttackContinueClick = () => {
this.setState({showUnsafeAttackOptionsWarning: false});
}


updateConfig = (callback=null) => {
this.authFetch(CONFIG_URL)
.then(res => res.json())
.then(data => {
this.setInitialConfig(data.configuration);
this.setState({configuration: data.configuration});
this.setState({configuration: data.configuration}, callback);
})
};

Expand Down Expand Up @@ -130,14 +137,20 @@ class ConfigurePageComponent extends AuthComponent {
.then(() => {
this.setInitialAttackConfig(this.state.attackConfig);
})
.then(this.updateConfig())
.then(this.setState({lastAction: 'saved'}))
.then(() => this.updateConfig(this.checkAndShowUnsafeAttackWarning))
.then(() => this.setState({lastAction: 'saved'}))
.catch(error => {
console.log('Bad configuration: ' + error.toString());
this.setState({lastAction: 'invalid_configuration'});
});
};

checkAndShowUnsafeAttackWarning = () => {
if (isUnsafeOptionSelected(this.state.schema, this.state.configuration)) {
this.setState({showUnsafeAttackOptionsWarning: true});
}
}

attemptConfigSubmit() {
this.updateConfigSection();
this.setState({lastAction: 'submit_attempt'}, () => {
Expand Down Expand Up @@ -243,6 +256,15 @@ class ConfigurePageComponent extends AuthComponent {
);
}

renderUnsafeAttackOptionsWarningModal() {
return (
<UnsafeOptionsWarningModal
show={this.state.showUnsafeAttackOptionsWarning}
onContinueClick={this.onUnsafeAttackContinueClick}
/>
);
}

userChangedConfig() {
if (JSON.stringify(this.state.configuration) === JSON.stringify(this.initialConfig)) {
if (Object.keys(this.currentFormData).length === 0 ||
Expand Down Expand Up @@ -468,6 +490,7 @@ class ConfigurePageComponent extends AuthComponent {
className={'main'}>
{this.renderAttackAlertModal()}
{this.renderUnsafeOptionsConfirmationModal()}
{this.renderUnsafeAttackOptionsWarningModal()}
<h1 className='page-title'>Monkey Configuration</h1>
{this.renderNav()}
{content}
Expand Down