Add automatic bas64 translation. Now I'll experiment with slicing the

objects into separate string entries
This commit is contained in:
Kuba Orlik 2021-11-22 15:08:29 +01:00
parent 5768ac93d9
commit c9f3876cf4
3 changed files with 62 additions and 32 deletions

View File

@ -1,11 +1,7 @@
import React from "react"; import React from "react";
import { getMemory } from "../memory"; import { getMemory } from "../memory";
import { RequestCluster } from "../request-cluster"; import { RequestCluster } from "../request-cluster";
import { import { MergedStolenDataEntry, Sources } from "../stolen-data-entry";
MergedStolenDataEntry,
Sources,
StolenDataEntry,
} from "../stolen-data-entry";
import { hyphenate, useEmitter } from "../util"; import { hyphenate, useEmitter } from "../util";
@ -19,33 +15,42 @@ function StolenDataValueTable({
prefixKey: string; prefixKey: string;
}) { }) {
return ( return (
<table> <div>
<tbody> {entry.getDecodingsApplied().includes("base64") ? (
{Object.keys(entry.getParsedValues(prefixKey)[0]).map((key) => { <span style={{ color: "white", backgroundColor: "green" }}>
const subkey = `${prefixKey}.${key}`; "base64"
return ( </span>
<tr key={`${prefixKey}.${key}`}> ) : (
<th ""
onClick={(e) => { )}
entry.toggleMark(subkey); <table>
e.stopPropagation(); <tbody>
}} {Object.keys(entry.getParsedValues(prefixKey)[0]).map((key) => {
style={{ const subkey = `${prefixKey}.${key}`;
border: entry.hasMark(subkey) return (
? "2px solid red" <tr key={`${prefixKey}.${key}`}>
: "2px solid transparent", <th
}} onClick={(e) => {
> entry.toggleMark(subkey);
{hyphenate(key)} e.stopPropagation();
</th> }}
<td> style={{
<StolenDataValue entry={entry} prefixKey={subkey} /> border: entry.hasMark(subkey)
</td> ? "2px solid red"
</tr> : "2px solid transparent",
); }}
})} >
</tbody> {hyphenate(key)}
</table> </th>
<td>
<StolenDataValue entry={entry} prefixKey={subkey} />
</td>
</tr>
);
})}
</tbody>
</table>
</div>
); );
} }

View File

@ -2,8 +2,10 @@ import { TCModel } from "@iabtcf/core";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import ExtendedRequest, { HAREntry } from "./extended-request"; import ExtendedRequest, { HAREntry } from "./extended-request";
import Mark from "./mark"; import Mark from "./mark";
import { import {
getshorthost, getshorthost,
isBase64JSON,
isJSONObject, isJSONObject,
isURL, isURL,
parseToObject, parseToObject,
@ -29,12 +31,15 @@ const id = (function* id() {
} }
})(); })();
export type DecodingSchema = "base64";
export class StolenDataEntry extends EventEmitter { export class StolenDataEntry extends EventEmitter {
public isIAB = false; public isIAB = false;
public iab: TCModel | null = null; public iab: TCModel | null = null;
public id: number; public id: number;
public marks: Mark[] = []; public marks: Mark[] = [];
public classification: keyof typeof Classifications; public classification: keyof typeof Classifications;
public decoding_applied: DecodingSchema = null;
constructor( constructor(
public request: ExtendedRequest, public request: ExtendedRequest,
@ -50,6 +55,10 @@ export class StolenDataEntry extends EventEmitter {
super(); super();
this.id = id.next().value as number; this.id = id.next().value as number;
this.classification = this.classify(); this.classification = this.classify();
if (isBase64JSON(value)) {
this.value = atob(value);
this.decoding_applied = "base64";
}
} }
getPriority() { getPriority() {
@ -291,4 +300,8 @@ export class MergedStolenDataEntry extends EventEmitter {
toggleMark(key: string): void { toggleMark(key: string): void {
this.entries.forEach((entry) => entry.toggleMark(key)); this.entries.forEach((entry) => entry.toggleMark(key));
} }
getDecodingsApplied(): DecodingSchema[] {
return unique(this.entries.map((entry) => entry.decoding_applied));
}
} }

12
util.ts
View File

@ -171,3 +171,15 @@ export function isSameURL(url1: string, url2: string): boolean {
url2 = url2.replace(/^https?:\/\//, "").replace(/\/$/, ""); url2 = url2.replace(/^https?:\/\//, "").replace(/\/$/, "");
return url1 === url2; return url1 === url2;
} }
export function isBase64(s: string): boolean {
try {
atob(s);
return true;
} catch (e) {}
return false;
}
export function isBase64JSON(s: unknown): s is string {
return typeof s === "string" && isBase64(s) && isJSONObject(atob(s));
}