@@ -6,12 +6,7 @@ import { hasOwn } from '@socketsecurity/registry/lib/objects'
6
6
import { resolvePackageName } from '@socketsecurity/registry/lib/packages'
7
7
import { naturalCompare } from '@socketsecurity/registry/lib/sorts'
8
8
9
- import {
10
- CompactSocketArtifact ,
11
- isArtifactAlertCve ,
12
- isArtifactAlertCveFixable ,
13
- isArtifactAlertUpgrade
14
- } from './alert/artifact'
9
+ import { CompactSocketArtifact , isArtifactAlertCve } from './alert/artifact'
15
10
import { uxLookup } from './alert/rules'
16
11
import { SEVERITY } from './alert/severity'
17
12
import { ColorOrMarkdown } from './color-or-markdown'
@@ -34,7 +29,12 @@ export type SocketPackageAlert = {
34
29
35
30
export type AlertsByPkgId = Map < string , SocketPackageAlert [ ] >
36
31
37
- const { CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER , NPM } = constants
32
+ const {
33
+ ALERT_FIX_TYPE_CVE ,
34
+ ALERT_FIX_TYPE_UPGRADE ,
35
+ CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER ,
36
+ NPM
37
+ } = constants
38
38
39
39
const format = new ColorOrMarkdown ( false )
40
40
@@ -62,6 +62,7 @@ export async function addArtifactToAlertsMap(
62
62
if ( ! artifact . name || ! artifact . version || ! artifact . alerts ?. length ) {
63
63
return
64
64
}
65
+
65
66
const {
66
67
consolidate = false ,
67
68
include : _include ,
@@ -70,6 +71,7 @@ export async function addArtifactToAlertsMap(
70
71
__proto__ : null ,
71
72
...options
72
73
} as AddSocketArtifactAlertToAlertsMapOptions
74
+
73
75
const include = {
74
76
__proto__ : null ,
75
77
critical : true ,
@@ -79,6 +81,7 @@ export async function addArtifactToAlertsMap(
79
81
upgrade : false ,
80
82
..._include
81
83
} as AlertIncludeFilter
84
+
82
85
const name = resolvePackageName ( artifact )
83
86
const { version } = artifact
84
87
const pkgId = `${ name } @${ version } `
@@ -90,10 +93,11 @@ export async function addArtifactToAlertsMap(
90
93
package : { name, version } ,
91
94
alert : { type : alert . type }
92
95
} )
96
+ const fixType = alert . fix ?. type ?? ''
93
97
const critical = alert . severity === SEVERITY . critical
94
98
const cve = isArtifactAlertCve ( alert )
95
- const fixableCve = isArtifactAlertCveFixable ( alert )
96
- const fixableUpgrade = isArtifactAlertUpgrade ( alert )
99
+ const fixableCve = fixType === ALERT_FIX_TYPE_CVE
100
+ const fixableUpgrade = fixType === ALERT_FIX_TYPE_UPGRADE
97
101
const fixable = fixableCve || fixableUpgrade
98
102
const upgrade = fixableUpgrade && ! hasOwn ( overrides , name )
99
103
if (
@@ -130,11 +134,11 @@ export async function addArtifactToAlertsMap(
130
134
> ( )
131
135
const unfixableAlerts : SocketPackageAlert [ ] = [ ]
132
136
for ( const sockPkgAlert of sockPkgAlerts ) {
133
- if ( isArtifactAlertCveFixable ( sockPkgAlert . raw ) ) {
137
+ const alert = sockPkgAlert . raw
138
+ const fixType = alert . fix ?. type ?? ''
139
+ if ( fixType === ALERT_FIX_TYPE_CVE ) {
134
140
const patchedVersion =
135
- sockPkgAlert . raw . props [
136
- CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER
137
- ]
141
+ alert . props [ CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER ]
138
142
const patchedMajor = semver . major ( patchedVersion )
139
143
const oldHighest = highestForCve . get ( patchedMajor )
140
144
const highest = oldHighest ?. version ?? '0.0.0'
@@ -144,7 +148,7 @@ export async function addArtifactToAlertsMap(
144
148
version : patchedVersion
145
149
} )
146
150
}
147
- } else if ( isArtifactAlertUpgrade ( sockPkgAlert . raw ) ) {
151
+ } else if ( fixType === ALERT_FIX_TYPE_UPGRADE ) {
148
152
const oldHighest = highestForUpgrade . get ( major )
149
153
const highest = oldHighest ?. version ?? '0.0.0'
150
154
if ( semver . gt ( version , highest ) ) {
@@ -192,12 +196,13 @@ export function getCveInfoByAlertsMap(
192
196
...( { __proto__ : null , ...options } as GetCveInfoByPackageOptions ) . exclude
193
197
}
194
198
let infoByPkg : CveInfoByPkgId | null = null
195
- for ( const [ pkgId , alerts ] of alertsMap ) {
199
+ for ( const [ pkgId , sockPkgAlerts ] of alertsMap ) {
196
200
const purlObj = PackageURL . fromString ( `pkg:npm/${ pkgId } ` )
197
201
const name = resolvePackageName ( purlObj )
198
- for ( const alert of alerts ) {
202
+ for ( const sockPkgAlert of sockPkgAlerts ) {
203
+ const alert = sockPkgAlert . raw
199
204
if (
200
- ! isArtifactAlertCveFixable ( alert . raw ) ||
205
+ alert . fix ?. type !== ALERT_FIX_TYPE_CVE ||
201
206
( exclude . upgrade && getManifestData ( NPM , name ) )
202
207
) {
203
208
continue
@@ -211,7 +216,7 @@ export function getCveInfoByAlertsMap(
211
216
infoByPkg . set ( name , infos )
212
217
}
213
218
const { firstPatchedVersionIdentifier, vulnerableVersionRange } =
214
- alert . raw . props
219
+ alert . props
215
220
infos . push ( {
216
221
firstPatchedVersionIdentifier,
217
222
vulnerableVersionRange : new semver . Range (
0 commit comments