Skip to content

Commit 2ba09fe

Browse files
committed
ensure media elements have their source blocked correctly (#97)
* Fixes a bug in the `needsMask` processing that would stop recording children if `highlight-mask` was set on a div with `enableStrictPrivacy` set globally. * Adds source obfuscation for other media elements: video, audio, and source. Testing: before the fix - https://app.highlight.io/649/sessions/o5jfoC9BXXjBkxqwpVbNNDWK3hcI after the fix - https://app.highlight.io/649/sessions/9DR6a5arNtGacbkr2pwyPn5ENh3E
1 parent 66b34eb commit 2ba09fe

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

packages/rrweb-snapshot/src/snapshot.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
extractFileExtension,
3030
absolutifyURLs,
3131
markCssSplits,
32+
isElementSrcBlocked,
3233
} from './utils';
3334
import dom from '@rrweb/utils';
3435

@@ -796,16 +797,20 @@ function serializeElementNode(
796797
}
797798
}
798799
// block element
799-
if (needBlock || needMask || (tagName === 'img' && enableStrictPrivacy)) {
800+
if (
801+
needBlock ||
802+
needMask ||
803+
(enableStrictPrivacy && isElementSrcBlocked(tagName))
804+
) {
800805
const { width, height } = n.getBoundingClientRect();
801806
attributes = {
802807
class: attributes.class,
803808
rr_width: `${width}px`,
804809
rr_height: `${height}px`,
805810
};
806-
if (enableStrictPrivacy) {
807-
needBlock = true;
808-
}
811+
}
812+
if (enableStrictPrivacy && isElementSrcBlocked(tagName)) {
813+
needBlock = true;
809814
}
810815
// iframe
811816
if (tagName === 'iframe' && !keepIframeSrcFn(attributes.src as string)) {
@@ -1077,10 +1082,10 @@ export function serializeNodeWithId(
10771082
!!serializedNode.needMask;
10781083

10791084
/** Highlight Code Begin */
1080-
// Remove the image's src if enableStrictPrivacy.
1081-
if (strictPrivacy && serializedNode.tagName === 'img') {
1085+
// process enableStrictPrivacy obfuscation of non-text elements
1086+
if (strictPrivacy && isElementSrcBlocked(serializedNode.tagName)) {
10821087
const clone = n.cloneNode();
1083-
(clone as unknown as HTMLImageElement).src = '';
1088+
(clone as unknown as { src: string }).src = '';
10841089
mirror.add(clone, serializedNode);
10851090
}
10861091
/** Highlight Code End */

packages/rrweb-snapshot/src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,15 @@ export function obfuscateText(text: string): string {
518518
.join(' ') || '';
519519
return text;
520520
}
521+
522+
// returns true if the tag name is an element type that should have its source blocked
523+
export function isElementSrcBlocked(tagName: string): boolean {
524+
return (
525+
tagName === 'img' ||
526+
tagName === 'video' ||
527+
tagName === 'audio' ||
528+
tagName === 'source'
529+
);
530+
}
531+
521532
/* End of Highlight Code */

0 commit comments

Comments
 (0)