From 026e08a08f3795db90a02196e1164357a424e59e Mon Sep 17 00:00:00 2001 From: Anas Khurshid Date: Thu, 16 Feb 2023 10:40:17 +0100 Subject: [PATCH 1/2] add support to modify the logic for match --- src/index.ts | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/index.ts b/src/index.ts index e0f4956..225c189 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import deparam from 'deparam'; +import deparam from "deparam"; interface INetworkRequestResponse { body?: any; // POJO or a JSON stringify equalivant @@ -6,9 +6,9 @@ interface INetworkRequestResponse { headers: object; } -export default class LogrocketFuzzySearch { - public static setup(fields: string[]) { - const instance = new LogrocketFuzzySearch(fields); +export default class fuzzySearch { + public static setup(fields: string[], isSubStringMatch?: boolean) { + const instance = new fuzzySearch(fields, isSubStringMatch); return { requestSanitizer: instance.requestSanitizer.bind(instance), @@ -17,14 +17,16 @@ export default class LogrocketFuzzySearch { } public fields: string[] = []; + public isSubStringMatch?: boolean = false; - constructor(privateFields: string[]) { + constructor(privateFields: string[], isSubStringMatch?: boolean) { this.fields = privateFields; + this.isSubStringMatch = isSubStringMatch; } public requestSanitizer(request: INetworkRequestResponse): object | any { // avoid parsing GET requests as there will be no body - if (request.method === 'GET') { + if (request.method === "GET") { return request; } @@ -37,8 +39,10 @@ export default class LogrocketFuzzySearch { private _networkHandler(networkRequestReponse: INetworkRequestResponse) { const { body, headers } = networkRequestReponse; - const requestContentType: string = headers && (headers['Content-Type'] || ''); - const isUrlEncodedRequest: boolean = requestContentType.includes('form-urlencoded'); + const requestContentType: string = + headers && (headers["Content-Type"] || ""); + const isUrlEncodedRequest: boolean = + requestContentType.includes("form-urlencoded"); let parsedBody: object; try { @@ -72,16 +76,16 @@ export default class LogrocketFuzzySearch { where type/value keynames are generic and instead the value matching the type keyname should be masked. */ - const isTypeValuePair = key === 'type' && 'value' in body; + const isTypeValuePair = key === "type" && "value" in body; - if (typeof keyName === 'object') { + if (typeof keyName === "object") { if (!isTypeValuePair) { this._searchBody(keyName); } } if (isTypeValuePair) { - this._mask(body, body.type, 'value'); + this._mask(body, body.type, "value"); } else { this._mask(body, key); } @@ -96,14 +100,21 @@ export default class LogrocketFuzzySearch { const isSensitiveFieldName = this._match(searchKeyName); if (isSensitiveFieldName) { - body[maskKeyName] = '*'; + body[maskKeyName] = "*"; } } - private _match(keyName: string = ''): boolean { + private _match(keyName: string = ""): boolean { const { fields } = this; const normalizedKeyName = keyName.toLowerCase(); - return fields.some((field) => normalizedKeyName.indexOf(field.toLowerCase()) > -1); + if (this.isSubStringMatch) { + return fields.some( + (field) => normalizedKeyName.indexOf(field.toLowerCase()) > -1 + ); + } else { + const fieldsLowerCase = fields.map((x) => x.toLowerCase()); + return fieldsLowerCase.includes(normalizedKeyName); + } } } From 802bac5f6e3185d4db53174ebbf454c3fb907bad Mon Sep 17 00:00:00 2001 From: Anas Khurshid Date: Thu, 16 Feb 2023 10:59:02 +0100 Subject: [PATCH 2/2] changes --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 225c189..c0110e2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import deparam from "deparam"; +import deparam from 'deparam'; interface INetworkRequestResponse { body?: any; // POJO or a JSON stringify equalivant @@ -6,9 +6,9 @@ interface INetworkRequestResponse { headers: object; } -export default class fuzzySearch { +export default class LogrocketFuzzySearch { public static setup(fields: string[], isSubStringMatch?: boolean) { - const instance = new fuzzySearch(fields, isSubStringMatch); + const instance = new LogrocketFuzzySearch(fields, isSubStringMatch); return { requestSanitizer: instance.requestSanitizer.bind(instance), @@ -117,4 +117,4 @@ export default class fuzzySearch { return fieldsLowerCase.includes(normalizedKeyName); } } -} +} \ No newline at end of file