From c9bc0c3a414d34af15c06ec90b105f62cd434c6d Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Sun, 7 Nov 2021 19:03:00 +0100 Subject: [PATCH] Basic email summary --- extended-request.ts | 15 +++---- memory.ts | 12 +++--- report-window/report-window.tsx | 70 ++++++++++++++++++++++++++++++++- request-cluster.ts | 12 +++++- util.ts | 7 ++++ 5 files changed, 98 insertions(+), 18 deletions(-) diff --git a/extended-request.ts b/extended-request.ts index 7a19a65..df4a0a8 100644 --- a/extended-request.ts +++ b/extended-request.ts @@ -17,6 +17,7 @@ export default class ExtendedRequest { public shorthost: string; public requestHeaders: Request["requestHeaders"]; public originalURL: string; + public origin: string; public initialized = false; public stolenData: StolenDataEntry[]; @@ -34,19 +35,13 @@ export default class ExtendedRequest { } else { url = (this.data as any).frameAncestors[0].url; } - this.originalURL = new URL(url).origin; - } - - getOriginalURL(): string { - if (!this.initialized) { - throw new Error("initialize first!!"); - } - return this.originalURL; + this.originalURL = url; + this.origin = new URL(url).origin; } isThirdParty() { const request_url = new URL(this.data.url); - const origin_url = new URL(this.getOriginalURL()); + const origin_url = new URL(this.originalURL); if (request_url.host.includes(origin_url.host)) { return false; } @@ -65,7 +60,7 @@ export default class ExtendedRequest { } exposesOrigin() { - const url = new URL(this.getOriginalURL()); + const url = new URL(this.origin); const host = url.host; const path = url.pathname; return ( diff --git a/memory.ts b/memory.ts index 29b8e73..f9bec5a 100644 --- a/memory.ts +++ b/memory.ts @@ -7,19 +7,19 @@ export default class Memory extends EventEmitter { origin_to_history = {} as Record>; async register(request: ExtendedRequest) { await request.init(); - console.log("registering request for", request.originalURL); + console.log("registering request for", request.origin); if (!request.isThirdParty()) { return; } - if (!this.origin_to_history[request.originalURL]) { - this.origin_to_history[request.originalURL] = {}; + if (!this.origin_to_history[request.origin]) { + this.origin_to_history[request.origin] = {}; } const shorthost = getshorthost(new URL(request.url).host); - if (!this.origin_to_history[request.originalURL][shorthost]) { + if (!this.origin_to_history[request.origin][shorthost]) { const cluster = new RequestCluster(shorthost); - this.origin_to_history[request.originalURL][shorthost] = cluster; + this.origin_to_history[request.origin][shorthost] = cluster; } - this.origin_to_history[request.originalURL][shorthost].add(request); + this.origin_to_history[request.origin][shorthost].add(request); this.emit("change"); } diff --git a/report-window/report-window.tsx b/report-window/report-window.tsx index bf92420..3eb45a2 100644 --- a/report-window/report-window.tsx +++ b/report-window/report-window.tsx @@ -1,8 +1,47 @@ -import React from "react"; +import React, { useState } from "react"; import ReactDOM from "react-dom"; import { getMemory } from "../memory"; +import { RequestCluster } from "../request-cluster"; +import { Classifications } from "../stolen-data-entry"; +import { getDate } from "../util"; + +const emailClassifications: Record = { + id: "sztucznie nadane mi ID", + history: "część mojej historii przeglądania", +}; + +type PopupState = "not_clicked" | "clicked_but_invalid"; + +function DomainSummary({ cluster }: { cluster: RequestCluster }) { + return ( +
  • + Właściciel domeny {cluster.id} otrzymał:{" "} +
      + {cluster + .getMarkedEntries() + .sort((entryA, entryB) => (entryA.value > entryB.value ? -1 : 1)) + .reduce((acc, entry, index, arr) => { + if (index === 0) { + return [entry]; + } + if (entry.value != arr[index - 1].value) { + acc.push(entry); + } + return acc; + }, []) + .map((entry) => ( +
    • + {emailClassifications[entry.classification]} w {entry.source} +  ({entry.name.trim()}) +
    • + ))} +
    +
  • + ); +} function Report() { + const [popupState, setPopupState] = useState("not_clicked"); const origin = new URL(document.location.toString()).searchParams.get( "origin" ); @@ -64,6 +103,35 @@ function Report() { ))} + + +
    +

    + Dzień dobry, w dniu {getDate()} odwiedziłem stronę{" "} + {marked_entries[0].request.originalURL}. Strona ta wysłała moje dane + osobowe do podmiotów trzecich - bez mojej zgody.{" "} +

    +
      + {Object.values(clusters) + .filter((cluster) => cluster.hasMarks()) + .map((cluster) => ( + + ))} +
    + {popupState === "not_clicked" ? ( +

    + Dane te zostały wysłane przez Państwa stronę zanim zdążyłem w ogóle + przeczytać treść wyskakującego okienka ze zgodami. +

    + ) : null} +
    ); } diff --git a/request-cluster.ts b/request-cluster.ts index d0ba14a..e19f042 100644 --- a/request-cluster.ts +++ b/request-cluster.ts @@ -2,7 +2,7 @@ import { EventEmitter } from "events"; import ExtendedRequest from "./extended-request"; import { MergedStolenDataEntry, StolenDataEntry } from "./stolen-data-entry"; -import { allSubhosts, unique } from "./util"; +import { allSubhosts, reduceConcat, unique } from "./util"; export class RequestCluster extends EventEmitter { public requests: ExtendedRequest[] = []; @@ -93,4 +93,14 @@ export class RequestCluster extends EventEmitter { .reduce((a, b) => a.concat(b), []) ); } + + hasMarks() { + return this.requests.some((request) => request.hasMark()); + } + + getMarkedEntries() { + return this.requests + .map((request) => request.getMarkedEntries()) + .reduce(reduceConcat, []); + } } diff --git a/util.ts b/util.ts index 2c31532..2b65cbf 100644 --- a/util.ts +++ b/util.ts @@ -99,3 +99,10 @@ export function allSubhosts(host: string) { export function reduceConcat(a: T[], b: T[]): T[] { return a.concat(b); } + +export function getDate() { + const d = new Date(); + return `${d.getFullYear()}-${(d.getMonth() + 1) + .toString() + .padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")}`; +}