Skip to content

Commit 385d733

Browse files
RafaelGSStrivikr
andauthored
feat: add support to old versions of Node.js (#23)
* feat: add compatibility to Node.js >= 0.12 For retro-compatibility lovers * doc: add note about supported Node.js versions * fixup! feat: add compatibility to Node.js >= 0.12 * chore: drop cli-colors Refs: #19 * fixup! extra forward slashes Co-authored-by: Trivikram Kamat <[email protected]> * fixup! feat: add compatibility to Node.js >= 0.12 --------- Co-authored-by: Trivikram Kamat <[email protected]>
1 parent 050a05a commit 385d733

File tree

9 files changed

+388
-330
lines changed

9 files changed

+388
-330
lines changed

.github/workflows/test.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [14, 16, 18, 20, 21, 22]
14+
node-version: [16, 18, 20, 21, 22, 23]
1515

1616
steps:
1717
- uses: actions/checkout@v3
@@ -32,3 +32,21 @@ jobs:
3232
- name: Ensure Build
3333
run: |
3434
npm run build
35+
36+
old-versions:
37+
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
node-version: [0.12, 4, 6, 8, 9, 10, 12]
41+
42+
steps:
43+
- uses: actions/checkout@v3
44+
45+
- name: Use Node.js
46+
uses: actions/setup-node@v3
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
50+
- name: Run test
51+
run: |
52+
node setup-test.js

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ npx is-my-node-vulnerable
1212

1313
It's strongly recommended to include this as a step in the app CI.
1414

15+
> [!NOTE]
16+
> For retro-compatibility enthusiasts: This module supports Node.js versions >= v0.12.
17+
> However, npx does not work with those older versions, so you'll need to install the
18+
> package and run index.js manually. If you encounter errors when using npx, it's
19+
> likely because you're using a vulnerable version of Node.js. Please consider upgrading.
20+
1521
### Output - When vulnerable
1622

1723

@@ -73,6 +79,9 @@ End-of-Life versions don't keep track of recent security releases, therefore, it
7379

7480
This package also exports a function `isNodeVulnerable` to perform the check in runtime
7581

82+
> [!NOTE]
83+
> The API is only supported on active Node.js versions (v18.x, v20.x, v22.x, v23.x)
84+
7685
```js
7786
const { isNodeVulnerable } = require('is-my-node-vulnerable')
7887

ascii.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
1-
const clc = require('cli-color')
1+
const util = require('util')
22

3-
const danger = `
4-
5-
██████ █████ ███ ██ ██████ ███████ ██████
6-
██ ██ ██ ██ ████ ██ ██ ██ ██ ██
7-
██ ██ ███████ ██ ██ ██ ██ ███ █████ ██████
8-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
9-
██████ ██ ██ ██ ████ ██████ ███████ ██ ██
10-
11-
`
3+
const danger = '\n' +
4+
'\n' +
5+
'██████ █████ ███ ██ ██████ ███████ ███████\n' +
6+
'██ ██ ██ ██ ████ ██ ██ ██ ██ ██\n' +
7+
'██ ██ ███████ ██ ██ ██ ██ ███ █████ ███████\n' +
8+
'██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n' +
9+
'██████ ██ ██ ██ ████ ██████ ███████ ██ ██\n' +
10+
'\n'
1211

13-
const allGood = `
14-
15-
█████ ██ ██ ██████ ██████ ██████ ██████ ██
16-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
17-
███████ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██
18-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
19-
██ ██ ███████ ███████ ██████ ██████ ██████ ██████ ██
20-
21-
`
12+
const allGood = '\n' +
13+
'\n' +
14+
' █████ ██ ██ ██████ ██████ ██████ ██████ ██\n' +
15+
'██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n' +
16+
'███████ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██\n' +
17+
'██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n' +
18+
'██ ██ ███████ ███████ ██████ ██████ ██████ ██████ ██\n' +
19+
'\n'
2220

23-
const bold = clc.bold
21+
function escapeStyleCode (code) {
22+
return '\u001b[' + code + 'm'
23+
}
2424

25-
const vulnerableWarning = bold(`The current Node.js version (${process.version}) is vulnerable to the following CVEs:`)
25+
function bold (text) {
26+
var left = ''
27+
var right = ''
28+
const formatCodes = util.inspect.colors.bold
29+
left += escapeStyleCode(formatCodes[0])
30+
right = escapeStyleCode(formatCodes[1]) + right
31+
return left + text + right
32+
}
2633

27-
const separator = '='.repeat(process.stdout.columns)
34+
const vulnerableWarning = bold('The current Node.js version (' + process.version + ') is vulnerable to the following CVEs:')
2835

29-
module.exports = {
30-
danger,
31-
allGood,
32-
bold,
33-
vulnerableWarning,
34-
separator
36+
var separator = '='
37+
for (var i = 0; i < process.stdout.columns; ++i) {
38+
separator = separator + '='
3539
}
40+
41+
module.exports.danger = danger
42+
module.exports.allGood = allGood
43+
module.exports.bold = bold
44+
module.exports.vulnerableWarning = vulnerableWarning
45+
module.exports.separator = separator

eol-versions.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Sync from https://raw.githubusercontent.com/nodejs/Release/master/schedule.json
2+
// These are the list of versions that might be affected by this module dependencies
3+
const versionMap = {
4+
// v0.12
5+
v0: {
6+
start: '2015-02-06',
7+
end: '2016-12-31'
8+
},
9+
v4: {
10+
start: '2015-09-08',
11+
lts: '2015-10-12',
12+
maintenance: '2017-04-01',
13+
end: '2018-04-30',
14+
codename: 'Argon'
15+
},
16+
v5: {
17+
start: '2015-10-29',
18+
maintenance: '2016-04-30',
19+
end: '2016-06-30'
20+
},
21+
v6: {
22+
start: '2016-04-26',
23+
lts: '2016-10-18',
24+
maintenance: '2018-04-30',
25+
end: '2019-04-30',
26+
codename: 'Boron'
27+
},
28+
v7: {
29+
start: '2016-10-25',
30+
maintenance: '2017-04-30',
31+
end: '2017-06-30'
32+
},
33+
v8: {
34+
start: '2017-05-30',
35+
lts: '2017-10-31',
36+
maintenance: '2019-01-01',
37+
end: '2019-12-31',
38+
codename: 'Carbon'
39+
},
40+
v9: {
41+
start: '2017-10-01',
42+
maintenance: '2018-04-01',
43+
end: '2018-06-30'
44+
},
45+
v10: {
46+
start: '2018-04-24',
47+
lts: '2018-10-30',
48+
maintenance: '2020-05-19',
49+
end: '2021-04-30',
50+
codename: 'Dubnium'
51+
},
52+
v11: {
53+
start: '2018-10-23',
54+
maintenance: '2019-04-22',
55+
end: '2019-06-01'
56+
},
57+
v12: {
58+
start: '2019-04-23',
59+
lts: '2019-10-21',
60+
maintenance: '2020-11-30',
61+
end: '2022-04-30',
62+
codename: 'Erbium'
63+
},
64+
v13: {
65+
start: '2019-10-22',
66+
maintenance: '2020-04-01',
67+
end: '2020-06-01'
68+
},
69+
v14: {
70+
start: '2020-04-21',
71+
lts: '2020-10-27',
72+
maintenance: '2021-10-19',
73+
end: '2023-04-30',
74+
codename: 'Fermium'
75+
},
76+
v15: {
77+
start: '2020-10-20',
78+
maintenance: '2021-04-01',
79+
end: '2021-06-01'
80+
},
81+
v16: {
82+
start: '2021-04-20',
83+
lts: '2021-10-26',
84+
maintenance: '2022-10-18',
85+
end: '2023-09-11',
86+
codename: 'Gallium'
87+
},
88+
v17: {
89+
start: '2021-10-19',
90+
maintenance: '2022-04-01',
91+
end: '2022-06-01'
92+
},
93+
v19: {
94+
start: '2022-10-18',
95+
maintenance: '2023-04-01',
96+
end: '2023-06-01'
97+
}
98+
}
99+
100+
function isOldEnough (version) {
101+
const versionInfo = getVersionInfo(version)
102+
103+
if (!versionInfo) {
104+
return false
105+
} else if (!versionInfo.end) {
106+
return true // Versions without an EOL date are considered EOL
107+
}
108+
109+
const now = new Date()
110+
const end = new Date(versionInfo.end)
111+
return now > end
112+
}
113+
114+
function getVersionInfo (version) {
115+
const majorVersion = extractMajorVersion(version)
116+
return versionMap[majorVersion] || null
117+
}
118+
119+
function extractMajorVersion (version) {
120+
// Extracts the major version number from a version string like 'v12.22.12'
121+
const major = version.split('.')[0]
122+
return major
123+
}
124+
125+
module.exports = isOldEnough

0 commit comments

Comments
 (0)