fix(browser): fingerprint cookies at the selected page URL (#763)
Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
stringValue,
|
||||
} from "./CdpCaptureValues.js";
|
||||
|
||||
/** Capture redacted storage metadata for one authorized origin. */
|
||||
/** Capture redacted storage metadata for an authorized page and its origin. */
|
||||
export const captureStorage = async (
|
||||
context: {
|
||||
readonly connection: CdpConnection;
|
||||
@@ -24,11 +24,12 @@ export const captureStorage = async (
|
||||
readonly input: InspectWebPageInput;
|
||||
readonly signal?: AbortSignal;
|
||||
},
|
||||
origin: string,
|
||||
pageUrl: string,
|
||||
limitations: string[],
|
||||
): Promise<{
|
||||
readonly value: WebPageInspection["storage"];
|
||||
}> => {
|
||||
const origin = new URL(pageUrl).origin;
|
||||
const quota = recordValue(
|
||||
await optionalCdpCommand(
|
||||
context,
|
||||
@@ -67,6 +68,7 @@ export const captureStorage = async (
|
||||
? await captureStorageFingerprints({
|
||||
context,
|
||||
origin,
|
||||
cookieUrl: pageUrl,
|
||||
local,
|
||||
session,
|
||||
indexedDbNames: indexed,
|
||||
|
||||
@@ -48,6 +48,7 @@ interface FingerprintRun {
|
||||
interface CaptureStorageFingerprintInput {
|
||||
readonly context: StorageFingerprintContext;
|
||||
readonly origin: string;
|
||||
readonly cookieUrl: string;
|
||||
readonly local: CapturedStorageItems;
|
||||
readonly session: CapturedStorageItems;
|
||||
readonly indexedDbNames: readonly string[];
|
||||
@@ -64,6 +65,7 @@ type StorageFingerprintCapture = {
|
||||
export const captureStorageFingerprints = async ({
|
||||
context,
|
||||
origin,
|
||||
cookieUrl,
|
||||
local,
|
||||
session,
|
||||
indexedDbNames,
|
||||
@@ -77,7 +79,7 @@ export const captureStorageFingerprints = async ({
|
||||
const run = { context, limitations, state };
|
||||
addStorageItems(state, "local_storage", local.items);
|
||||
addStorageItems(state, "session_storage", session.items);
|
||||
await addCookies(run, origin);
|
||||
await addCookies(run, cookieUrl);
|
||||
await addIndexedDb(run, origin, indexedDbNames);
|
||||
await addCaches(run, caches);
|
||||
state.items.sort((left, right) =>
|
||||
@@ -107,12 +109,15 @@ const addStorageItems = (
|
||||
|
||||
const addCookies = async (
|
||||
run: FingerprintRun,
|
||||
origin: string,
|
||||
pageUrl: string,
|
||||
): Promise<void> => {
|
||||
run.limitations.push(
|
||||
"Cookie fingerprints cover cookies applicable to the current main-frame URL, not every path on its origin.",
|
||||
);
|
||||
const raw = await optionalCdpCommand(
|
||||
run.context,
|
||||
"Network.getCookies",
|
||||
{ urls: [origin] },
|
||||
{ urls: [pageUrl] },
|
||||
run.limitations,
|
||||
);
|
||||
if (raw === undefined) {
|
||||
|
||||
@@ -144,7 +144,7 @@ const captureAuthorizedPage = async (
|
||||
);
|
||||
const storageCapture = await captureStorage(
|
||||
context,
|
||||
frames[0]?.origin ?? new URL(attachedUrl).origin,
|
||||
attachedUrl,
|
||||
limitations,
|
||||
);
|
||||
if (!input.include_storage_keys)
|
||||
|
||||
Reference in New Issue
Block a user