Skip to content

Commit b5dcb29

Browse files
dgp1130angular-robot[bot]
authored andcommitted
refactor: only collect Node version if it's a standard version string
Any other kinds of Node version are collected as "other" to avoid pulling in an unbounded user input.
1 parent c3adf11 commit b5dcb29

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/angular/cli/src/analytics/analytics-collector.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { randomUUID } from 'crypto';
1010
import * as https from 'https';
1111
import * as os from 'os';
1212
import * as querystring from 'querystring';
13+
import * as semver from 'semver';
1314
import type { CommandContext } from '../command-builder/command-module';
1415
import { ngDebug } from '../utilities/environment-options';
1516
import { assertIsError } from '../utilities/error';
@@ -52,8 +53,7 @@ export class AnalyticsCollector {
5253

5354
this.requestParameterStringified = querystring.stringify(requestParameters);
5455

55-
// Remove the `v` at the beginning.
56-
const nodeVersion = process.version.substring(1);
56+
const parsedVersion = semver.parse(process.version);
5757
const packageManagerVersion = context.packageManager.version;
5858

5959
this.userParameters = {
@@ -62,8 +62,10 @@ export class AnalyticsCollector {
6262
[UserCustomDimension.OsArchitecture]: os.arch(),
6363
// While User ID is being collected by GA, this is not visible in reports/for filtering.
6464
[UserCustomDimension.UserId]: userId,
65-
[UserCustomDimension.NodeVersion]: nodeVersion,
66-
[UserCustomDimension.NodeMajorVersion]: +nodeVersion.split('.', 1)[0],
65+
[UserCustomDimension.NodeVersion]: parsedVersion
66+
? `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}`
67+
: 'other',
68+
[UserCustomDimension.NodeMajorVersion]: parsedVersion?.major,
6769
[UserCustomDimension.PackageManager]: context.packageManager.name,
6870
[UserCustomDimension.PackageManagerVersion]: packageManagerVersion,
6971
[UserCustomDimension.PackageManagerMajorVersion]: packageManagerVersion

0 commit comments

Comments
 (0)