def delete_tags(finding_id: str, vulnerabilities: List[str]) -> bool: success = [] for vulnerability in vulnerabilities: result = vuln_dal.update(finding_id, vulnerability, {'tag': []}) success.append(result) return all(success)
def mask_vuln(finding_id: str, vuln_id: str) -> bool: success = vuln_dal.update(finding_id, vuln_id, { 'specific': 'Masked', 'where': 'Masked' }) return success
def update_treatment_in_vuln(finding_id: str, updated_values: Dict[str, str]) -> bool: new_values = cast( Dict[str, FindingType], { 'treatment': updated_values.get('treatment', ''), 'treatment_justification': updated_values.get('justification'), 'acceptance_date': updated_values.get('acceptance_date'), }) if new_values['treatment'] == 'NEW': new_values['treatment_manager'] = None vulns = get_vulnerabilities(finding_id) resp = True for vuln in vulns: if 'treatment_manager' not in [vuln, new_values]: new_values[ 'treatment_manager'] = vuln_domain.set_treatment_manager( str(new_values.get('treatment', '')), str(updated_values.get('user', '')), finding_dal.get_finding(finding_id), user_domain.get_data(str(updated_values.get('user')), 'role') == 'customeradmin', str(updated_values.get('user', ''))) result_update_treatment = \ vuln_dal.update(finding_id, str(vuln.get('UUID', '')), new_values) if not result_update_treatment: resp = False return resp
def update_vuln_state(info, vulnerability: List[Dict[str, str]], item: Dict[str, str], finding_id: str, current_day: str) -> bool: """Update vulnerability state.""" historic_state = cast(List[Dict[str, str]], vulnerability[0].get('historic_state')) last_state = historic_state[len(historic_state) - 1] response = False if last_state.get('state') != item.get('state'): historic_state = [] user_data = cast(UserType, util.get_jwt_content(info.context)) analyst = str(user_data['user_email']) if util.is_api_token(user_data): current_state = { 'date': current_day, 'state': item.get('state', ''), 'origin': item.get('origin', ''), 'approval_status': 'PENDING', 'analyst': 'api-{email}'.format(email=analyst) } else: current_state = { 'date': current_day, 'state': item.get('state', ''), 'analyst': analyst } historic_state.append(current_state) remove_treatment_manager = True if item.get('state') == 'closed': remove_treatment_manager = vuln_dal.update( finding_id, vulnerability[0].get('UUID', ''), {'treatment_manager': None}) response = vuln_dal.update_state( finding_id, str(vulnerability[0].get( 'UUID', '')), 'historic_state', historic_state, vulnerability) and remove_treatment_manager else: response = True return response
def update_treatment_vuln(vulnerabilities: List[str], finding_id: str, updated_values: Dict[str, FindingType], info) -> bool: if updated_values.get('acceptance_date'): del updated_values['acceptance_date'] del updated_values['finding_id'] user_email = util.get_jwt_content(info.context)['user_email'] updated_vuln_description = [] for vulnerability in vulnerabilities: vuln_info = cast(List[Dict[str, FindingType]], vuln_dal.get(finding_id, uuid=vulnerability)) new_info = copy.copy(updated_values) if new_info.get('tag'): new_info['tag'] = cast(List[str], vuln_info[0].get('tag', [])) for tag in str(updated_values['tag']).split(','): validations.validate_field(cast(List[str], tag)) if tag.strip(): cast(List[str], new_info['tag']).append(tag.strip()) new_info['tag'] = cast( # conflict between mypy and pylint -> 'github.com/PyCQA/pylint/issues/2377' # pylint: disable=unsubscriptable-object List[str], list(set(cast(Iterable[Collection[str]], new_info['tag'])))) new_info['tag'] = [ html.unescape(tag) for tag in cast(List[str], new_info['tag']) ] new_info = { key: None if not value else value for key, value in new_info.items() } new_info = { util.camelcase_to_snakecase(k): new_info.get(k) for k in new_info } result_update_vuln = \ vuln_dal.update(finding_id, vulnerability, new_info) if 'lines' in str(vuln_info[0]['vuln_type']): where = 'Path' specific = 'Line' elif 'ports' in str(vuln_info[0]['vuln_type']): where = 'Host' specific = 'Port' else: where = 'URL' specific = 'Field' mail_description =\ "<b>{where}:</b>{where_info} \ <b>{specific}:</b> {specific_info}"\ .format(where=where, where_info=vuln_info[0]['where'], specific_info=vuln_info[0]['specific'], specific=specific) updated_vuln_description.append( {'updated_vuln_description': mail_description}) if not result_update_vuln: util.cloudwatch_log( info.context, 'Security: Attempted to update vulnerability\ :{id} from finding:{finding}'.format(id=vulnerability, finding=finding_id)) return False util.cloudwatch_log( info.context, 'Security: Updated vulnerability:\ {id} from finding:{finding} succesfully'.format(id=vulnerability, finding=finding_id)) if updated_values.get('treatment') != 'NEW': send_updated_vuln_email(finding_id, user_email, cast(Dict[str, str], updated_values), str(updated_vuln_description)) return True