networkProxy: improve sanitizer, fix bodyreader class
This commit is contained in:
parent
dbb805189f
commit
f0f78341e7
3 changed files with 15 additions and 10 deletions
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue