Basic email summary

This commit is contained in:
Kuba Orlik 2021-11-07 19:03:00 +01:00
parent e8075b384d
commit c9bc0c3a41
5 changed files with 98 additions and 18 deletions

View File

@ -17,6 +17,7 @@ export default class ExtendedRequest {
public shorthost: string; public shorthost: string;
public requestHeaders: Request["requestHeaders"]; public requestHeaders: Request["requestHeaders"];
public originalURL: string; public originalURL: string;
public origin: string;
public initialized = false; public initialized = false;
public stolenData: StolenDataEntry[]; public stolenData: StolenDataEntry[];
@ -34,19 +35,13 @@ export default class ExtendedRequest {
} else { } else {
url = (this.data as any).frameAncestors[0].url; url = (this.data as any).frameAncestors[0].url;
} }
this.originalURL = new URL(url).origin; this.originalURL = url;
} this.origin = new URL(url).origin;
getOriginalURL(): string {
if (!this.initialized) {
throw new Error("initialize first!!");
}
return this.originalURL;
} }
isThirdParty() { isThirdParty() {
const request_url = new URL(this.data.url); 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)) { if (request_url.host.includes(origin_url.host)) {
return false; return false;
} }
@ -65,7 +60,7 @@ export default class ExtendedRequest {
} }
exposesOrigin() { exposesOrigin() {
const url = new URL(this.getOriginalURL()); const url = new URL(this.origin);
const host = url.host; const host = url.host;
const path = url.pathname; const path = url.pathname;
return ( return (

View File

@ -7,19 +7,19 @@ export default class Memory extends EventEmitter {
origin_to_history = {} as Record<string, Record<string, RequestCluster>>; origin_to_history = {} as Record<string, Record<string, RequestCluster>>;
async register(request: ExtendedRequest) { async register(request: ExtendedRequest) {
await request.init(); await request.init();
console.log("registering request for", request.originalURL); console.log("registering request for", request.origin);
if (!request.isThirdParty()) { if (!request.isThirdParty()) {
return; return;
} }
if (!this.origin_to_history[request.originalURL]) { if (!this.origin_to_history[request.origin]) {
this.origin_to_history[request.originalURL] = {}; this.origin_to_history[request.origin] = {};
} }
const shorthost = getshorthost(new URL(request.url).host); 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); 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"); this.emit("change");
} }

View File

@ -1,8 +1,47 @@
import React from "react"; import React, { useState } from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { getMemory } from "../memory"; import { getMemory } from "../memory";
import { RequestCluster } from "../request-cluster";
import { Classifications } from "../stolen-data-entry";
import { getDate } from "../util";
const emailClassifications: Record<keyof typeof Classifications, string> = {
id: "sztucznie nadane mi ID",
history: "część mojej historii przeglądania",
};
type PopupState = "not_clicked" | "clicked_but_invalid";
function DomainSummary({ cluster }: { cluster: RequestCluster }) {
return (
<li>
Właściciel domeny {cluster.id} otrzymał:{" "}
<ul>
{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) => (
<li>
{emailClassifications[entry.classification]} w {entry.source}
&nbsp;(<code>{entry.name.trim()}</code>)
</li>
))}
</ul>
</li>
);
}
function Report() { function Report() {
const [popupState, setPopupState] = useState<PopupState>("not_clicked");
const origin = new URL(document.location.toString()).searchParams.get( const origin = new URL(document.location.toString()).searchParams.get(
"origin" "origin"
); );
@ -64,6 +103,35 @@ function Report() {
))} ))}
</tbody> </tbody>
</table> </table>
<label htmlFor="popupState">Status okienka o rodo:</label>
<select
id="popupState"
value={popupState}
onChange={(e) => setPopupState(e.target.value as PopupState)}
>
<option value="not_clicked">Nic nie kliknięte</option>
<option value="clicked_but_invalid">Kliknięte, ale nieważne</option>
</select>
<div>
<p>
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.{" "}
</p>
<ul>
{Object.values(clusters)
.filter((cluster) => cluster.hasMarks())
.map((cluster) => (
<DomainSummary cluster={cluster} />
))}
</ul>
{popupState === "not_clicked" ? (
<p>
Dane te zostały wysłane przez Państwa stronę zanim zdążyłem w ogóle
przeczytać treść wyskakującego okienka ze zgodami.
</p>
) : null}
</div>
</div> </div>
); );
} }

View File

@ -2,7 +2,7 @@ import { EventEmitter } from "events";
import ExtendedRequest from "./extended-request"; import ExtendedRequest from "./extended-request";
import { MergedStolenDataEntry, StolenDataEntry } from "./stolen-data-entry"; import { MergedStolenDataEntry, StolenDataEntry } from "./stolen-data-entry";
import { allSubhosts, unique } from "./util"; import { allSubhosts, reduceConcat, unique } from "./util";
export class RequestCluster extends EventEmitter { export class RequestCluster extends EventEmitter {
public requests: ExtendedRequest[] = []; public requests: ExtendedRequest[] = [];
@ -93,4 +93,14 @@ export class RequestCluster extends EventEmitter {
.reduce((a, b) => a.concat(b), []) .reduce((a, b) => a.concat(b), [])
); );
} }
hasMarks() {
return this.requests.some((request) => request.hasMark());
}
getMarkedEntries() {
return this.requests
.map((request) => request.getMarkedEntries())
.reduce(reduceConcat, []);
}
} }

View File

@ -99,3 +99,10 @@ export function allSubhosts(host: string) {
export function reduceConcat<T>(a: T[], b: T[]): T[] { export function reduceConcat<T>(a: T[], b: T[]): T[] {
return a.concat(b); 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")}`;
}