@@ -7,6 +7,7 @@ const path = require('path')
77const debug = require ( 'debug' ) ( 'is-my-node-vulnerable' )
88const satisfies = require ( 'semver/functions/satisfies' )
99const { danger, vulnerableWarning, bold, separator, allGood } = require ( './ascii' )
10+ const nv = require ( '@pkgjs/nv' )
1011
1112setGlobalDispatcher ( new Agent ( { connections : 20 } ) )
1213
@@ -73,6 +74,13 @@ function getVulnerabilityList (currentVersion, data) {
7374}
7475
7576async function main ( currentVersion ) {
77+ const isEOL = await isNodeEOL ( currentVersion )
78+ if ( isEOL ) {
79+ console . error ( danger )
80+ console . error ( `${ currentVersion } is end-of-life. There are high chances of being vulnerable. Please upgrade it.` )
81+ process . exit ( 1 )
82+ }
83+
7684 const coreIndex = await getCoreIndex ( )
7785 const list = getVulnerabilityList ( currentVersion , coreIndex )
7886 if ( list . length ) {
@@ -85,7 +93,34 @@ async function main (currentVersion) {
8593 }
8694}
8795
96+ /**
97+ * @param {string } version
98+ * @returns {Promise<boolean> } true if the version is end-of-life
99+ */
100+ async function isNodeEOL ( version ) {
101+ const myVersionInfo = await nv ( version )
102+ if ( ! myVersionInfo ) {
103+ // i.e. isNodeEOL('abcd')
104+ throw Error ( `Could not fetch version information for ${ version } ` )
105+ } else if ( myVersionInfo . length !== 1 ) {
106+ // i.e. isNodeEOL('lts') or isNodeEOL('99')
107+ throw Error ( `Did not get exactly one version record for ${ version } ` )
108+ } else if ( ! myVersionInfo [ 0 ] . end ) {
109+ // We got a record, but..
110+ // v0.12.18 etc does not have an EOL date, which probably means too old.
111+ return true
112+ }
113+ const now = new Date ( )
114+ const end = new Date ( myVersionInfo [ 0 ] . end )
115+ return now > end
116+ }
117+
88118async function isNodeVulnerable ( version ) {
119+ const isEOL = await isNodeEOL ( version )
120+ if ( isEOL ) {
121+ return true
122+ }
123+
89124 const coreIndex = await getCoreIndex ( )
90125 const list = getVulnerabilityList ( version , coreIndex )
91126 return list . length > 0
0 commit comments