Skip to content

Commit

Permalink
refactor: only collect Node version if it's a standard version string
Browse files Browse the repository at this point in the history
Any other kinds of Node version are collected as "other" to avoid pulling in an unbounded user input.

(cherry picked from commit b5dcb29)
  • Loading branch information
dgp1130 committed Jan 18, 2023
1 parent bf4639a commit bc5555c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/angular/cli/src/analytics/analytics-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { randomUUID } from 'crypto';
import * as https from 'https';
import * as os from 'os';
import * as querystring from 'querystring';
import * as semver from 'semver';
import type { CommandContext } from '../command-builder/command-module';
import { ngDebug } from '../utilities/environment-options';
import { assertIsError } from '../utilities/error';
Expand Down Expand Up @@ -52,8 +53,7 @@ export class AnalyticsCollector {

this.requestParameterStringified = querystring.stringify(requestParameters);

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

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

0 comments on commit bc5555c

Please sign in to comment.