From 93f3d568ae911f58ad5fb32537d026e9ab107ca7 Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Fri, 22 Apr 2022 18:48:16 +0200 Subject: [PATCH 1/3] Stringify API call arguments. --- collectors/APICallCollector.js | 14 +++++++++++++- tests/collectors/APICallCollector.test.js | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/collectors/APICallCollector.js b/collectors/APICallCollector.js index 1e7e00de..35296cd1 100644 --- a/collectors/APICallCollector.js +++ b/collectors/APICallCollector.js @@ -81,10 +81,22 @@ class APICallCollector extends BaseCollector { sourceStats.set(breakpoint.description, count + 1); if (breakpoint.saveArguments) { + const stringifiedArguments = breakpoint.arguments.map(arg => { + let stringifiedArg = String(arg); + + try { + stringifiedArg = JSON.stringify(arg); + } catch (e) { + // probably a circular reference? + } + + return stringifiedArg; + }); + this._calls.push({ source: breakpoint.source, description: breakpoint.description, - arguments: breakpoint.arguments + arguments: stringifiedArguments }); } } diff --git a/tests/collectors/APICallCollector.test.js b/tests/collectors/APICallCollector.test.js index b194f03c..d9632c68 100644 --- a/tests/collectors/APICallCollector.test.js +++ b/tests/collectors/APICallCollector.test.js @@ -93,7 +93,10 @@ async function main() { payload: JSON.stringify({ description: 'Document.cookie setter', stack: '(https://example.com/different.js:1:23)\n(https://example.com/different.js:2:23)', - args: ['uuid=123'] + args: [ + 'uuid=123', + {key: 'key', value: 'value'} + ] }) }); @@ -109,7 +112,8 @@ async function main() { source: 'https://example.com/different.js', description: 'Document.cookie setter', arguments: [ - 'uuid=123' + '"uuid=123"', + '{"key":"key","value":"value"}' ] } ] From b78187cf86c5b8d0c67e71e9566cebf3faae731a Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Thu, 3 Nov 2022 11:48:47 +0100 Subject: [PATCH 2/3] Serialize arguments when the binding is called not when it's received. --- collectors/APICallCollector.js | 14 +------------- collectors/APICalls/TrackerTracker.js | 8 +++++++- tests/collectors/APICallCollector.test.js | 8 ++++---- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/collectors/APICallCollector.js b/collectors/APICallCollector.js index 35296cd1..1e7e00de 100644 --- a/collectors/APICallCollector.js +++ b/collectors/APICallCollector.js @@ -81,22 +81,10 @@ class APICallCollector extends BaseCollector { sourceStats.set(breakpoint.description, count + 1); if (breakpoint.saveArguments) { - const stringifiedArguments = breakpoint.arguments.map(arg => { - let stringifiedArg = String(arg); - - try { - stringifiedArg = JSON.stringify(arg); - } catch (e) { - // probably a circular reference? - } - - return stringifiedArg; - }); - this._calls.push({ source: breakpoint.source, description: breakpoint.description, - arguments: stringifiedArguments + arguments: breakpoint.arguments }); } } diff --git a/collectors/APICalls/TrackerTracker.js b/collectors/APICalls/TrackerTracker.js index 59509717..b07e2dae 100644 --- a/collectors/APICalls/TrackerTracker.js +++ b/collectors/APICalls/TrackerTracker.js @@ -84,7 +84,13 @@ class TrackerTracker { // only save arguments if requested for given breakpoint if (saveArguments) { conditionScript += ` - data.args = Array.from(arguments).map(a => a.toString()); + data.args = Array.from(arguments).map(a => { + try { + return JSON.stringify(a); + } catch (e) { + return a.toString(); + } + }); `; } diff --git a/tests/collectors/APICallCollector.test.js b/tests/collectors/APICallCollector.test.js index d9632c68..393c6eca 100644 --- a/tests/collectors/APICallCollector.test.js +++ b/tests/collectors/APICallCollector.test.js @@ -94,8 +94,8 @@ async function main() { description: 'Document.cookie setter', stack: '(https://example.com/different.js:1:23)\n(https://example.com/different.js:2:23)', args: [ - 'uuid=123', - {key: 'key', value: 'value'} + "\"uuid=123\"", + "{\"key\":\"key\",\"value\":\"value\"}" ] }) }); @@ -112,8 +112,8 @@ async function main() { source: 'https://example.com/different.js', description: 'Document.cookie setter', arguments: [ - '"uuid=123"', - '{"key":"key","value":"value"}' + "\"uuid=123\"", + "{\"key\":\"key\",\"value\":\"value\"}" ] } ] From 9c6012bc996e4cac21506da4dccecd699de08ca5 Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Thu, 3 Nov 2022 11:55:25 +0100 Subject: [PATCH 3/3] Parse stringified artuments back before storing. --- collectors/APICallCollector.js | 8 +++++++- tests/collectors/APICallCollector.test.js | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/collectors/APICallCollector.js b/collectors/APICallCollector.js index 1e7e00de..31546a1e 100644 --- a/collectors/APICallCollector.js +++ b/collectors/APICallCollector.js @@ -84,7 +84,13 @@ class APICallCollector extends BaseCollector { this._calls.push({ source: breakpoint.source, description: breakpoint.description, - arguments: breakpoint.arguments + arguments: breakpoint.arguments.map(arg => { + try { + return JSON.parse(arg); + } catch (e) { + return arg; + } + }) }); } } diff --git a/tests/collectors/APICallCollector.test.js b/tests/collectors/APICallCollector.test.js index 393c6eca..37453f51 100644 --- a/tests/collectors/APICallCollector.test.js +++ b/tests/collectors/APICallCollector.test.js @@ -112,8 +112,11 @@ async function main() { source: 'https://example.com/different.js', description: 'Document.cookie setter', arguments: [ - "\"uuid=123\"", - "{\"key\":\"key\",\"value\":\"value\"}" + "uuid=123", + { + key: "key", + value: "value" + } ] } ]