@@ -51,6 +51,7 @@ const { request, stream, setGlobalDispatcher, Agent } = __nccwpck_require__(1773
51
51
const EE = __nccwpck_require__(2361)
52
52
const fs = __nccwpck_require__(7147)
53
53
const path = __nccwpck_require__(1017)
54
+ const os = __nccwpck_require__(2037)
54
55
const debug = __nccwpck_require__(8237)('is-my-node-vulnerable')
55
56
const satisfies = __nccwpck_require__(6055)
56
57
const { danger, vulnerableWarning, bold, separator, allGood } = __nccwpck_require__(9139)
@@ -106,21 +107,38 @@ async function getCoreIndex () {
106
107
}
107
108
}
108
109
109
- function getVulnerabilityList (currentVersion, data) {
110
+ function getVulnerabilityList (currentVersion, data, systemEnvironment ) {
110
111
const list = []
111
112
for (const key in data) {
112
113
const vuln = data[key]
113
114
if (
114
- satisfies(currentVersion, vuln.vulnerable) &&
115
- !satisfies(currentVersion, vuln.patched)
115
+ (
116
+ satisfies(currentVersion, vuln.vulnerable) &&
117
+ !satisfies(currentVersion, vuln.patched)
118
+ ) && (
119
+ (!systemEnvironment || !Array.isArray(vuln.affectedEnvironments)) ||
120
+ vuln.affectedEnvironments.includes(systemEnvironment)
121
+ )
116
122
) {
117
123
list.push(`${bold(vuln.cve)}: ${vuln.overview}\n${bold('Patched versions')}: ${vuln.patched}`)
118
124
}
119
125
}
120
126
return list
121
127
}
122
128
123
- async function main (currentVersion) {
129
+ const getSystemEnvironment = (platform) => {
130
+ switch (platform) {
131
+ case 'darwin':
132
+ return 'osx'
133
+ case 'win32':
134
+ return 'win'
135
+ default:
136
+ return 'linux'
137
+ }
138
+ }
139
+
140
+ async function main (currentVersion, platform) {
141
+ const systemEnvironment = getSystemEnvironment(platform)
124
142
const isEOL = await isNodeEOL(currentVersion)
125
143
if (isEOL) {
126
144
console.error(danger)
@@ -129,7 +147,7 @@ async function main (currentVersion) {
129
147
}
130
148
131
149
const coreIndex = await getCoreIndex()
132
- const list = getVulnerabilityList(currentVersion, coreIndex)
150
+ const list = getVulnerabilityList(currentVersion, coreIndex, systemEnvironment )
133
151
if (list.length) {
134
152
console.error(danger)
135
153
console.error(vulnerableWarning + '\n')
@@ -162,14 +180,14 @@ async function isNodeEOL (version) {
162
180
return now > end
163
181
}
164
182
165
- async function isNodeVulnerable (version) {
183
+ async function isNodeVulnerable (version, systemEnvironment ) {
166
184
const isEOL = await isNodeEOL(version)
167
185
if (isEOL) {
168
186
return true
169
187
}
170
188
171
189
const coreIndex = await getCoreIndex()
172
- const list = getVulnerabilityList(version, coreIndex)
190
+ const list = getVulnerabilityList(version, coreIndex, systemEnvironment )
173
191
return list.length > 0
174
192
}
175
193
@@ -41519,8 +41537,14 @@ const { isNodeVulnerable } = __nccwpck_require__(2932)
41519
41537
async function run () {
41520
41538
// Inputs
41521
41539
const nodeVersion = core.getInput('node-version', { required: true })
41522
- core.info(`Checking Node.js version ${nodeVersion}...`)
41523
- const isVulnerable = await isNodeVulnerable(nodeVersion)
41540
+ const platform = core.getInput('platform', { required: false })
41541
+
41542
+ if (platform && !['linux', 'win', 'osx'].includes(platform)) {
41543
+ core.setFailed(`platform ${platform} is not valid. Please use linux, win or osx.`)
41544
+ }
41545
+
41546
+ core.info(`Checking Node.js version ${nodeVersion} with platform ${platform}...`)
41547
+ const isVulnerable = await isNodeVulnerable(nodeVersion, platform)
41524
41548
if (isVulnerable) {
41525
41549
core.setFailed(`Node.js version ${nodeVersion} is vulnerable. Please upgrade!`)
41526
41550
} else {
0 commit comments