@newrelic/browser-agent 1.306.0-rc.1 → 1.306.0

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.
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.306.0-rc.1";
20
+ const VERSION = exports.VERSION = "1.306.0";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.306.0-rc.1";
20
+ const VERSION = exports.VERSION = "1.306.0";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -26,12 +26,12 @@ var denyList = [];
26
26
  function shouldCollectEvent(params) {
27
27
  if (!params || hasUndefinedHostname(params)) return false;
28
28
  if (denyList.length === 0) return true;
29
-
30
- // short circuit if deny list contains just a wildcard
31
- if (denyList[0].hostname === '*') return false;
32
29
  for (var i = 0; i < denyList.length; i++) {
33
30
  var parsed = denyList[i];
34
- if (parsed.hostname.test(params.hostname) && parsed.pathname.test(params.pathname)) {
31
+ if (parsed.hostname === '*') {
32
+ return false;
33
+ }
34
+ if (domainMatchesPattern(parsed.hostname, params.hostname) && comparePath(parsed.pathname, params.pathname)) {
35
35
  return false;
36
36
  }
37
37
  }
@@ -54,13 +54,6 @@ function setDenyList(denyListConfig) {
54
54
  let url = denyListConfig[i];
55
55
  if (!url) continue; // ignore bad values like undefined or empty strings
56
56
 
57
- // short circuit if deny list entry is just a wildcard
58
- if (url === '*') {
59
- denyList = [{
60
- hostname: '*'
61
- }];
62
- return;
63
- }
64
57
  if (url.indexOf('http://') === 0) {
65
58
  url = url.substring(7);
66
59
  } else if (url.indexOf('https://') === 0) {
@@ -73,24 +66,45 @@ function setDenyList(denyListConfig) {
73
66
  pathname = url.substring(firstSlash);
74
67
  } else {
75
68
  host = url;
76
- pathname = '*';
69
+ pathname = '';
77
70
  }
78
71
  let [hostname] = host.split(':');
79
72
  denyList.push({
80
- hostname: convertToRegularExpression(hostname),
81
- pathname: convertToRegularExpression(pathname, true)
73
+ hostname,
74
+ pathname
82
75
  });
83
76
  }
84
77
  }
78
+ /**
79
+ * Returns true if the right side of `domain` (end of string) matches `pattern`.
80
+ * @param {string} pattern - a string to be matched against the end of `domain` string
81
+ * @param {string} domain - a domain string with no protocol or path (e.g., app1.example.com)
82
+ * @returns {boolean} `true` if domain matches pattern; else `false`
83
+ */
84
+ function domainMatchesPattern(pattern, domain) {
85
+ if (pattern.length > domain.length) {
86
+ return false;
87
+ }
88
+ return domain.indexOf(pattern) === domain.length - pattern.length;
89
+ }
85
90
 
86
91
  /**
87
- * Converts a deny list filter string into a regular expression object with wildcard support
88
- * @param {string} filter - deny list filter to convert
89
- * @param {boolean} [isPathname=false] - indicates if the filter is a pathname
90
- * @returns {RegExp} - regular expression object built from the input string
92
+ * Returns true if a URL path matches a pattern string, disregarding leading slashes.
93
+ * @param {string} pattern - a string to compare with path (e.g., api/v1)
94
+ * @param {string} path - a string representing a URL path (e.g., /api/v1)
95
+ * @returns {boolean} `true` if path and pattern are an exact string match (except for leading slashes); else `false`
91
96
  */
92
- function convertToRegularExpression(filter, isPathname = false) {
93
- const newFilter = filter.replace(/[.+?^${}()|[\]\\]/g, m => '\\' + m) // use a replacer function to not break apm injection
94
- .replace(/\*/g, '.*?'); // use lazy matching instead of greedy
95
- return new RegExp((isPathname ? '^' : '') + newFilter + '$');
97
+ function comparePath(pattern, path) {
98
+ if (pattern.indexOf('/') === 0) {
99
+ pattern = pattern.substring(1);
100
+ }
101
+ if (path.indexOf('/') === 0) {
102
+ path = path.substring(1);
103
+ }
104
+
105
+ // No path in pattern means match all paths.
106
+ if (pattern === '') {
107
+ return true;
108
+ }
109
+ return pattern === path;
96
110
  }
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.306.0-rc.1";
14
+ export const VERSION = "1.306.0";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.306.0-rc.1";
14
+ export const VERSION = "1.306.0";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -18,12 +18,12 @@ var denyList = [];
18
18
  export function shouldCollectEvent(params) {
19
19
  if (!params || hasUndefinedHostname(params)) return false;
20
20
  if (denyList.length === 0) return true;
21
-
22
- // short circuit if deny list contains just a wildcard
23
- if (denyList[0].hostname === '*') return false;
24
21
  for (var i = 0; i < denyList.length; i++) {
25
22
  var parsed = denyList[i];
26
- if (parsed.hostname.test(params.hostname) && parsed.pathname.test(params.pathname)) {
23
+ if (parsed.hostname === '*') {
24
+ return false;
25
+ }
26
+ if (domainMatchesPattern(parsed.hostname, params.hostname) && comparePath(parsed.pathname, params.pathname)) {
27
27
  return false;
28
28
  }
29
29
  }
@@ -46,13 +46,6 @@ export function setDenyList(denyListConfig) {
46
46
  let url = denyListConfig[i];
47
47
  if (!url) continue; // ignore bad values like undefined or empty strings
48
48
 
49
- // short circuit if deny list entry is just a wildcard
50
- if (url === '*') {
51
- denyList = [{
52
- hostname: '*'
53
- }];
54
- return;
55
- }
56
49
  if (url.indexOf('http://') === 0) {
57
50
  url = url.substring(7);
58
51
  } else if (url.indexOf('https://') === 0) {
@@ -65,24 +58,45 @@ export function setDenyList(denyListConfig) {
65
58
  pathname = url.substring(firstSlash);
66
59
  } else {
67
60
  host = url;
68
- pathname = '*';
61
+ pathname = '';
69
62
  }
70
63
  let [hostname] = host.split(':');
71
64
  denyList.push({
72
- hostname: convertToRegularExpression(hostname),
73
- pathname: convertToRegularExpression(pathname, true)
65
+ hostname,
66
+ pathname
74
67
  });
75
68
  }
76
69
  }
70
+ /**
71
+ * Returns true if the right side of `domain` (end of string) matches `pattern`.
72
+ * @param {string} pattern - a string to be matched against the end of `domain` string
73
+ * @param {string} domain - a domain string with no protocol or path (e.g., app1.example.com)
74
+ * @returns {boolean} `true` if domain matches pattern; else `false`
75
+ */
76
+ function domainMatchesPattern(pattern, domain) {
77
+ if (pattern.length > domain.length) {
78
+ return false;
79
+ }
80
+ return domain.indexOf(pattern) === domain.length - pattern.length;
81
+ }
77
82
 
78
83
  /**
79
- * Converts a deny list filter string into a regular expression object with wildcard support
80
- * @param {string} filter - deny list filter to convert
81
- * @param {boolean} [isPathname=false] - indicates if the filter is a pathname
82
- * @returns {RegExp} - regular expression object built from the input string
84
+ * Returns true if a URL path matches a pattern string, disregarding leading slashes.
85
+ * @param {string} pattern - a string to compare with path (e.g., api/v1)
86
+ * @param {string} path - a string representing a URL path (e.g., /api/v1)
87
+ * @returns {boolean} `true` if path and pattern are an exact string match (except for leading slashes); else `false`
83
88
  */
84
- function convertToRegularExpression(filter, isPathname = false) {
85
- const newFilter = filter.replace(/[.+?^${}()|[\]\\]/g, m => '\\' + m) // use a replacer function to not break apm injection
86
- .replace(/\*/g, '.*?'); // use lazy matching instead of greedy
87
- return new RegExp((isPathname ? '^' : '') + newFilter + '$');
89
+ function comparePath(pattern, path) {
90
+ if (pattern.indexOf('/') === 0) {
91
+ pattern = pattern.substring(1);
92
+ }
93
+ if (path.indexOf('/') === 0) {
94
+ path = path.substring(1);
95
+ }
96
+
97
+ // No path in pattern means match all paths.
98
+ if (pattern === '') {
99
+ return true;
100
+ }
101
+ return pattern === path;
88
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deny-list.d.ts","sourceRoot":"","sources":["../../../../src/common/deny-list/deny-list.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,2CAHW,MAAM,GACJ,OAAO,CAoBnB;AAED,2DAEC;AAED;;;GAGG;AACH,4CAFW,MAAM,EAAE,QAyClB"}
1
+ {"version":3,"file":"deny-list.d.ts","sourceRoot":"","sources":["../../../../src/common/deny-list/deny-list.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,2CAHW,MAAM,GACJ,OAAO,CAqBnB;AAED,2DAEC;AAED;;;GAGG;AACH,4CAFW,MAAM,EAAE,QAgClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.306.0-rc.1",
3
+ "version": "1.306.0",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -292,4 +292,4 @@
292
292
  "README.md",
293
293
  "CHANGELOG.md"
294
294
  ]
295
- }
295
+ }
@@ -20,14 +20,15 @@ export function shouldCollectEvent (params) {
20
20
 
21
21
  if (denyList.length === 0) return true
22
22
 
23
- // short circuit if deny list contains just a wildcard
24
- if (denyList[0].hostname === '*') return false
25
-
26
23
  for (var i = 0; i < denyList.length; i++) {
27
24
  var parsed = denyList[i]
28
25
 
29
- if (parsed.hostname.test(params.hostname) &&
30
- parsed.pathname.test(params.pathname)) {
26
+ if (parsed.hostname === '*') {
27
+ return false
28
+ }
29
+
30
+ if (domainMatchesPattern(parsed.hostname, params.hostname) &&
31
+ comparePath(parsed.pathname, params.pathname)) {
31
32
  return false
32
33
  }
33
34
  }
@@ -54,12 +55,6 @@ export function setDenyList (denyListConfig) {
54
55
  let url = denyListConfig[i]
55
56
  if (!url) continue // ignore bad values like undefined or empty strings
56
57
 
57
- // short circuit if deny list entry is just a wildcard
58
- if (url === '*') {
59
- denyList = [{ hostname: '*' }]
60
- return
61
- }
62
-
63
58
  if (url.indexOf('http://') === 0) {
64
59
  url = url.substring(7)
65
60
  } else if (url.indexOf('https://') === 0) {
@@ -73,26 +68,46 @@ export function setDenyList (denyListConfig) {
73
68
  pathname = url.substring(firstSlash)
74
69
  } else {
75
70
  host = url
76
- pathname = '*'
71
+ pathname = ''
77
72
  }
78
73
  let [hostname] = host.split(':')
79
74
 
80
- denyList.push({
81
- hostname: convertToRegularExpression(hostname),
82
- pathname: convertToRegularExpression(pathname, true)
83
- })
75
+ denyList.push({ hostname, pathname })
84
76
  }
85
77
  }
78
+ /**
79
+ * Returns true if the right side of `domain` (end of string) matches `pattern`.
80
+ * @param {string} pattern - a string to be matched against the end of `domain` string
81
+ * @param {string} domain - a domain string with no protocol or path (e.g., app1.example.com)
82
+ * @returns {boolean} `true` if domain matches pattern; else `false`
83
+ */
84
+ function domainMatchesPattern (pattern, domain) {
85
+ if (pattern.length > domain.length) {
86
+ return false
87
+ }
88
+
89
+ return domain.indexOf(pattern) === (domain.length - pattern.length)
90
+ }
86
91
 
87
92
  /**
88
- * Converts a deny list filter string into a regular expression object with wildcard support
89
- * @param {string} filter - deny list filter to convert
90
- * @param {boolean} [isPathname=false] - indicates if the filter is a pathname
91
- * @returns {RegExp} - regular expression object built from the input string
93
+ * Returns true if a URL path matches a pattern string, disregarding leading slashes.
94
+ * @param {string} pattern - a string to compare with path (e.g., api/v1)
95
+ * @param {string} path - a string representing a URL path (e.g., /api/v1)
96
+ * @returns {boolean} `true` if path and pattern are an exact string match (except for leading slashes); else `false`
92
97
  */
93
- function convertToRegularExpression (filter, isPathname = false) {
94
- const newFilter = filter
95
- .replace(/[.+?^${}()|[\]\\]/g, (m) => '\\' + m) // use a replacer function to not break apm injection
96
- .replace(/\*/g, '.*?') // use lazy matching instead of greedy
97
- return new RegExp((isPathname ? '^' : '') + newFilter + '$')
98
+ function comparePath (pattern, path) {
99
+ if (pattern.indexOf('/') === 0) {
100
+ pattern = pattern.substring(1)
101
+ }
102
+
103
+ if (path.indexOf('/') === 0) {
104
+ path = path.substring(1)
105
+ }
106
+
107
+ // No path in pattern means match all paths.
108
+ if (pattern === '') {
109
+ return true
110
+ }
111
+
112
+ return pattern === path
98
113
  }