1
- const util = require ( "./util" ) ;
1
+ import { util } from "./util" ;
2
2
3
3
/**
4
4
* Parses the vector to a number score
@@ -40,11 +40,7 @@ function getTemporalScore(vector) {
40
40
const rcMetric = util . findMetricValue ( "RC" , vectorObject ) ;
41
41
const reportConfidence = rcMetric ? rcMetric . numerical : 1 ;
42
42
43
- return roundUp (
44
- baseScore * exploitCodeMaturity * remediationLevel * reportConfidence ,
45
- 1 ,
46
- vector
47
- ) ;
43
+ return roundUp ( baseScore * exploitCodeMaturity * remediationLevel * reportConfidence , 1 , vector ) ;
48
44
}
49
45
50
46
const calculateISCBase = function ( vectorObject ) {
@@ -62,18 +58,10 @@ const calculateISCBase = function (vectorObject) {
62
58
*/
63
59
function getEnvironmentalScore ( vector ) {
64
60
const vectorObject = util . getVectorObject ( vector ) ;
65
- const scopeChanged =
66
- vectorObject . MS === "X" ? vectorObject . S === "C" : vectorObject . MS === "C" ;
61
+ const scopeChanged = vectorObject . MS === "X" ? vectorObject . S === "C" : vectorObject . MS === "C" ;
67
62
const modifiedISCBase = calculateISCModifiedBase ( vectorObject ) ;
68
- const modifiedExploitability = calculateModifiedExploitability (
69
- vectorObject ,
70
- scopeChanged
71
- ) ;
72
- const modifiedISC = calculateModifiedISC (
73
- modifiedISCBase ,
74
- scopeChanged ,
75
- vector
76
- ) ;
63
+ const modifiedExploitability = calculateModifiedExploitability ( vectorObject , scopeChanged ) ;
64
+ const modifiedISC = calculateModifiedISC ( modifiedISCBase , scopeChanged , vector ) ;
77
65
78
66
if ( modifiedISC <= 0 ) return 0 ;
79
67
@@ -95,11 +83,7 @@ function getEnvironmentalScore(vector) {
95
83
) ;
96
84
}
97
85
return roundUp (
98
- roundUp (
99
- Math . min ( 1.08 * ( modifiedISC + modifiedExploitability ) , 10 ) ,
100
- 1 ,
101
- vector
102
- ) *
86
+ roundUp ( Math . min ( 1.08 * ( modifiedISC + modifiedExploitability ) , 10 ) , 1 , vector ) *
103
87
eValue *
104
88
rlValue *
105
89
rcValue ,
@@ -122,9 +106,7 @@ const calculateModifiedISC = function (iscBase, scopeChanged, vector) {
122
106
if ( util . getVersion ( vector ) === "3.0" ) {
123
107
return 7.52 * ( iscBase - 0.029 ) - 3.25 * Math . pow ( iscBase - 0.02 , 15 ) ;
124
108
} else if ( util . getVersion ( vector ) === "3.1" ) {
125
- return (
126
- 7.52 * ( iscBase - 0.029 ) - 3.25 * Math . pow ( iscBase * 0.9731 - 0.02 , 13 )
127
- ) ;
109
+ return 7.52 * ( iscBase - 0.029 ) - 3.25 * Math . pow ( iscBase * 0.9731 - 0.02 , 13 ) ;
128
110
}
129
111
} ;
130
112
@@ -147,12 +129,9 @@ function calculateISCModifiedBase(vectorObject) {
147
129
const irValue = util . findMetricValue ( "IR" , vectorObject ) . numerical ;
148
130
const arValue = util . findMetricValue ( "AR" , vectorObject ) . numerical ;
149
131
150
- if ( ! mcValue || mcValue . abbr === "X" )
151
- mcValue = util . findMetricValue ( "C" , vectorObject ) ;
152
- if ( ! miValue || miValue . abbr === "X" )
153
- miValue = util . findMetricValue ( "I" , vectorObject ) ;
154
- if ( ! maValue || maValue . abbr === "X" )
155
- maValue = util . findMetricValue ( "A" , vectorObject ) ;
132
+ if ( ! mcValue || mcValue . abbr === "X" ) mcValue = util . findMetricValue ( "C" , vectorObject ) ;
133
+ if ( ! miValue || miValue . abbr === "X" ) miValue = util . findMetricValue ( "I" , vectorObject ) ;
134
+ if ( ! maValue || maValue . abbr === "X" ) maValue = util . findMetricValue ( "A" , vectorObject ) ;
156
135
157
136
return Math . min (
158
137
1 -
@@ -169,26 +148,14 @@ const calculateModifiedExploitability = function (vectorObject, scopeChanged) {
169
148
let mprMetrics = util . findMetricValue ( "MPR" , vectorObject ) ;
170
149
let muiValue = util . findMetricValue ( "MUI" , vectorObject ) ;
171
150
172
- if ( ! mavValue || mavValue . abbr === "X" )
173
- mavValue = util . findMetricValue ( "AV" , vectorObject ) ;
174
- if ( ! macValue || macValue . abbr === "X" )
175
- macValue = util . findMetricValue ( "AC" , vectorObject ) ;
176
- if ( ! mprMetrics || mprMetrics . abbr === "X" )
177
- mprMetrics = util . findMetricValue ( "PR" , vectorObject ) ;
178
- if ( ! muiValue || muiValue . abbr === "X" )
179
- muiValue = util . findMetricValue ( "UI" , vectorObject ) ;
180
-
181
- const mprValue = scopeChanged
182
- ? mprMetrics . numerical . changed
183
- : mprMetrics . numerical . unchanged ;
184
-
185
- return (
186
- 8.22 *
187
- mavValue . numerical *
188
- macValue . numerical *
189
- mprValue *
190
- muiValue . numerical
191
- ) ;
151
+ if ( ! mavValue || mavValue . abbr === "X" ) mavValue = util . findMetricValue ( "AV" , vectorObject ) ;
152
+ if ( ! macValue || macValue . abbr === "X" ) macValue = util . findMetricValue ( "AC" , vectorObject ) ;
153
+ if ( ! mprMetrics || mprMetrics . abbr === "X" ) mprMetrics = util . findMetricValue ( "PR" , vectorObject ) ;
154
+ if ( ! muiValue || muiValue . abbr === "X" ) muiValue = util . findMetricValue ( "UI" , vectorObject ) ;
155
+
156
+ const mprValue = scopeChanged ? mprMetrics . numerical . changed : mprMetrics . numerical . unchanged ;
157
+
158
+ return 8.22 * mavValue . numerical * macValue . numerical * mprValue * muiValue . numerical ;
192
159
} ;
193
160
194
161
/**
@@ -243,10 +210,10 @@ function getExploitabilitySubScore(vector) {
243
210
return Number ( calculateExploitability ( vectorObject , S === "C" ) . toFixed ( 1 ) ) ;
244
211
}
245
212
246
- module . exports = {
213
+ export const score = {
247
214
getScore,
248
215
getTemporalScore,
249
216
getEnvironmentalScore,
250
217
getImpactSubScore,
251
- getExploitabilitySubScore,
218
+ getExploitabilitySubScore
252
219
} ;
0 commit comments