Files
rea/src/domain/webNetworkCapture.ts
T
YsopwnableGitHubKaoru0822github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2bf3663f65 feat(browser): inspect historical web network captures (#992)
* feat(browser): inspect retained HAR and mitmproxy capture evidence

Add independent offline format adapters, inline CLI/MCP evidence, bounded
owned decoder processes, and real producer verification.

Refs #882

Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)

* fix(browser): preserve capture boundaries during cancellation and decoding

Honor cancellation during owned-command cleanup, retain opaque HAR
extension content, and clean verifier resources on every failure path.

Refs #882

Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)

* fix(browser): exclude sensitive capture fields across representations

Normalize known native transport URLs for both bytes and strings, including backups. Exclude explicitly sensitive text fields with null so redaction markers cannot reintroduce declared literals. Cover both provider identities in catalog conformance.

Refs #882

Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)

* fix(browser): exclude sensitive capture identities and bound diagnostics

* fix(browser): validate excluded HAR subtrees before projection

* fix(browser): distinguish capture input limits from decoder failures

* fix(browser): preserve decoder failure categories

* fix(browser): validate excluded native credential values

* test(browser): report capture verifier assertions directly

* fix(browser): classify native representation failures precisely

* fix(browser): exclude URL userinfo after header whitespace

* fix(browser): preserve capture evidence and failure boundaries

* fix(browser): exclude sensitive literals from capture limitations

* test(browser): check limitation values without JSON syntax

* fix(browser): preserve acquisition integrity and exclude selection diagnostics

* fix(browser): preserve capture acquisition and declaration boundaries

* fix(mcp): project sensitive capture argument validation

* fix: preserve capture bytes and prelaunch cancellation

* fix(browser): exclude sensitive HAR record ancestry

* fix(browser): preserve transport URL and parameter exclusions

* fix(browser): preserve numeric redaction and canonical capture provenance

* fix(browser): cover derived capture values and ownership preparation deadlines

* fix(browser): exclude explicitly sensitive artifact digests

* chore: regenerate generated metadata

* fix(browser): reject lossy HAR member normalization

* test(browser): assert the advertised unsupported-profile outcome

* fix(browser): preserve JSON visitor nesting failure locations

* fix(browser): exclude explicitly sensitive native source ranges

---------

Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-10-08 07:53:41 +08:00

142 lines
4.5 KiB
TypeScript

import { z } from "zod";
import { jsonValueSchema } from "./jsonValue.js";
/** Complete historical evidence budgets; exceeding a budget returns no partial capture. */
export const WEB_NETWORK_CAPTURE_LIMITS = {
inputBytes: 32 * 1024 * 1024,
outputBytes: 96 * 1024 * 1024,
timeoutMs: 30_000,
depth: 64,
} as const;
/** Inspect an explicit retained capture without contacting its recorded destinations. */
export const inspectWebNetworkCaptureInputSchema = z.strictObject({
capture_path: z
.string()
.min(1)
.describe("Absolute local HAR or mitmproxy capture path."),
format: z.enum(["har", "mitmproxy"]),
record_ordinals: z
.array(z.number().int().nonnegative())
.min(1)
.optional()
.describe(
"Zero-based producer record ordinals, in caller-selected order. Omit to inspect every record.",
),
sensitive_values: z
.array(z.string().min(1))
.default([])
.describe(
"Literal text excluded from capture payloads, byte/numeric projections, producer coordinates, artifact paths/digests and diagnostic text. Declaration strings are never persisted in Evidence parameters. Canonical contract keys, enums and provider identities remain intact.",
),
});
const pointerSchema = z
.string()
.describe("RFC 6901 pointer in the producer's reported object.");
const redactionSchema = z.union([
z.strictObject({
pointer: pointerSchema,
reason: z.enum(["transport-credential", "explicit-sensitive-value"]),
}),
z.strictObject({
pointer: pointerSchema,
reason: z.literal("explicit-sensitive-value"),
scope: z
.literal("property-name")
.describe(
"An omitted property name; pointer identifies its actual parent, not an invented child coordinate.",
),
}),
]);
const binaryBase = {
pointer: pointerSchema,
representation: z.enum(["producer-bytes", "har-base64-content"]),
};
const binarySchema = z.discriminatedUnion("state", [
z.strictObject({
...binaryBase,
state: z.literal("retained"),
content_base64: z.string(),
bytes: z.number().int().nonnegative(),
sha256: z.string().regex(/^[0-9a-f]{64}$/),
}),
z.strictObject({
...binaryBase,
state: z.literal("redacted"),
content_base64: z.null(),
bytes: z.null(),
sha256: z.null(),
}),
]);
const numberSchema = z.strictObject({
pointer: pointerSchema,
producer_type: z.enum(["json-number", "integer", "float"]),
literal: z.string(),
});
/** Preserve producer representations with independent sidecars rather than invented browser IDs. */
export const webNetworkCaptureRecordSchema = z.strictObject({
ordinal: z.number().int().nonnegative(),
location: z.discriminatedUnion("kind", [
z.strictObject({
kind: z.literal("unknown"),
reason: z.literal("explicit-sensitive-value"),
}),
z.strictObject({ kind: z.literal("json-pointer"), pointer: pointerSchema }),
z.strictObject({
kind: z.literal("byte-range"),
offset: z.number().int().nonnegative(),
bytes: z.number().int().positive(),
}),
]),
reported: jsonValueSchema,
binary_fields: z.array(binarySchema),
numeric_literals: z.array(numberSchema),
redactions: z.array(redactionSchema),
limitations: z.array(z.string()),
});
/** Historical capture inspection has file identity, producer provenance and explicit unknowns. */
export const webNetworkCaptureSchema = z.strictObject({
artifact: z.strictObject({
path: z
.string()
.describe(
"Selected artifact path; empty when explicitly excluded from Evidence.",
),
sha256: z
.string()
.regex(/^[0-9a-f]{64}$/)
.nullable()
.describe(
"Observed artifact SHA-256; null only when explicitly excluded by a sensitive declaration.",
),
bytes: z.number().int().nonnegative(),
}),
format: z.enum(["har", "mitmproxy"]),
decoder: z.strictObject({
id: z.string().min(1),
name: z.string().min(1),
version: z.string().min(1),
}),
container: z.strictObject({
reported: jsonValueSchema,
numeric_literals: z.array(numberSchema),
redactions: z.array(redactionSchema),
records_pointer: pointerSchema.nullable(),
}),
total_records: z.number().int().nonnegative(),
records: z.array(webNetworkCaptureRecordSchema),
runtime_attribution: z.literal("unknown"),
limitations: z.array(z.string()),
});
export type InspectWebNetworkCaptureInput = z.output<
typeof inspectWebNetworkCaptureInputSchema
>;
export type WebNetworkCapture = z.output<typeof webNetworkCaptureSchema>;
export type WebNetworkCaptureRecord = z.output<
typeof webNetworkCaptureRecordSchema
>;