@cloudcare/browser-rum 3.3.13 → 3.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/startRecording.js +5 -2
  4. package/cjs/boot/startRecording.js.map +1 -1
  5. package/cjs/domain/configuration.js +1 -0
  6. package/cjs/domain/configuration.js.map +1 -1
  7. package/cjs/domain/deflate/deflateWorker.js +1 -1
  8. package/cjs/domain/privacy.js +278 -0
  9. package/cjs/domain/privacy.js.map +1 -0
  10. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  11. package/cjs/domain/replay/record/privacy.js +11 -272
  12. package/cjs/domain/replay/record/privacy.js.map +1 -1
  13. package/cjs/domain/replay/record/record.js +10 -1
  14. package/cjs/domain/replay/record/record.js.map +1 -1
  15. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +81 -19
  16. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  17. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  18. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  19. package/cjs/domain/rumEventsCollection/view/trackViews.js +16 -5
  20. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  21. package/cjs/domain/rumSessionManager.js +2 -2
  22. package/cjs/domain/rumSessionManager.js.map +1 -1
  23. package/esm/boot/buildEnv.js +1 -1
  24. package/esm/boot/startRecording.js +5 -2
  25. package/esm/boot/startRecording.js.map +1 -1
  26. package/esm/domain/configuration.js +1 -0
  27. package/esm/domain/configuration.js.map +1 -1
  28. package/esm/domain/deflate/deflateWorker.js +1 -1
  29. package/esm/domain/privacy.js +266 -0
  30. package/esm/domain/privacy.js.map +1 -0
  31. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  32. package/esm/domain/replay/record/privacy.js +1 -266
  33. package/esm/domain/replay/record/privacy.js.map +1 -1
  34. package/esm/domain/replay/record/record.js +10 -1
  35. package/esm/domain/replay/record/record.js.map +1 -1
  36. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +80 -18
  37. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  38. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  39. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  40. package/esm/domain/rumEventsCollection/view/trackViews.js +17 -6
  41. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  42. package/esm/domain/rumSessionManager.js +2 -2
  43. package/esm/domain/rumSessionManager.js.map +1 -1
  44. package/package.json +4 -4
  45. package/src/boot/startRecording.js +11 -2
  46. package/src/domain/configuration.js +4 -0
  47. package/src/domain/privacy.js +356 -0
  48. package/src/domain/replay/record/privacy.js +1 -356
  49. package/src/domain/replay/record/record.js +10 -1
  50. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +148 -21
  51. package/src/domain/rumEventsCollection/actions/trackClickActions.js +19 -5
  52. package/src/domain/rumEventsCollection/view/trackViews.js +33 -6
  53. package/src/domain/rumSessionManager.js +2 -2
@@ -0,0 +1,356 @@
1
+ import {
2
+ isElementNode,
3
+ getParentNode,
4
+ isTextNode
5
+ } from '@cloudcare/browser-core'
6
+
7
+ import {
8
+ NodePrivacyLevel,
9
+ PRIVACY_ATTR_NAME,
10
+ PRIVACY_ATTR_VALUE_ALLOW,
11
+ PRIVACY_ATTR_VALUE_MASK,
12
+ PRIVACY_ATTR_VALUE_MASK_USER_INPUT,
13
+ PRIVACY_ATTR_VALUE_HIDDEN,
14
+ PRIVACY_CLASS_ALLOW,
15
+ PRIVACY_CLASS_MASK,
16
+ PRIVACY_CLASS_MASK_USER_INPUT,
17
+ PRIVACY_CLASS_HIDDEN,
18
+ FORM_PRIVATE_TAG_NAMES,
19
+ CENSORED_STRING_MARK
20
+ } from '../constants'
21
+
22
+ export var MAX_ATTRIBUTE_VALUE_CHAR_LENGTH = 100_000
23
+
24
+ var TEXT_MASKING_CHAR = 'x'
25
+ export var MAX_PRIVACY_ANCESTOR_DEPTH = 1000
26
+
27
+ /**
28
+ * Get node privacy level by iterating over its ancestors. When the direct parent privacy level is
29
+ * know, it is best to use something like:
30
+ *
31
+ * derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel)
32
+ */
33
+ export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache) {
34
+ if (cache && cache.has(node)) {
35
+ return cache.get(node)
36
+ }
37
+
38
+ // Resolve ancestors iteratively so an adversarially deep DOM cannot grow the
39
+ // JavaScript stack. If the watermark is crossed, fail closed: hiding the
40
+ // branch is safer than spending unbounded time resolving its privacy chain.
41
+ var unresolvedNodes = []
42
+ var currentNode = node
43
+ var inheritedPrivacyLevel
44
+ while (currentNode) {
45
+ if (cache && cache.has(currentNode)) {
46
+ inheritedPrivacyLevel = cache.get(currentNode)
47
+ break
48
+ }
49
+ if (unresolvedNodes.length >= MAX_PRIVACY_ANCESTOR_DEPTH) {
50
+ inheritedPrivacyLevel = NodePrivacyLevel.HIDDEN
51
+ break
52
+ }
53
+ unresolvedNodes.push(currentNode)
54
+ currentNode = getParentNode(currentNode)
55
+ }
56
+ if (inheritedPrivacyLevel === undefined) {
57
+ inheritedPrivacyLevel = defaultPrivacyLevel
58
+ }
59
+
60
+ while (unresolvedNodes.length) {
61
+ var unresolvedNode = unresolvedNodes.pop()
62
+ inheritedPrivacyLevel = reducePrivacyLevel(
63
+ getNodeSelfPrivacyLevel(unresolvedNode),
64
+ inheritedPrivacyLevel
65
+ )
66
+ if (cache) {
67
+ cache.set(unresolvedNode, inheritedPrivacyLevel)
68
+ }
69
+ }
70
+ return inheritedPrivacyLevel
71
+ }
72
+
73
+ /**
74
+ * Reduces the next privacy level based on self + parent privacy levels
75
+ */
76
+ export function reducePrivacyLevel(childPrivacyLevel, parentNodePrivacyLevel) {
77
+ switch (parentNodePrivacyLevel) {
78
+ // These values cannot be overridden
79
+ case NodePrivacyLevel.HIDDEN:
80
+ case NodePrivacyLevel.IGNORE:
81
+ return parentNodePrivacyLevel
82
+ }
83
+ switch (childPrivacyLevel) {
84
+ case NodePrivacyLevel.ALLOW:
85
+ case NodePrivacyLevel.MASK:
86
+ case NodePrivacyLevel.MASK_USER_INPUT:
87
+ case NodePrivacyLevel.HIDDEN:
88
+ case NodePrivacyLevel.IGNORE:
89
+ return childPrivacyLevel
90
+ default:
91
+ return parentNodePrivacyLevel
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Determines the node's own privacy level without checking for ancestors.
97
+ */
98
+ export function getNodeSelfPrivacyLevel(node) {
99
+ // Only Element types can have a privacy level set
100
+ if (!isElementNode(node)) {
101
+ return
102
+ }
103
+
104
+ var privAttr = node.getAttribute(PRIVACY_ATTR_NAME)
105
+
106
+ // Overrules for replay purpose
107
+ if (node.tagName === 'BASE') {
108
+ return NodePrivacyLevel.ALLOW
109
+ }
110
+
111
+ // Overrules to enforce end-user protection
112
+ if (node.tagName === 'INPUT') {
113
+ var inputElement = node
114
+ if (
115
+ inputElement.type === 'password' ||
116
+ inputElement.type === 'email' ||
117
+ inputElement.type === 'tel'
118
+ ) {
119
+ return NodePrivacyLevel.MASK
120
+ }
121
+ if (inputElement.type === 'hidden') {
122
+ return NodePrivacyLevel.MASK
123
+ }
124
+ var autocomplete = inputElement.getAttribute('autocomplete')
125
+ // Handle input[autocomplete=cc-number/cc-csc/cc-exp/cc-exp-month/cc-exp-year]
126
+ if (autocomplete && autocomplete.indexOf('cc-') === 0) {
127
+ return NodePrivacyLevel.MASK
128
+ }
129
+ }
130
+
131
+ // Check HTML privacy attributes and classes
132
+ if (
133
+ privAttr === PRIVACY_ATTR_VALUE_HIDDEN ||
134
+ node.classList.contains(PRIVACY_CLASS_HIDDEN)
135
+ ) {
136
+ return NodePrivacyLevel.HIDDEN
137
+ }
138
+
139
+ if (
140
+ privAttr === PRIVACY_ATTR_VALUE_MASK ||
141
+ node.classList.contains(PRIVACY_CLASS_MASK)
142
+ ) {
143
+ return NodePrivacyLevel.MASK
144
+ }
145
+
146
+ if (
147
+ privAttr === PRIVACY_ATTR_VALUE_MASK_USER_INPUT ||
148
+ node.classList.contains(PRIVACY_CLASS_MASK_USER_INPUT)
149
+ ) {
150
+ return NodePrivacyLevel.MASK_USER_INPUT
151
+ }
152
+
153
+ if (
154
+ privAttr === PRIVACY_ATTR_VALUE_ALLOW ||
155
+ node.classList.contains(PRIVACY_CLASS_ALLOW)
156
+ ) {
157
+ return NodePrivacyLevel.ALLOW
158
+ }
159
+
160
+ if (shouldIgnoreElement(node)) {
161
+ return NodePrivacyLevel.IGNORE
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Helper aiming to unify `mask` and `mask-user-input` privacy levels:
167
+ *
168
+ * In the `mask` case, it is trivial: we should mask the element.
169
+ *
170
+ * In the `mask-user-input` case, we should mask the element only if it is a "form" element or the
171
+ * direct parent is a form element for text nodes).
172
+ *
173
+ * Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a
174
+ * node if it is ignored or hidden? it doesn't matter since it won't be serialized).
175
+ */
176
+ export function shouldMaskNode(configuration, node, privacyLevel) {
177
+ if (
178
+ configuration.shouldMaskNode &&
179
+ configuration.shouldMaskNode(node, privacyLevel) === true
180
+ )
181
+ return true
182
+ switch (privacyLevel) {
183
+ case NodePrivacyLevel.MASK:
184
+ case NodePrivacyLevel.HIDDEN:
185
+ case NodePrivacyLevel.IGNORE:
186
+ return true
187
+ case NodePrivacyLevel.MASK_USER_INPUT:
188
+ return isTextNode(node)
189
+ ? isFormElement(node.parentNode)
190
+ : isFormElement(node)
191
+ default:
192
+ return false
193
+ }
194
+ }
195
+
196
+ function isFormElement(node) {
197
+ if (!node || node.nodeType !== node.ELEMENT_NODE) {
198
+ return false
199
+ }
200
+ var element = node
201
+ if (element.tagName === 'INPUT') {
202
+ switch (element.type) {
203
+ case 'button':
204
+ case 'color':
205
+ case 'reset':
206
+ case 'submit':
207
+ return false
208
+ }
209
+ }
210
+ return !!FORM_PRIVATE_TAG_NAMES[element.tagName]
211
+ }
212
+
213
+ /**
214
+ * Text censoring non-destructively maintains whitespace characters in order to preserve text shape
215
+ * during replay.
216
+ */
217
+ export var censorText = function (text) {
218
+ return text.replace(/\S/g, TEXT_MASKING_CHAR)
219
+ }
220
+
221
+ export function getTextContent(
222
+ configuration,
223
+ textNode,
224
+ ignoreWhiteSpace,
225
+ parentNodePrivacyLevel
226
+ ) {
227
+ // The parent node may not be a html element which has a tagName attribute.
228
+ // So just let it be undefined which is ok in this use case.
229
+ var parentTagName = textNode.parentElement && textNode.parentElement.tagName
230
+ var textContent = textNode.textContent || ''
231
+
232
+ if (ignoreWhiteSpace && !textContent.trim()) {
233
+ return
234
+ }
235
+
236
+ var nodePrivacyLevel = parentNodePrivacyLevel
237
+
238
+ // var isStyle = parentTagName === 'STYLE' ? true : undefined
239
+ var isScript = parentTagName === 'SCRIPT'
240
+
241
+ if (isScript) {
242
+ // For perf reasons, we don't record script (heuristic)
243
+ textContent = CENSORED_STRING_MARK
244
+ } else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
245
+ // Should never occur, but just in case, we set to CENSORED_MARK.
246
+ textContent = CENSORED_STRING_MARK
247
+ } else if (shouldMaskNode(configuration, textNode, nodePrivacyLevel)) {
248
+ if (
249
+ // Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP
250
+ parentTagName === 'DATALIST' ||
251
+ parentTagName === 'SELECT' ||
252
+ parentTagName === 'OPTGROUP'
253
+ ) {
254
+ if (!textContent.trim()) {
255
+ return
256
+ }
257
+ } else if (parentTagName === 'OPTION') {
258
+ // <Option> has low entropy in charset + text length, so use `CENSORED_STRING_MARK` when masked
259
+ textContent = CENSORED_STRING_MARK
260
+ } else {
261
+ textContent = censorText(textContent)
262
+ }
263
+ }
264
+ // else if (isStyle && textContent) {
265
+ // try {
266
+ // // try to read style sheet
267
+ // if (textNode.nextSibling || textNode.previousSibling) {
268
+ // // This is not the only child of the stylesheet.
269
+ // // We can't read all of the sheet's .cssRules and expect them
270
+ // // to _only_ include the current rule(s) added by the text node.
271
+ // // So we'll be conservative and keep textContent as-is.
272
+ // } else if (
273
+ // textNode.parentNode &&
274
+ // textNode.parentNode.sheet &&
275
+ // textNode.parentNode.sheet.cssRules
276
+ // ) {
277
+ // textContent = getCssRulesString(textNode.parentNode.sheet)
278
+ // }
279
+ // } catch (err) {}
280
+ // textContent = switchToAbsoluteUrl(textContent, getHref())
281
+ // }
282
+ return textContent
283
+ }
284
+
285
+ /**
286
+ * We don't need this logic on the recorder side.
287
+ * For security related meta's, customer can mask themmanually given they
288
+ * are easy to identify in the HEAD tag.
289
+ */
290
+ export function shouldIgnoreElement(element) {
291
+ if (element.nodeName === 'SCRIPT') {
292
+ return true
293
+ }
294
+
295
+ if (element.nodeName === 'LINK') {
296
+ var relAttribute = getLowerCaseAttribute('rel')
297
+ return (
298
+ // Link as script - Ignore only when rel=preload, modulepreload or prefetch
299
+ (/preload|prefetch/i.test(relAttribute) &&
300
+ getLowerCaseAttribute('as') === 'script') ||
301
+ // Favicons
302
+ relAttribute === 'shortcut icon' ||
303
+ relAttribute === 'icon'
304
+ )
305
+ }
306
+
307
+ if (element.nodeName === 'META') {
308
+ var nameAttribute = getLowerCaseAttribute('name')
309
+ var relAttribute = getLowerCaseAttribute('rel')
310
+ var propertyAttribute = getLowerCaseAttribute('property')
311
+ return (
312
+ // Favicons
313
+ /^msapplication-tile(image|color)$/.test(nameAttribute) ||
314
+ nameAttribute === 'application-name' ||
315
+ relAttribute === 'icon' ||
316
+ relAttribute === 'apple-touch-icon' ||
317
+ relAttribute === 'shortcut icon' ||
318
+ // Description
319
+ nameAttribute === 'keywords' ||
320
+ nameAttribute === 'description' ||
321
+ // Social
322
+ /^(og|twitter|fb):/.test(propertyAttribute) ||
323
+ /^(og|twitter):/.test(nameAttribute) ||
324
+ nameAttribute === 'pinterest' ||
325
+ // Robots
326
+ nameAttribute === 'robots' ||
327
+ nameAttribute === 'googlebot' ||
328
+ nameAttribute === 'bingbot' ||
329
+ // Http headers. Ex: X-UA-Compatible, Content-Type, Content-Language, cache-control,
330
+ // X-Translated-By
331
+ element.hasAttribute('http-equiv') ||
332
+ // Authorship
333
+ nameAttribute === 'author' ||
334
+ nameAttribute === 'generator' ||
335
+ nameAttribute === 'framework' ||
336
+ nameAttribute === 'publisher' ||
337
+ nameAttribute === 'progid' ||
338
+ /^article:/.test(propertyAttribute) ||
339
+ /^product:/.test(propertyAttribute) ||
340
+ // Verification
341
+ nameAttribute === 'google-site-verification' ||
342
+ nameAttribute === 'yandex-verification' ||
343
+ nameAttribute === 'csrf-token' ||
344
+ nameAttribute === 'p:domain_verify' ||
345
+ nameAttribute === 'verify-v1' ||
346
+ nameAttribute === 'verification' ||
347
+ nameAttribute === 'shopify-checkout-api-token'
348
+ )
349
+ }
350
+
351
+ function getLowerCaseAttribute(name) {
352
+ return (element.getAttribute(name) || '').toLowerCase()
353
+ }
354
+
355
+ return false
356
+ }
@@ -1,356 +1 @@
1
- import {
2
- isElementNode,
3
- getParentNode,
4
- isTextNode
5
- } from '@cloudcare/browser-core'
6
-
7
- import {
8
- NodePrivacyLevel,
9
- PRIVACY_ATTR_NAME,
10
- PRIVACY_ATTR_VALUE_ALLOW,
11
- PRIVACY_ATTR_VALUE_MASK,
12
- PRIVACY_ATTR_VALUE_MASK_USER_INPUT,
13
- PRIVACY_ATTR_VALUE_HIDDEN,
14
- PRIVACY_CLASS_ALLOW,
15
- PRIVACY_CLASS_MASK,
16
- PRIVACY_CLASS_MASK_USER_INPUT,
17
- PRIVACY_CLASS_HIDDEN,
18
- FORM_PRIVATE_TAG_NAMES,
19
- CENSORED_STRING_MARK
20
- } from '../../../constants'
21
-
22
- export var MAX_ATTRIBUTE_VALUE_CHAR_LENGTH = 100_000
23
-
24
- var TEXT_MASKING_CHAR = 'x'
25
- export var MAX_PRIVACY_ANCESTOR_DEPTH = 1000
26
-
27
- /**
28
- * Get node privacy level by iterating over its ancestors. When the direct parent privacy level is
29
- * know, it is best to use something like:
30
- *
31
- * derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel)
32
- */
33
- export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache) {
34
- if (cache && cache.has(node)) {
35
- return cache.get(node)
36
- }
37
-
38
- // Resolve ancestors iteratively so an adversarially deep DOM cannot grow the
39
- // JavaScript stack. If the watermark is crossed, fail closed: hiding the
40
- // branch is safer than spending unbounded time resolving its privacy chain.
41
- var unresolvedNodes = []
42
- var currentNode = node
43
- var inheritedPrivacyLevel
44
- while (currentNode) {
45
- if (cache && cache.has(currentNode)) {
46
- inheritedPrivacyLevel = cache.get(currentNode)
47
- break
48
- }
49
- if (unresolvedNodes.length >= MAX_PRIVACY_ANCESTOR_DEPTH) {
50
- inheritedPrivacyLevel = NodePrivacyLevel.HIDDEN
51
- break
52
- }
53
- unresolvedNodes.push(currentNode)
54
- currentNode = getParentNode(currentNode)
55
- }
56
- if (inheritedPrivacyLevel === undefined) {
57
- inheritedPrivacyLevel = defaultPrivacyLevel
58
- }
59
-
60
- while (unresolvedNodes.length) {
61
- var unresolvedNode = unresolvedNodes.pop()
62
- inheritedPrivacyLevel = reducePrivacyLevel(
63
- getNodeSelfPrivacyLevel(unresolvedNode),
64
- inheritedPrivacyLevel
65
- )
66
- if (cache) {
67
- cache.set(unresolvedNode, inheritedPrivacyLevel)
68
- }
69
- }
70
- return inheritedPrivacyLevel
71
- }
72
-
73
- /**
74
- * Reduces the next privacy level based on self + parent privacy levels
75
- */
76
- export function reducePrivacyLevel(childPrivacyLevel, parentNodePrivacyLevel) {
77
- switch (parentNodePrivacyLevel) {
78
- // These values cannot be overridden
79
- case NodePrivacyLevel.HIDDEN:
80
- case NodePrivacyLevel.IGNORE:
81
- return parentNodePrivacyLevel
82
- }
83
- switch (childPrivacyLevel) {
84
- case NodePrivacyLevel.ALLOW:
85
- case NodePrivacyLevel.MASK:
86
- case NodePrivacyLevel.MASK_USER_INPUT:
87
- case NodePrivacyLevel.HIDDEN:
88
- case NodePrivacyLevel.IGNORE:
89
- return childPrivacyLevel
90
- default:
91
- return parentNodePrivacyLevel
92
- }
93
- }
94
-
95
- /**
96
- * Determines the node's own privacy level without checking for ancestors.
97
- */
98
- export function getNodeSelfPrivacyLevel(node) {
99
- // Only Element types can have a privacy level set
100
- if (!isElementNode(node)) {
101
- return
102
- }
103
-
104
- var privAttr = node.getAttribute(PRIVACY_ATTR_NAME)
105
-
106
- // Overrules for replay purpose
107
- if (node.tagName === 'BASE') {
108
- return NodePrivacyLevel.ALLOW
109
- }
110
-
111
- // Overrules to enforce end-user protection
112
- if (node.tagName === 'INPUT') {
113
- var inputElement = node
114
- if (
115
- inputElement.type === 'password' ||
116
- inputElement.type === 'email' ||
117
- inputElement.type === 'tel'
118
- ) {
119
- return NodePrivacyLevel.MASK
120
- }
121
- if (inputElement.type === 'hidden') {
122
- return NodePrivacyLevel.MASK
123
- }
124
- var autocomplete = inputElement.getAttribute('autocomplete')
125
- // Handle input[autocomplete=cc-number/cc-csc/cc-exp/cc-exp-month/cc-exp-year]
126
- if (autocomplete && autocomplete.indexOf('cc-') === 0) {
127
- return NodePrivacyLevel.MASK
128
- }
129
- }
130
-
131
- // Check HTML privacy attributes and classes
132
- if (
133
- privAttr === PRIVACY_ATTR_VALUE_HIDDEN ||
134
- node.classList.contains(PRIVACY_CLASS_HIDDEN)
135
- ) {
136
- return NodePrivacyLevel.HIDDEN
137
- }
138
-
139
- if (
140
- privAttr === PRIVACY_ATTR_VALUE_MASK ||
141
- node.classList.contains(PRIVACY_CLASS_MASK)
142
- ) {
143
- return NodePrivacyLevel.MASK
144
- }
145
-
146
- if (
147
- privAttr === PRIVACY_ATTR_VALUE_MASK_USER_INPUT ||
148
- node.classList.contains(PRIVACY_CLASS_MASK_USER_INPUT)
149
- ) {
150
- return NodePrivacyLevel.MASK_USER_INPUT
151
- }
152
-
153
- if (
154
- privAttr === PRIVACY_ATTR_VALUE_ALLOW ||
155
- node.classList.contains(PRIVACY_CLASS_ALLOW)
156
- ) {
157
- return NodePrivacyLevel.ALLOW
158
- }
159
-
160
- if (shouldIgnoreElement(node)) {
161
- return NodePrivacyLevel.IGNORE
162
- }
163
- }
164
-
165
- /**
166
- * Helper aiming to unify `mask` and `mask-user-input` privacy levels:
167
- *
168
- * In the `mask` case, it is trivial: we should mask the element.
169
- *
170
- * In the `mask-user-input` case, we should mask the element only if it is a "form" element or the
171
- * direct parent is a form element for text nodes).
172
- *
173
- * Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a
174
- * node if it is ignored or hidden? it doesn't matter since it won't be serialized).
175
- */
176
- export function shouldMaskNode(configuration, node, privacyLevel) {
177
- if (
178
- configuration.shouldMaskNode &&
179
- configuration.shouldMaskNode(node, privacyLevel) === true
180
- )
181
- return true
182
- switch (privacyLevel) {
183
- case NodePrivacyLevel.MASK:
184
- case NodePrivacyLevel.HIDDEN:
185
- case NodePrivacyLevel.IGNORE:
186
- return true
187
- case NodePrivacyLevel.MASK_USER_INPUT:
188
- return isTextNode(node)
189
- ? isFormElement(node.parentNode)
190
- : isFormElement(node)
191
- default:
192
- return false
193
- }
194
- }
195
-
196
- function isFormElement(node) {
197
- if (!node || node.nodeType !== node.ELEMENT_NODE) {
198
- return false
199
- }
200
- var element = node
201
- if (element.tagName === 'INPUT') {
202
- switch (element.type) {
203
- case 'button':
204
- case 'color':
205
- case 'reset':
206
- case 'submit':
207
- return false
208
- }
209
- }
210
- return !!FORM_PRIVATE_TAG_NAMES[element.tagName]
211
- }
212
-
213
- /**
214
- * Text censoring non-destructively maintains whitespace characters in order to preserve text shape
215
- * during replay.
216
- */
217
- export var censorText = function (text) {
218
- return text.replace(/\S/g, TEXT_MASKING_CHAR)
219
- }
220
-
221
- export function getTextContent(
222
- configuration,
223
- textNode,
224
- ignoreWhiteSpace,
225
- parentNodePrivacyLevel
226
- ) {
227
- // The parent node may not be a html element which has a tagName attribute.
228
- // So just let it be undefined which is ok in this use case.
229
- var parentTagName = textNode.parentElement && textNode.parentElement.tagName
230
- var textContent = textNode.textContent || ''
231
-
232
- if (ignoreWhiteSpace && !textContent.trim()) {
233
- return
234
- }
235
-
236
- var nodePrivacyLevel = parentNodePrivacyLevel
237
-
238
- // var isStyle = parentTagName === 'STYLE' ? true : undefined
239
- var isScript = parentTagName === 'SCRIPT'
240
-
241
- if (isScript) {
242
- // For perf reasons, we don't record script (heuristic)
243
- textContent = CENSORED_STRING_MARK
244
- } else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
245
- // Should never occur, but just in case, we set to CENSORED_MARK.
246
- textContent = CENSORED_STRING_MARK
247
- } else if (shouldMaskNode(configuration, textNode, nodePrivacyLevel)) {
248
- if (
249
- // Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP
250
- parentTagName === 'DATALIST' ||
251
- parentTagName === 'SELECT' ||
252
- parentTagName === 'OPTGROUP'
253
- ) {
254
- if (!textContent.trim()) {
255
- return
256
- }
257
- } else if (parentTagName === 'OPTION') {
258
- // <Option> has low entropy in charset + text length, so use `CENSORED_STRING_MARK` when masked
259
- textContent = CENSORED_STRING_MARK
260
- } else {
261
- textContent = censorText(textContent)
262
- }
263
- }
264
- // else if (isStyle && textContent) {
265
- // try {
266
- // // try to read style sheet
267
- // if (textNode.nextSibling || textNode.previousSibling) {
268
- // // This is not the only child of the stylesheet.
269
- // // We can't read all of the sheet's .cssRules and expect them
270
- // // to _only_ include the current rule(s) added by the text node.
271
- // // So we'll be conservative and keep textContent as-is.
272
- // } else if (
273
- // textNode.parentNode &&
274
- // textNode.parentNode.sheet &&
275
- // textNode.parentNode.sheet.cssRules
276
- // ) {
277
- // textContent = getCssRulesString(textNode.parentNode.sheet)
278
- // }
279
- // } catch (err) {}
280
- // textContent = switchToAbsoluteUrl(textContent, getHref())
281
- // }
282
- return textContent
283
- }
284
-
285
- /**
286
- * We don't need this logic on the recorder side.
287
- * For security related meta's, customer can mask themmanually given they
288
- * are easy to identify in the HEAD tag.
289
- */
290
- export function shouldIgnoreElement(element) {
291
- if (element.nodeName === 'SCRIPT') {
292
- return true
293
- }
294
-
295
- if (element.nodeName === 'LINK') {
296
- var relAttribute = getLowerCaseAttribute('rel')
297
- return (
298
- // Link as script - Ignore only when rel=preload, modulepreload or prefetch
299
- (/preload|prefetch/i.test(relAttribute) &&
300
- getLowerCaseAttribute('as') === 'script') ||
301
- // Favicons
302
- relAttribute === 'shortcut icon' ||
303
- relAttribute === 'icon'
304
- )
305
- }
306
-
307
- if (element.nodeName === 'META') {
308
- var nameAttribute = getLowerCaseAttribute('name')
309
- var relAttribute = getLowerCaseAttribute('rel')
310
- var propertyAttribute = getLowerCaseAttribute('property')
311
- return (
312
- // Favicons
313
- /^msapplication-tile(image|color)$/.test(nameAttribute) ||
314
- nameAttribute === 'application-name' ||
315
- relAttribute === 'icon' ||
316
- relAttribute === 'apple-touch-icon' ||
317
- relAttribute === 'shortcut icon' ||
318
- // Description
319
- nameAttribute === 'keywords' ||
320
- nameAttribute === 'description' ||
321
- // Social
322
- /^(og|twitter|fb):/.test(propertyAttribute) ||
323
- /^(og|twitter):/.test(nameAttribute) ||
324
- nameAttribute === 'pinterest' ||
325
- // Robots
326
- nameAttribute === 'robots' ||
327
- nameAttribute === 'googlebot' ||
328
- nameAttribute === 'bingbot' ||
329
- // Http headers. Ex: X-UA-Compatible, Content-Type, Content-Language, cache-control,
330
- // X-Translated-By
331
- element.hasAttribute('http-equiv') ||
332
- // Authorship
333
- nameAttribute === 'author' ||
334
- nameAttribute === 'generator' ||
335
- nameAttribute === 'framework' ||
336
- nameAttribute === 'publisher' ||
337
- nameAttribute === 'progid' ||
338
- /^article:/.test(propertyAttribute) ||
339
- /^product:/.test(propertyAttribute) ||
340
- // Verification
341
- nameAttribute === 'google-site-verification' ||
342
- nameAttribute === 'yandex-verification' ||
343
- nameAttribute === 'csrf-token' ||
344
- nameAttribute === 'p:domain_verify' ||
345
- nameAttribute === 'verify-v1' ||
346
- nameAttribute === 'verification' ||
347
- nameAttribute === 'shopify-checkout-api-token'
348
- )
349
- }
350
-
351
- function getLowerCaseAttribute(name) {
352
- return (element.getAttribute(name) || '').toLowerCase()
353
- }
354
-
355
- return false
356
- }
1
+ export * from '../../privacy'