From 577e9ee0a33f580674c422ff07c130a7ed72649d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 30 Oct 2020 17:45:52 +0000 Subject: [PATCH 1/2] Fix method bindings --- src/CountlyAnalytics.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CountlyAnalytics.ts b/src/CountlyAnalytics.ts index 600a9be1bf..476508ce8c 100644 --- a/src/CountlyAnalytics.ts +++ b/src/CountlyAnalytics.ts @@ -666,11 +666,11 @@ export default class CountlyAnalytics { return window.innerWidth > window.innerHeight ? Orientation.Landscape : Orientation.Portrait; }; - private reportOrientation() { + private reportOrientation = () => { this.track("[CLY]_orientation", { mode: this.getOrientation(), }); - } + }; private startTime() { if (!this.trackTime) { @@ -754,7 +754,7 @@ export default class CountlyAnalytics { } } - private endSession() { + private endSession = () => { if (this.sessionStarted) { window.removeEventListener("resize", this.reportOrientation) @@ -765,7 +765,7 @@ export default class CountlyAnalytics { }); } this.sessionStarted = false; - } + }; private onVisibilityChange = () => { if (document.hidden) { From 7b625dbe0dfb76fa19c3f2ec20fb48875159067e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 30 Oct 2020 18:04:19 +0000 Subject: [PATCH 2/2] sanitize error reports --- src/CountlyAnalytics.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/CountlyAnalytics.ts b/src/CountlyAnalytics.ts index 476508ce8c..36d4b5ae8c 100644 --- a/src/CountlyAnalytics.ts +++ b/src/CountlyAnalytics.ts @@ -343,6 +343,18 @@ const getRoomStats = (roomId: string) => { } } +// async wrapper for regex-powered String.prototype.replace +const strReplaceAsync = async (str: string, regex: RegExp, fn: (...args: string[]) => Promise) => { + const promises: Promise[] = []; + // dry-run to calculate the replace values + str.replace(regex, (...args: string[]) => { + promises.push(fn(...args)); + return ""; + }); + const values = await Promise.all(promises); + return str.replace(regex, () => values.shift()); +}; + export default class CountlyAnalytics { private baseUrl: URL = null; private appKey: string = null; @@ -495,7 +507,7 @@ export default class CountlyAnalytics { return this.lastMsTs; } - public recordError(err: Error | string, fatal = false) { + public async recordError(err: Error | string, fatal = false) { if (this.disabled || this.anonymous) return; let error = ""; @@ -523,6 +535,11 @@ export default class CountlyAnalytics { error = err + ""; } + // sanitize the error from identifiers + error = await strReplaceAsync(error, /([!@+#]).+?:[\w:.]+/g, async (substring: string, glyph: string) => { + return glyph + await hashHex(substring.substring(1)); + }); + const metrics = this.getMetrics(); const ob: ICrash = { _resolution: metrics?._resolution,