Skip to content

Commit 08146f3

Browse files
Prevent debugging serialization to cause page to break (#574)
* Prevent debugging serialization to cause page to break * Change to <> to assist debugging and also truncate large serializations before sending
1 parent e334bea commit 08146f3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/utils.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,27 @@ export function hasTaintedMethod (scope, shouldStackCheck = false) {
398398
return false
399399
}
400400

401+
/**
402+
* @param {*[]} argsArray
403+
* @returns {string}
404+
*/
405+
function debugSerialize (argsArray) {
406+
const maxSerializedSize = 1000
407+
const serializedArgs = argsArray.map((arg) => {
408+
try {
409+
const serializableOut = JSON.stringify(arg)
410+
if (serializableOut.length > maxSerializedSize) {
411+
return `<truncated, length: ${serializableOut.length}, value: ${serializableOut.substring(0, maxSerializedSize)}...>`
412+
}
413+
return serializableOut
414+
} catch (e) {
415+
// Sometimes this happens when we can't serialize an object to string but we still wish to log it and make other args readable
416+
return '<unserializable>'
417+
}
418+
})
419+
return JSON.stringify(serializedArgs)
420+
}
421+
401422
/**
402423
* @template {object} P
403424
* @typedef {object} ProxyObject<P>
@@ -440,7 +461,7 @@ export class DDGProxy {
440461
kind: this.property,
441462
documentUrl: document.location.href,
442463
stack: getStack(),
443-
args: JSON.stringify(args[2])
464+
args: debugSerialize(args[2])
444465
})
445466
}
446467
// The normal return value

0 commit comments

Comments
 (0)