Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
19 changes: 15 additions & 4 deletions packages/cli-kit/src/public/node/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,21 @@ describe('event tracking', () => {
})
})

test('does not send passwords to Monorail', async () => {
test('does not send any shopify tokens to Monorail', async () => {
await inProjectWithFile('package.json', async (args) => {
// Given
const commandContent = {command: 'dev', topic: 'app'}
const argsWithPassword = args.concat(['--password', 'shptka_abc123'])
await startAnalytics({commandContent, args: argsWithPassword, currentTime: currentDate.getTime() - 100})
const argsWithTokens = args.concat([
'--password',
'shptka_abc123',
'--token',
'shpat_abc123',
'--user-token',
'shpua_abc123',
'--custom-token',
'shpca_abc123',
])
await startAnalytics({commandContent, args: argsWithTokens, currentTime: currentDate.getTime() - 100})

// When
const config = {
Expand All @@ -180,7 +189,9 @@ describe('event tracking', () => {

// Then
const expectedPayloadSensitive = {
args: expect.stringMatching(/.*password \*\*\*\*\*/),
args: expect.stringMatching(
/.*password \*\*\*\*\*.*token \*\*\*\*\*.*user-token \*\*\*\*\*.*custom-token \*\*\*\*\*/,
Comment thread
gonzaloriestra marked this conversation as resolved.
),
metadata: expect.anything(),
}
expect(publishEventMock).toHaveBeenCalledOnce()
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-kit/src/public/node/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ async function buildPayload({config, errorMessage, exitMode}: ReportAnalyticsEve

function sanitizePayload<T>(payload: T): T {
const payloadString = JSON.stringify(payload)
// Remove Theme Access passwords from the payload
const sanitizedPayloadString = payloadString.replace(/shptka_\w*/g, '*****')
// Remove Shopify tokens from the payload
const sanitizedPayloadString = payloadString.replace(/shp[a-z0-9]{1,6}_\w*/g, '*****')
return JSON.parse(sanitizedPayloadString)
}

Expand Down
Loading