diff --git a/packages/cli-kit/src/public/node/monorail.test.ts b/packages/cli-kit/src/public/node/monorail.test.ts index 39f246933e..fcb8e5751a 100644 --- a/packages/cli-kit/src/public/node/monorail.test.ts +++ b/packages/cli-kit/src/public/node/monorail.test.ts @@ -40,4 +40,12 @@ describe('monorail', () => { headers: expectedHeaders, }) }) + + test('sanitizes the api_key from the debug log', async () => { + const outputMock = mockAndCaptureOutput() + const res = await publishMonorailEvent('fake_schema/0.0', {api_key: 'some-api-key'}, {baz: 'abc'}) + expect(res.type).toEqual('ok') + expect(outputMock.debug()).toContain('"api_key": "****"') + expect(outputMock.debug()).not.toContain('some-api-key') + }) }) diff --git a/packages/cli-kit/src/public/node/monorail.ts b/packages/cli-kit/src/public/node/monorail.ts index f0bc3fc3bb..27b41c2c57 100644 --- a/packages/cli-kit/src/public/node/monorail.ts +++ b/packages/cli-kit/src/public/node/monorail.ts @@ -198,7 +198,7 @@ export async function publishMonorailEvent(payload: T): T { + const result = {...payload} + if ('api_key' in result) { + result.api_key = '****' + } + + return result +} + const buildHeaders = (currentTime: number) => { return { 'Content-Type': 'application/json; charset=utf-8',