From 3ae5da1888fcc58a6a4e54c9437fa55a8d3af460 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Wed, 6 Oct 2021 17:22:33 +0200 Subject: [PATCH] Add headers data. Detect if a cookie is IAB consent --- extended-request.ts | 27 +++++++++++++++++++++++++++ package-lock.json | 38 +++++++++++--------------------------- package.json | 2 +- request-cluster.ts | 15 +++++++++++++-- sidebar.tsx | 5 ++++- 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/extended-request.ts b/extended-request.ts index b70ff64..e089dd4 100644 --- a/extended-request.ts +++ b/extended-request.ts @@ -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; diff --git a/package-lock.json b/package-lock.json index aa7f130..358e097 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 87a8032..22f09ce 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/request-cluster.ts b/request-cluster.ts index 63e1ca7..50623ba 100644 --- a/request-cluster.ts +++ b/request-cluster.ts @@ -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; diff --git a/sidebar.tsx b/sidebar.tsx index 6b62156..763e184 100644 --- a/sidebar.tsx +++ b/sidebar.tsx @@ -61,6 +61,7 @@ const StolenDataRow = ({ cookie: "🍪", pathname: "🛣", queryparams: "🅿", + header: "H", }; return (
@@ -76,7 +77,9 @@ const StolenDataRow = ({ {entry.name} {icons[entry.source]} - {entry.value} + + {entry.value} {entry.isIAB ? "!!!!! IAB" : ""} + ))}