diff --git a/package-lock.json b/package-lock.json index a5a9a36f..15813d00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tlsn-extension", - "version": "0.1.0.700", + "version": "0.1.0.702", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tlsn-extension", - "version": "0.1.0.700", + "version": "0.1.0.702", "license": "MIT", "dependencies": { "@extism/extism": "^1.0.2", @@ -19,6 +19,7 @@ "copy-to-clipboard": "^3.3.3", "fast-deep-equal": "^3.1.3", "fuse.js": "^6.6.2", + "http-string-parser": "^0.0.6", "level": "^8.0.0", "minimatch": "^9.0.4", "node-cache": "^5.1.2", @@ -41,6 +42,7 @@ "@babel/preset-react": "^7.18.6", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10", "@types/chrome": "^0.0.202", + "@types/http-string-parser": "^0.0.33", "@types/node": "^20.4.10", "@types/react": "^18.0.26", "@types/react-dom": "^18.0.10", @@ -3723,6 +3725,12 @@ "@types/node": "*" } }, + "node_modules/@types/http-string-parser": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@types/http-string-parser/-/http-string-parser-0.0.33.tgz", + "integrity": "sha512-8F4z30z3/mcKcqjdAhCKOEcTG03Db3XMUkCIWaX+sYeNHypops+HQ3ATybD7vyvZAYtBQcEGboIC2Shratz5UQ==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -8363,6 +8371,11 @@ } } }, + "node_modules/http-string-parser": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/http-string-parser/-/http-string-parser-0.0.6.tgz", + "integrity": "sha512-sngOeBkIL32kum4Z+FulU+3Ve41B3js1IKfel0WAhwLqDJiUPC1UTqFRBr2/IDw9dbks6B4xSIYgPiJU7ivxww==" + }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -16560,6 +16573,12 @@ "@types/node": "*" } }, + "@types/http-string-parser": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@types/http-string-parser/-/http-string-parser-0.0.33.tgz", + "integrity": "sha512-8F4z30z3/mcKcqjdAhCKOEcTG03Db3XMUkCIWaX+sYeNHypops+HQ3ATybD7vyvZAYtBQcEGboIC2Shratz5UQ==", + "dev": true + }, "@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -19979,6 +19998,11 @@ "micromatch": "^4.0.2" } }, + "http-string-parser": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/http-string-parser/-/http-string-parser-0.0.6.tgz", + "integrity": "sha512-sngOeBkIL32kum4Z+FulU+3Ve41B3js1IKfel0WAhwLqDJiUPC1UTqFRBr2/IDw9dbks6B4xSIYgPiJU7ivxww==" + }, "human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", diff --git a/package.json b/package.json index 30095085..7aded0f6 100755 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "copy-to-clipboard": "^3.3.3", "fast-deep-equal": "^3.1.3", "fuse.js": "^6.6.2", + "http-string-parser": "^0.0.6", "level": "^8.0.0", "minimatch": "^9.0.4", "node-cache": "^5.1.2", @@ -48,6 +49,7 @@ "@babel/preset-react": "^7.18.6", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10", "@types/chrome": "^0.0.202", + "@types/http-string-parser": "^0.0.33", "@types/node": "^20.4.10", "@types/react": "^18.0.26", "@types/react-dom": "^18.0.10", diff --git a/src/entries/Background/rpc.ts b/src/entries/Background/rpc.ts index 8672078d..7fab8763 100644 --- a/src/entries/Background/rpc.ts +++ b/src/entries/Background/rpc.ts @@ -1,6 +1,7 @@ import browser from 'webextension-polyfill'; import { clearCache, getCacheByTabId } from './cache'; import { addRequestHistory, setRequests } from '../../reducers/history'; +import { parseResponse } from "http-string-parser"; import { addNotaryRequest, addNotaryRequestProofs, @@ -521,29 +522,20 @@ async function runPluginProver(request: BackgroundAction, now = Date.now()) { } if (getSecretResponse) { - const body = data.transcript.recv.split('\r\n').reduce( - (state: { headerEnd: boolean; body: string[] }, line: string) => { - if (state.headerEnd) { - state.body.push(line); - } else if (!line) { - state.headerEnd = true; - } + const res = parseResponse(data.transcript.recv); + const body = res.body.split('\r\n') - return state; - }, - { headerEnd: false, body: [] }, - ).body; + let bodyString = "" - if (body.length == 1) { - secretResps = await getSecretResponseFn(body[0]); - } else { - secretResps = await getSecretResponseFn( - body.filter((txt: string) => { - const json = safeParseJSON(txt); - return typeof json === 'object'; - })[0], - ); - } + // Each second line is the response body chunk + // Each line before second line is the size of the chunk + body.forEach((line, i) => { + if ((i + 1) % 2 === 0) { + bodyString += line + } + }) + + secretResps = await getSecretResponseFn(bodyString); } const commit = {