Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telemetry] Expand field sanitization to codedError.data #14161

Merged
merged 9 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Expand sanitization checks for error telemetry instances",
"packageName": "@react-native-windows/telemetry",
"email": "14967941+danielayala94@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ function verifyTestCommandTelemetryProcessor(
: 'Unknown',
);

// NOTE: At this point, expectedError has been modified by trackException().
expect(codedError.data).toStrictEqual(
(expectedError as errorUtils.CodedError).data ?? {},
);
Expand Down Expand Up @@ -694,3 +695,37 @@ test.each(testTelemetryOptions)(
});
},
);

test.each(testTelemetryOptions)(
'Telemetry run test command end to end with CodedError, verifies PII is scrubbed if present in CodedError.',
async options => {
await TelemetryTest.startTest(options);

const expectedError = new errorUtils.CodedError(
'MSBuildError', // type
'test error', // message
{
fieldWithPath:
'Test Error occurred at C:\\some\\file\\path\\project.build.appxrecipe', // expectation: replace the whole C:\\... thing with "[path]".
fieldWithNoPath: 'Test Error data', // expectation: no changes to this string.
fieldWithNoString: 14, // expectation: no changes to this value.
}, // data
);

const caughtErrors: Error[] = [];
TelemetryTest.addTelemetryInitializer(
verifyTestCommandTelemetryProcessor(
caughtErrors,
expectedError.type,
expectedError,
),
);

await runTestCommandE2E(() => testCommandBody(expectedError));

TelemetryTest.endTest(() => {
// Check if any errors were thrown
expect(caughtErrors).toHaveLength(0);
});
},
);
15 changes: 15 additions & 0 deletions packages/@react-native-windows/telemetry/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,21 @@ export class Telemetry {
data: codedError?.data ?? {},
};

// Scrub any potential PII present in codedError.data array, as long as the data is a string.
if (Object.keys(codedErrorStruct.data).length > 0) {
danielayala94 marked this conversation as resolved.
Show resolved Hide resolved
for (const field in codedErrorStruct.data) {
if (
codedErrorStruct.data.hasOwnProperty(field) &&
typeof codedErrorStruct.data[field] === 'string'
) {
const sanitizedError = errorUtils.sanitizeErrorMessage(
codedErrorStruct.data[field],
);
codedErrorStruct.data[field] = sanitizedError;
}
}
}

// Copy msBuildErrorMessages into the codedError.data object
if ((error as any).msBuildErrorMessages) {
// Always grab MSBuild error codes if possible
Expand Down