From 298a5418f0f8c0d4a40c1b50b3a844bf529207b3 Mon Sep 17 00:00:00 2001 From: Jan Polonsky Date: Tue, 23 Jan 2024 10:22:58 +0100 Subject: [PATCH] Allow store CVSS as number (quick need for reporting) Same as #163 CVSS might be inserted as a number (small improvements, fixed default value, 1 decimal point, some code enhacements) --- .../common/attribute/AttributeCVSS.vue | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/gui/src/components/common/attribute/AttributeCVSS.vue b/src/gui/src/components/common/attribute/AttributeCVSS.vue index d989fb46c..e095f0e52 100644 --- a/src/gui/src/components/common/attribute/AttributeCVSS.vue +++ b/src/gui/src/components/common/attribute/AttributeCVSS.vue @@ -117,7 +117,7 @@ status: "", rules: { vector: value => { - const pattern = /^CVSS:3\.1\/((AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])\/)*(AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])$/ + const pattern = /(^CVSS:3\.1\/((AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])\/)*(AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]|E:[XUPFH]|RL:[XOTWU]|RC:[XURC]|[CIA]R:[XLMH]|MAV:[XNALP]|MAC:[XLH]|MPR:[XUNLH]|MUI:[XNR]|MS:[XUC]|M[CIA]:[XNLH])$)|(^(10(\.0)?|[0-9](\.[0-9])?)$)/ return value == '' || pattern.test(value) || 'Invalid or Incomplete Vector String' } } @@ -136,29 +136,40 @@ methods: { updateValue(e) { this.calcValue = e; - this.score = this.clc.calculateCVSSFromVector(this.calcValue); - setTimeout(()=>{ + const value = parseFloat(e); + if (value >= 0 && value <= 10) { + // OK + } else { + this.score = this.clc.calculateCVSSFromVector(this.calcValue); + } + setTimeout(() => { this.values[0].value = e; this.onEdit(0); - },200); + }, 200); }, report(e) { this.status = e; }, directValueChange() { - let vsReport = this.clc.calculateCVSSFromVector(this.calcValue); - - if(vsReport.success) { - this.score = vsReport; - + const value = parseFloat(this.calcValue); + if (value >= 0 && value <= 10) { this.values[0].value = this.calcValue; this.onKeyUp(0); + } else { + let vsReport = this.clc.calculateCVSSFromVector(this.calcValue); + if (vsReport.success) { + this.score = vsReport; + this.values[0].value = this.calcValue; + this.onKeyUp(0); + } } } - }, - mounted(){ - if( this.values[0].value !== "" ) { + mounted() { + const value = parseFloat(this.values[0].value); + if (value >= 0 && value <= 10) { + this.calcValue = this.values[0].value; + } else if (this.values[0].value !== "") { this.calcValue = this.values[0].value; this.score = this.clc.calculateCVSSFromVector(this.calcValue); } else {