networkProxy: improve sanitizer, fix bodyreader class

This commit is contained in:
nick-delirium 2025-04-14 10:52:59 +02:00
parent dbb805189f
commit f0f78341e7
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
3 changed files with 15 additions and 10 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@openreplay/network-proxy", "name": "@openreplay/network-proxy",
"version": "1.1.0", "version": "1.1.1",
"description": "this library helps us to create proxy objects for fetch, XHR and beacons for proper request tracking.", "description": "this library helps us to create proxy objects for fetch, XHR and beacons for proper request tracking.",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.js", "module": "dist/index.js",

View file

@ -56,9 +56,10 @@ export class ResponseProxyHandler<T extends Response> implements ProxyHandler<T>
if (typeof this.resp.body.getReader !== 'function') { if (typeof this.resp.body.getReader !== 'function') {
return return
} }
const _getReader = this.resp.body.getReader const clonedResp = this.resp.clone();
const _getReader = clonedResp.body.getReader
// @ts-ignore // @ts-ignore
this.resp.body.getReader = () => { clonedResp.body.getReader = () => {
const reader = <ReturnType<typeof _getReader>>_getReader.apply(this.resp.body) const reader = <ReturnType<typeof _getReader>>_getReader.apply(this.resp.body)
// when readyState is already 4, // when readyState is already 4,

View file

@ -80,15 +80,19 @@ export function filterBody(body: any): string {
obscureSensitiveData(parsedBody); obscureSensitiveData(parsedBody);
return JSON.stringify(parsedBody); return JSON.stringify(parsedBody);
} else { } else {
const params = new URLSearchParams(body); try {
for (const key of params.keys()) { const params = new URLSearchParams(body);
if (sensitiveParams.has(key.toLowerCase())) { for (const key of params.keys()) {
const value = obscure(params.get(key)) if (sensitiveParams.has(key.toLowerCase())) {
params.set(key, value); const value = obscure(params.get(key))
params.set(key, value);
}
} }
return params.toString();
} catch (e) {
// not string or url query
return body;
} }
return params.toString();
} }
} }