Add headers data. Detect if a cookie is IAB consent

This commit is contained in:
Kuba Orlik 2021-10-06 17:22:33 +02:00
parent 43e0c6c7f8
commit 3ae5da1888
5 changed files with 56 additions and 31 deletions

View File

@ -1,6 +1,16 @@
import { StolenDataEntry } from "./request-cluster";
import { getshorthost, parseCookie, Request } from "./util";
const whitelisted_cookies = [
/^Accept.*$/,
/^Host$/,
/^Connection$/,
/^Sec-Fetch-.*$/,
/^Content-Type$/,
/^Cookie$/, // we're extracting it in getCookie separately anyway
/^User-Agent$/,
];
export default class ExtendedRequest {
public tabId: number;
public url: string;
@ -68,6 +78,7 @@ export default class ExtendedRequest {
...this.getPathParams(),
...this.getCookieData(),
...this.getQueryParams(),
...this.getHeadersData(),
];
}
@ -120,6 +131,22 @@ export default class ExtendedRequest {
});
}
getHeadersData(): StolenDataEntry[] {
return this.data.requestHeaders
.filter((header) => {
for (const regex of whitelisted_cookies) {
if (regex.test(header.name)) {
return false;
}
}
return true;
})
.map(
(header) =>
new StolenDataEntry(this, "header", header.name, header.value)
);
}
constructor(public data: Request) {
this.tabId = data.tabId;
this.url = data.url;

38
package-lock.json generated
View File

@ -9,7 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"consent-string": "^1.5.2",
"@iabtcf/core": "^1.3.1",
"esbuild": "^0.13.3",
"events": "^3.3.0",
"react": "^17.0.2",
@ -22,6 +22,11 @@
"web-ext-types": "^3.2.1"
}
},
"node_modules/@iabtcf/core": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@iabtcf/core/-/core-1.3.1.tgz",
"integrity": "sha512-t3ZvQRXLhoze2cx15mZMt5wUVhj+q3CoXtSSdZuVbrEbnyzFJ6uW0fxr5dmH1vRud7QYGRXqjhCBL7Yr46VRpA=="
},
"node_modules/@types/events": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz",
@ -60,19 +65,6 @@
"integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==",
"dev": true
},
"node_modules/base-64": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz",
"integrity": "sha1-eAqZyE59YAJgNhURxId2E78k9rs="
},
"node_modules/consent-string": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/consent-string/-/consent-string-1.5.2.tgz",
"integrity": "sha512-xzfHnFzHQSupiamNY93UGn8FggPajHYExI45pzadhVpXVaj3ztnhnA7lYjKXl09pKRQKCT4hvjytt+2eoH7Jaw==",
"dependencies": {
"base-64": "^0.1.0"
}
},
"node_modules/csstype": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.9.tgz",
@ -377,6 +369,11 @@
}
},
"dependencies": {
"@iabtcf/core": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@iabtcf/core/-/core-1.3.1.tgz",
"integrity": "sha512-t3ZvQRXLhoze2cx15mZMt5wUVhj+q3CoXtSSdZuVbrEbnyzFJ6uW0fxr5dmH1vRud7QYGRXqjhCBL7Yr46VRpA=="
},
"@types/events": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz",
@ -415,19 +412,6 @@
"integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==",
"dev": true
},
"base-64": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz",
"integrity": "sha1-eAqZyE59YAJgNhURxId2E78k9rs="
},
"consent-string": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/consent-string/-/consent-string-1.5.2.tgz",
"integrity": "sha512-xzfHnFzHQSupiamNY93UGn8FggPajHYExI45pzadhVpXVaj3ztnhnA7lYjKXl09pKRQKCT4hvjytt+2eoH7Jaw==",
"requires": {
"base-64": "^0.1.0"
}
},
"csstype": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.9.tgz",

View File

@ -14,7 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"consent-string": "^1.5.2",
"@iabtcf/core": "^1.3.1",
"esbuild": "^0.13.3",
"events": "^3.3.0",
"react": "^17.0.2",

View File

@ -1,15 +1,26 @@
import { EventEmitter } from "events";
import ExtendedRequest from "./extended-request";
export type Sources = "cookie" | "pathname" | "queryparams";
export type Sources = "cookie" | "pathname" | "queryparams" | "header";
import { TCString, TCModel } from "@iabtcf/core";
export class StolenDataEntry {
public isIAB = false;
public iab: TCModel | null = null;
constructor(
public request: ExtendedRequest,
public source: Sources,
public name: string,
public value: string
) {}
) {
try {
this.iab = TCString.decode(value);
console.log(this.iab);
this.isIAB = true;
} catch (e) {}
}
getPriority() {
let priority = 0;

View File

@ -61,6 +61,7 @@ const StolenDataRow = ({
cookie: "🍪",
pathname: "🛣",
queryparams: "🅿",
header: "H",
};
return (
<div>
@ -76,7 +77,9 @@ const StolenDataRow = ({
{entry.name}
</th>
<td>{icons[entry.source]}</td>
<td style={{ wordWrap: "anywhere" as any }}>{entry.value}</td>
<td style={{ wordWrap: "anywhere" as any }}>
{entry.value} {entry.isIAB ? "!!!!! IAB" : ""}
</td>
</tr>
))}
</tbody>