Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit cfecb14

Browse files
fix: CVE-2022-33987 vulnerability with got (#1397)
* update latest-version * add got resolution and revert latest-version update * update got to a compatible version * remove use of latest-version * remove got resolution * apply types --------- Co-authored-by: tracyboehrer <[email protected]>
1 parent e6fc31b commit cfecb14

File tree

4 files changed

+31
-53
lines changed

4 files changed

+31
-53
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 0 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/chatdown/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"fs-extra": "^5.0.0",
1616
"glob": "^7.1.3",
1717
"intercept-stdout": "^0.1.2",
18-
"latest-version": "5.1.0",
1918
"mime-types": "^2.1.18",
2019
"minimist": "^1.2.6",
2120
"axios": "~1.7.5",
@@ -30,7 +29,7 @@
3029
"@oclif/plugin-help": "^6.2.10",
3130
"@oclif/test": "^1.2.5",
3231
"@oclif/tslint": "^3.1.1",
33-
"@types/chai": "^4.1.7",
32+
"@types/chai": "^4.2.10",
3433
"@types/fs-extra": "^5.0.5",
3534
"@types/mocha": "^10.0.6",
3635
"@types/node": "^11.3.7",

packages/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"cli-ux": "^5.3.0",
8585
"fs-extra": "^7.0.1",
8686
"is-ci": "2.0.0",
87-
"latest-version": "5.1.0",
8887
"semver": "^7.6.3",
8988
"tslib": "^2.0.3"
9089
},

packages/cli/src/hooks/init/inithook.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import cli from 'cli-ux'
88
import * as fs from 'fs-extra'
99
const chalk = require('chalk')
1010
const path = require('path')
11-
const latestVersion = require('latest-version')
11+
const {exec} = require('child_process')
1212
const semver = require('semver')
1313
const isCI = require('is-ci')
1414

@@ -35,12 +35,30 @@ const hook: Hook<'init'> = async function (opts) {
3535
}
3636
}
3737

38+
const execPromise = (command: string) => {
39+
return new Promise<string>((resolve, reject) => {
40+
exec(command, (error: any, stdout: any, stderr: any) => {
41+
if (error) {
42+
reject(error)
43+
} else if (stderr) {
44+
reject(new Error(stderr))
45+
} else {
46+
resolve(stdout.trim())
47+
}
48+
})
49+
})
50+
}
51+
3852
const checkForUpdate = async () => {
39-
const latest = await latestVersion(opts.config.name, {version: `>${opts.config.version}`})
40-
if (semver.gt(latest, opts.config.version)) {
41-
this.log('Update available ')
42-
this.log(' Run ')
43-
this.log(`npm i -g ${opts.config.name} `)
53+
try {
54+
const latest = await execPromise(`npm view ${opts.config.name} version`)
55+
if (semver.gt(latest, opts.config.version)) {
56+
this.log('Update available')
57+
this.log(' Run ')
58+
this.log(`npm i -g ${opts.config.name}`)
59+
}
60+
} catch (error) {
61+
this.log('Error checking for update:', error.message)
4462
}
4563
}
4664

@@ -59,16 +77,16 @@ const hook: Hook<'init'> = async function (opts) {
5977
// if there is a timestamp in config and it's not from today, check for updates
6078
const lastCheck = userConfig.lastVersionCheck ? new Date(userConfig.lastVersionCheck) : null
6179
if ((opts.id === '-v'
62-
|| opts.id === '--version')
63-
&& !isToday(lastCheck, curDateTime)) {
80+
|| opts.id === '--version')
81+
&& !isToday(lastCheck, curDateTime)) {
6482
await checkForUpdate()
6583
await updateUserConfig(curDateTime)
6684
}
6785

68-
/* tslint:disable:no-unused */
86+
/* tslint:disable:no-unused */
6987
} catch (err) {
70-
// swallow the exception; we don't want to crash the app
71-
// on a failed attempt to check version
88+
// swallow the exception; we don't want to crash the app
89+
// on a failed attempt to check version
7290
}
7391

7492
// Ensure telemetry is set
@@ -95,7 +113,7 @@ const hook: Hook<'init'> = async function (opts) {
95113
}
96114

97115
this.config.pjson.telemetry = userConfig.telemetry === null ? false : userConfig.telemetry
98-
/* tslint:disable:no-unused */
116+
/* tslint:disable:no-unused */
99117

100118
} catch (err) {
101119
this.config.pjson.telemetry = false

0 commit comments

Comments
 (0)