@honeybadger-io/js 6.16.5 → 6.16.6

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.
@@ -182,6 +182,17 @@
182
182
  var require$$0$1 = /*@__PURE__*/getAugmentedNamespace(stackTraceParser_esm);
183
183
 
184
184
  (function (exports) {
185
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
186
+ __assign = Object.assign || function(t) {
187
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
188
+ s = arguments[i];
189
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
190
+ t[p] = s[p];
191
+ }
192
+ return t;
193
+ };
194
+ return __assign.apply(this, arguments);
195
+ };
185
196
  var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
186
197
  if (k2 === undefined) k2 = k;
187
198
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -242,7 +253,7 @@
242
253
  }
243
254
  };
244
255
  Object.defineProperty(exports, "__esModule", { value: true });
245
- exports.logDeprecatedMethod = exports.globalThisOrWindow = exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrumentConsole = exports.instrument = exports.isErrorObject = exports.makeNotice = exports.logger = exports.sanitize = exports.shallowClone = exports.runAfterNotifyHandlers = exports.shouldSampleEvent = exports.resolveInsights = exports.runBeforeEventHandlers = exports.runBeforeNotifyHandlers = exports.getSourceForBacktrace = exports.getCauses = exports.calculateBacktraceShift = exports.DEFAULT_BACKTRACE_SHIFT = exports.makeBacktrace = exports.objectIsExtensible = exports.objectIsEmpty = exports.mergeNotice = exports.merge = void 0;
256
+ exports.logDeprecatedMethod = exports.globalThisOrWindow = exports.isBrowserConfig = exports.clone = exports.formatCGIData = exports.filterBreadcrumbs = exports.filterUrl = exports.filter = exports.generateStackTrace = exports.endpoint = exports.instrumentConsole = exports.instrument = exports.isErrorObject = exports.makeNotice = exports.logger = exports.sanitize = exports.shallowClone = exports.runAfterNotifyHandlers = exports.shouldSampleEvent = exports.resolveInsights = exports.runBeforeEventHandlers = exports.runBeforeNotifyHandlers = exports.getSourceForBacktrace = exports.getCauses = exports.calculateBacktraceShift = exports.DEFAULT_BACKTRACE_SHIFT = exports.makeBacktrace = exports.objectIsExtensible = exports.objectIsEmpty = exports.mergeNotice = exports.merge = void 0;
246
257
  /* eslint-disable prefer-rest-params */
247
258
  var stackTraceParser = __importStar(require$$0$1);
248
259
  function merge(obj1, obj2) {
@@ -828,6 +839,76 @@
828
839
  return result;
829
840
  }
830
841
  exports.filterUrl = filterUrl;
842
+ /**
843
+ * Breadcrumb metadata keys whose value is a URL, and so may carry a query string.
844
+ *
845
+ * Checked by name rather than by running `filterUrl` over every string value: a `?` is
846
+ * ordinary punctuation in a breadcrumb message or a console argument, and rewriting around
847
+ * it would mangle text that is not a URL at all.
848
+ */
849
+ var URL_METADATA_KEYS = ['url', 'from', 'to', 'href'];
850
+ /**
851
+ * Recursively rewrites the query string of every URL-bearing value.
852
+ *
853
+ * Nested as well as top-level: a breadcrumb may well carry
854
+ * `metadata: { request: { url: '/checkout?token=secret' } }`, and `filter` leaves that URL
855
+ * alone because the key `request` matches no filter.
856
+ *
857
+ * Safe to recurse without a seen-list because `filter` has already run: it replaces a
858
+ * circular reference with a string, so what arrives here is acyclic.
859
+ */
860
+ function filterUrlValues(value, filters) {
861
+ if (is('Array', value)) {
862
+ return value.map(function (entry) { return filterUrlValues(entry, filters); });
863
+ }
864
+ if (!is('Object', value)) {
865
+ return value;
866
+ }
867
+ var result = {};
868
+ var source = value;
869
+ // Own enumerable keys only, assigned with `defineProperty`: a plain `result[key] =` would
870
+ // reassign the prototype rather than create a property for a key named `__proto__`, and
871
+ // breadcrumb metadata is host-supplied.
872
+ Object.keys(source).forEach(function (key) {
873
+ var entry = source[key];
874
+ var filtered = URL_METADATA_KEYS.includes(key.toLowerCase()) && typeof entry === 'string'
875
+ ? filterUrl(entry, filters)
876
+ : filterUrlValues(entry, filters);
877
+ Object.defineProperty(result, key, {
878
+ value: filtered,
879
+ enumerable: true,
880
+ writable: true,
881
+ configurable: true
882
+ });
883
+ });
884
+ return result;
885
+ }
886
+ /**
887
+ * Applies `filters` to a breadcrumb trail.
888
+ *
889
+ * Metadata is filtered by key, exactly as `params` and `session` are, and any value under a
890
+ * URL-bearing key additionally has its query string filtered. Breadcrumb metadata is mostly
891
+ * generated by this library -- the XHR, fetch and navigation integrations all record a full
892
+ * URL -- so a query string lands there without the user ever choosing to put it there.
893
+ */
894
+ function filterBreadcrumbs(trail, filters) {
895
+ if (!is('Array', trail)) {
896
+ return [];
897
+ }
898
+ return trail.map(function (breadcrumb) {
899
+ // Leave a crumb that never carried metadata exactly as it is, so the payload shape does
900
+ // not change for it.
901
+ if (!is('Object', breadcrumb === null || breadcrumb === void 0 ? void 0 : breadcrumb.metadata)) {
902
+ return breadcrumb;
903
+ }
904
+ // `filter` runs first, so a key-matched value is already '[FILTERED]' by the time the
905
+ // URL pass sees it. Passing that through `filterUrl` is harmless: it holds no '?', so
906
+ // it is returned untouched.
907
+ var metadata = filterUrlValues(filter(breadcrumb.metadata, filters), filters);
908
+ return __assign(__assign({}, breadcrumb), { metadata: metadata });
909
+ });
910
+ }
911
+ exports.filterBreadcrumbs = filterBreadcrumbs;
831
912
  function formatCGIData(vars, prefix) {
832
913
  if (prefix === void 0) { prefix = ''; }
833
914
  var formattedVars = {};
@@ -1455,7 +1536,7 @@
1455
1536
  this.__notifier = {
1456
1537
  name: '@honeybadger-io/core',
1457
1538
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/core',
1458
- version: '6.16.5'
1539
+ version: '6.16.6'
1459
1540
  };
1460
1541
  this.config = __assign$1(__assign$1({}, defaults_1.CONFIG), opts);
1461
1542
  this.__initStore();
@@ -1816,7 +1897,7 @@
1816
1897
  notifier: this.__notifier,
1817
1898
  breadcrumbs: {
1818
1899
  enabled: !!this.config.breadcrumbsEnabled,
1819
- trail: notice.__breadcrumbs || []
1900
+ trail: (0, util_1$1.filterBreadcrumbs)(notice.__breadcrumbs || [], this.config.filters)
1820
1901
  },
1821
1902
  error: {
1822
1903
  class: notice.name,
@@ -2556,7 +2637,10 @@
2556
2637
  method = method.toUpperCase();
2557
2638
  }
2558
2639
  // localURLPathname cant be constructed for CF workers due to reliance on "document".
2559
- var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url : (0, util_1.localURLPathname)(url));
2640
+ // Drop the query string by hand there: nothing filters a breadcrumb message, and
2641
+ // localURLPathname would have removed it on the branch we cannot take, so leaving
2642
+ // the raw url in would report a secret the configured `filters` were meant to catch.
2643
+ var message = "".concat(method, " ").concat(typeof document === 'undefined' ? url.split('?')[0] : (0, util_1.localURLPathname)(url));
2560
2644
  var metadata = {
2561
2645
  type: 'fetch',
2562
2646
  method: method,
@@ -3255,7 +3339,7 @@
3255
3339
  var NOTIFIER = {
3256
3340
  name: '@honeybadger-io/js',
3257
3341
  url: 'https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js',
3258
- version: '6.16.5'
3342
+ version: '6.16.6'
3259
3343
  };
3260
3344
  var userAgent = function () {
3261
3345
  if (typeof navigator !== 'undefined') {