Skip to content

Commit ca30609

Browse files
authored
fix(replay): Make maskAllText selector more specific (#6544)
Sometimes, we seemed to be masking e.g. content of style tags. This new selector should be more specific to not mask anything that we know is not actually text.
1 parent 7139cec commit ca30609

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

packages/replay/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ export const MAX_SESSION_LIFE = 1_800_000; // 30 minutes
2525
*/
2626
export const DEFAULT_SESSION_SAMPLE_RATE = 0.1;
2727
export const DEFAULT_ERROR_SAMPLE_RATE = 1.0;
28+
29+
/** The select to use for the `maskAllText` option */
30+
export const MASK_ALL_TEXT_SELECTOR = 'body *:not(style,script)';

packages/replay/src/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { BrowserClient, BrowserOptions } from '@sentry/browser';
22
import { getCurrentHub } from '@sentry/core';
33
import { Integration } from '@sentry/types';
44

5-
import { DEFAULT_ERROR_SAMPLE_RATE, DEFAULT_SESSION_SAMPLE_RATE } from './constants';
5+
import { DEFAULT_ERROR_SAMPLE_RATE, DEFAULT_SESSION_SAMPLE_RATE, MASK_ALL_TEXT_SELECTOR } from './constants';
66
import { ReplayContainer } from './replay';
77
import type { RecordingOptions, ReplayConfiguration, ReplayPluginOptions } from './types';
88
import { isBrowser } from './util/isBrowser';
@@ -107,7 +107,7 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
107107
// `maskAllText` is a more user friendly option to configure
108108
// `maskTextSelector`. This means that all nodes will have their text
109109
// content masked.
110-
this.recordingOptions.maskTextSelector = '*';
110+
this.recordingOptions.maskTextSelector = MASK_ALL_TEXT_SELECTOR;
111111
}
112112

113113
if (this.options.blockAllMedia) {

packages/replay/test/unit/index-integrationSettings.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MASK_ALL_TEXT_SELECTOR } from '../../src/constants';
12
import { mockSdk } from './../index';
23

34
describe('integration settings', () => {
@@ -168,13 +169,13 @@ describe('integration settings', () => {
168169
const { replay } = await mockSdk({ replayOptions: {} });
169170

170171
// Default is true
171-
expect(replay['_recordingOptions'].maskTextSelector).toBe('*');
172+
expect(replay['_recordingOptions'].maskTextSelector).toBe(MASK_ALL_TEXT_SELECTOR);
172173
});
173174

174175
it('works with true', async () => {
175176
const { replay } = await mockSdk({ replayOptions: { maskAllText: true } });
176177

177-
expect(replay['_recordingOptions'].maskTextSelector).toBe('*');
178+
expect(replay['_recordingOptions'].maskTextSelector).toBe(MASK_ALL_TEXT_SELECTOR);
178179
});
179180

180181
it('works with false', async () => {
@@ -186,7 +187,7 @@ describe('integration settings', () => {
186187
it('overwrites custom maskTextSelector option', async () => {
187188
const { replay } = await mockSdk({ replayOptions: { maskAllText: true, maskTextSelector: '[custom]' } });
188189

189-
expect(replay['_recordingOptions'].maskTextSelector).toBe('*');
190+
expect(replay['_recordingOptions'].maskTextSelector).toBe(MASK_ALL_TEXT_SELECTOR);
190191
});
191192
});
192193

packages/replay/test/unit/index.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { getCurrentHub } from '@sentry/core';
22
import { EventType } from 'rrweb';
33

4-
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
4+
import {
5+
MASK_ALL_TEXT_SELECTOR,
6+
MAX_SESSION_LIFE,
7+
REPLAY_SESSION_KEY,
8+
VISIBILITY_CHANGE_TIMEOUT,
9+
WINDOW,
10+
} from '../../src/constants';
511
import { ReplayContainer } from '../../src/replay';
612
import type { RecordingEvent } from '../../src/types';
713
import { addEvent } from '../../src/util/addEvent';
@@ -39,7 +45,7 @@ describe('Replay with custom mock', () => {
3945
"ignoreClass": "sentry-test-ignore",
4046
"maskAllInputs": true,
4147
"maskTextClass": "sentry-mask",
42-
"maskTextSelector": "*",
48+
"maskTextSelector": "${MASK_ALL_TEXT_SELECTOR}",
4349
}
4450
`);
4551
});

0 commit comments

Comments
 (0)