feat(browser): inspect retained aioquic qlog JSON captures

Inspect bounded offline aioquic1.5.0 JSON qlog0.3 and page retained event/transport facts with explicit trace and stream selectors. Preserve producer coordinates, exact numeric lexemes, global pre-selection fact scope and endpoint declaration uncertainty.

Verified four real HTTP/3 recordings with an independent interval oracle, public CLI/MCP/schema parity, auth exclusions, source-deletion views and actual decoder heap exhaustion. Unverified producer platforms and qlog-specific lifecycle induction remain documented.

Co-authored-by: LuisTaffelli <86675342+LuisTaffelli@users.noreply.github.com>
Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
Luis
2026-10-13 03:24:05 +00:00
committed by GitHub
co-authored by N0zoM1z0
parent a2d8b94dd5
commit bb154d1067
30 changed files with 2206 additions and 151 deletions
+15
View File
@@ -62,6 +62,11 @@ import {
captureSummarySchema,
} from "./webNetworkCaptureView.js";
import type { WebNetworkApiSurfaceAccumulator } from "./WebNetworkApiSurfaceAccumulator.js";
import {
qlogViewRequestSchema,
qlogViewPageSchema,
qlogViewContextSchema,
} from "./qlogCaptureView.js";
import {
projectAndroidPackageView,
androidPackageSummarySchema,
@@ -184,6 +189,7 @@ export const analysisViewRequestSchema = z.discriminatedUnion("kind", [
androidViewRequestSchema,
apiSurfaceViewSchema,
captureViewRequestSchema,
qlogViewRequestSchema,
]);
// The application owns admission and authenticated Evidence parsing. SDK and
@@ -403,6 +409,14 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
...viewResultBase,
parent_operation: z.literal("inspect_web_network_capture"),
}),
z.strictObject({
kind: z.literal("qlog"),
view: qlogViewRequestSchema,
page: qlogViewPageSchema,
context: qlogViewContextSchema,
...viewResultBase,
parent_operation: z.literal("inspect_web_network_capture"),
}),
z.strictObject({
kind: z.literal("facet"),
view: facetViewSchema,
@@ -523,6 +537,7 @@ export type UnsignedAnalysisView =
>
| Omit<Extract<AnalysisViewResult, { readonly kind: "wasm" }>, "view_digest">
| Omit<Extract<AnalysisViewResult, { readonly kind: "evm" }>, "view_digest">
| Omit<Extract<AnalysisViewResult, { readonly kind: "qlog" }>, "view_digest">
| Omit<
Extract<AnalysisViewResult, { readonly kind: "capture" }>,
"view_digest"
+248
View File
@@ -0,0 +1,248 @@
import { z } from "zod";
import {
qlogCaptureFactsSchema,
type QlogCaptureFacts,
} from "../qlogCapture.js";
import { err, ok, type Result } from "../result.js";
import type { AnalysisError } from "../analysisErrorBase.js";
import { analysisViewInputError } from "./analysisView.js";
import { pageViewCoverage } from "./analysisViewCoverage.js";
const traceSchema = qlogCaptureFactsSchema.shape.traces.element;
const streamSchema = traceSchema.shape.streams.element;
export const qlogViewContextSchema = qlogCaptureFactsSchema.omit({
traces: true,
});
export const qlogSummarySchema = qlogViewContextSchema.extend({
trace_count: z.number().int().nonnegative(),
retained_stream_count: z.number().int().nonnegative(),
loss_declaration_count: z.number().int().nonnegative(),
incomplete_fact_record_count: z.number().int().nonnegative(),
});
/** Select retained trace facts without copying event inventories or every contribution. */
const pageRequestShape = {
kind: z.literal("qlog"),
offset: z.number().int().nonnegative().default(0),
limit: z.number().int().positive().default(64),
};
const traceSelectorShape = { trace_index: z.number().int().nonnegative() };
const streamSelectorShape = {
...traceSelectorShape,
stream_id: streamSchema.shape.stream_id,
direction: streamSchema.shape.direction,
};
export const qlogViewRequestSchema = z.discriminatedUnion("facet", [
z.strictObject({ ...pageRequestShape, facet: z.literal("traces") }),
z.strictObject({
...pageRequestShape,
...traceSelectorShape,
facet: z.literal("streams"),
}),
z.strictObject({
...pageRequestShape,
...traceSelectorShape,
facet: z.literal("loss-declarations"),
}),
z.strictObject({
...pageRequestShape,
...traceSelectorShape,
facet: z.literal("incomplete-records"),
}),
z.strictObject({
...pageRequestShape,
...streamSelectorShape,
facet: z.literal("contributions"),
}),
z.strictObject({
...pageRequestShape,
...streamSelectorShape,
facet: z.literal("ranges"),
}),
z.strictObject({
...pageRequestShape,
...streamSelectorShape,
facet: z.literal("final-sizes"),
}),
]);
export type QlogViewRequest = z.output<typeof qlogViewRequestSchema>;
const traceSummarySchema = traceSchema
.omit({
streams: true,
loss_declarations: true,
incomplete_fact_records: true,
})
.extend({
stream_count: z.number().int().nonnegative(),
loss_declaration_count: z.number().int().nonnegative(),
incomplete_fact_record_count: z.number().int().nonnegative(),
});
const streamSummarySchema = streamSchema
.omit({
contributions: true,
covered_ranges: true,
reported_final_sizes: true,
})
.extend({
contribution_count: z.number().int().nonnegative(),
covered_range_count: z.number().int().nonnegative(),
reported_final_size_count: z.number().int().nonnegative(),
});
/** Each page advertises exactly the retained item contract for its facet. */
export const qlogViewPageSchema = z.discriminatedUnion("facet", [
z.strictObject({
facet: z.literal("traces"),
items: z.array(traceSummarySchema),
}),
z.strictObject({
facet: z.literal("streams"),
items: z.array(streamSummarySchema),
}),
z.strictObject({
facet: z.literal("loss-declarations"),
items: traceSchema.shape.loss_declarations,
}),
z.strictObject({
facet: z.literal("incomplete-records"),
items: traceSchema.shape.incomplete_fact_records,
}),
z.strictObject({
facet: z.literal("contributions"),
items: streamSchema.shape.contributions,
}),
z.strictObject({
facet: z.literal("ranges"),
items: streamSchema.shape.covered_ranges,
}),
z.strictObject({
facet: z.literal("final-sizes"),
items: streamSchema.shape.reported_final_sizes,
}),
]);
type QlogViewPage = z.output<typeof qlogViewPageSchema>;
export const summarizeQlogCapture = (qlog: QlogCaptureFacts) => {
const { traces, ...context } = qlog;
return {
...context,
trace_count: traces.length,
retained_stream_count: traces.reduce(
(sum, trace) => sum + trace.streams.length,
0,
),
loss_declaration_count: traces.reduce(
(sum, trace) => sum + trace.loss_declarations.length,
0,
),
incomplete_fact_record_count: traces.reduce(
(sum, trace) => sum + trace.incomplete_fact_records.length,
0,
),
};
};
const summarizeTrace = ({
streams,
loss_declarations,
incomplete_fact_records,
...trace
}: QlogCaptureFacts["traces"][number]) => ({
...trace,
stream_count: streams.length,
loss_declaration_count: loss_declarations.length,
incomplete_fact_record_count: incomplete_fact_records.length,
});
const summarizeStream = ({
contributions,
covered_ranges,
reported_final_sizes,
...stream
}: QlogCaptureFacts["traces"][number]["streams"][number]) => ({
...stream,
contribution_count: contributions.length,
covered_range_count: covered_ranges.length,
reported_final_size_count: reported_final_sizes.length,
});
/** Array offsets refer to retained facts, whose scope remains all recorded events. */
export const projectQlogCapturePage = (
qlog: QlogCaptureFacts,
view: QlogViewRequest,
): Result<
{
context: z.output<typeof qlogViewContextSchema>;
page: QlogViewPage;
coverage: ReturnType<typeof pageViewCoverage>;
},
AnalysisError
> => {
const invalid = (field: string, message: string) =>
err(
analysisViewInputError([
{ path: ["view", field], reason: "invalid_value", message },
]),
);
const slice = <T>(items: readonly T[]) =>
items.slice(view.offset, view.offset + view.limit);
let page: QlogViewPage;
let total: number;
if (view.facet === "traces") {
total = qlog.traces.length;
page = {
facet: "traces",
items: slice(qlog.traces).map(summarizeTrace),
};
} else {
const matches = qlog.traces.filter(
(trace) => trace.trace_index === view.trace_index,
);
if (matches.length !== 1)
return invalid(
"trace_index",
"Select one unambiguous retained trace index.",
);
const trace = matches[0]!;
if (view.facet === "streams") {
total = trace.streams.length;
page = {
facet: "streams",
items: slice(trace.streams).map(summarizeStream),
};
} else if (view.facet === "loss-declarations") {
total = trace.loss_declarations.length;
page = { facet: view.facet, items: slice(trace.loss_declarations) };
} else if (view.facet === "incomplete-records") {
total = trace.incomplete_fact_records.length;
page = { facet: view.facet, items: slice(trace.incomplete_fact_records) };
} else {
const matches = trace.streams.filter(
(stream) =>
stream.stream_id === view.stream_id &&
stream.direction === view.direction,
);
if (matches.length !== 1)
return invalid(
"stream_id",
"Select one unambiguous retained stream ID and direction within the trace.",
);
const stream = matches[0]!;
if (view.facet === "contributions") {
total = stream.contributions.length;
page = { facet: view.facet, items: slice(stream.contributions) };
} else if (view.facet === "ranges") {
total = stream.covered_ranges.length;
page = { facet: view.facet, items: slice(stream.covered_ranges) };
} else {
total = stream.reported_final_sizes.length;
page = { facet: view.facet, items: slice(stream.reported_final_sizes) };
}
}
}
const { traces: _traces, ...context } = qlog;
return ok({
context,
page,
coverage: pageViewCoverage(view.offset, page.items.length, total),
});
};
@@ -7,7 +7,11 @@ import {
webNetworkCaptureRecordSchema,
webNetworkCaptureBinaryDescriptorSchema,
webNetworkCaptureSchema,
webNetworkCaptureArtifactSchema,
webNetworkCaptureDecoderSchema,
WEB_NETWORK_CAPTURE_FORMATS,
type WebNetworkCaptureRecord,
type WebNetworkCapture,
} from "../webNetworkCapture.js";
import {
analysisViewInputError,
@@ -19,6 +23,11 @@ import {
completeWithinViewCoverage,
pageViewCoverage,
} from "./analysisViewCoverage.js";
import {
qlogSummarySchema,
summarizeQlogCapture,
projectQlogCapturePage,
} from "./qlogCaptureView.js";
/** Offsets page the parent's retained record order, preserving producer ordinals. */
export const captureViewRequestSchema = z.strictObject({
@@ -37,12 +46,13 @@ export const captureViewItemsSchema = z.array(
/** Count/identity overview; bodies and the archive member inventory stay in the parent. */
export const captureSummarySchema = z.strictObject({
artifact: webNetworkCaptureSchema.shape.artifact,
decoder: webNetworkCaptureSchema.shape.decoder,
format: webNetworkCaptureSchema.shape.format,
artifact: webNetworkCaptureArtifactSchema,
decoder: webNetworkCaptureDecoderSchema,
format: z.enum(WEB_NETWORK_CAPTURE_FORMATS),
total_records: z.number().int().nonnegative(),
retained_records: z.number().int().nonnegative(),
runtime_attribution: z.literal("unknown"),
qlog: qlogSummarySchema.optional(),
});
const object = (
@@ -104,22 +114,10 @@ const preview = (record: WebNetworkCaptureRecord) => {
};
};
/** Page immutable retained facts; no capture file, provider or network is consulted. */
export const projectWebNetworkCaptureView = (
/** Authenticate the retained report and its subject at one owning boundary. */
const parseCaptureParent = (
parent: AnalysisViewParent,
view: AnalysisViewRequest,
): Result<UnsignedAnalysisView, AnalysisError> => {
if (view.kind !== "summary" && view.kind !== "capture")
return err(
analysisViewInputError([
{
path: ["view"],
reason: "invalid_value",
message:
"Historical captures support summary, capture record pages, and admitted api-surface views.",
},
]),
);
): Result<WebNetworkCapture, AnalysisError> => {
const parsed = webNetworkCaptureSchema.safeParse(parent.normalizedResult);
if (!parsed.success)
return err(
@@ -150,6 +148,32 @@ export const projectWebNetworkCaptureView = (
},
]),
);
return ok(report);
};
/** Page immutable retained facts; no capture file, provider or network is consulted. */
export const projectWebNetworkCaptureView = (
parent: AnalysisViewParent,
view: AnalysisViewRequest,
): Result<UnsignedAnalysisView, AnalysisError> => {
if (
view.kind !== "summary" &&
view.kind !== "capture" &&
view.kind !== "qlog"
)
return err(
analysisViewInputError([
{
path: ["view"],
reason: "invalid_value",
message:
"Historical captures support summary, capture record pages, qlog fact pages and admitted api-surface views.",
},
]),
);
const parsed = parseCaptureParent(parent);
if (!parsed.ok) return parsed;
const report = parsed.value;
const shared = {
parent_evidence_id: parent.evidenceId,
parent_operation: "inspect_web_network_capture" as const,
@@ -159,7 +183,7 @@ export const projectWebNetworkCaptureView = (
...new Set([
...parent.limitations,
...report.limitations,
"Pages cover the records selected into the parent Evidence, in that selected order; total_records counts the original decoded capture.",
"Capture record pages cover the records selected into the parent Evidence, in that selected order; total_records counts the original decoded capture.",
]),
],
unknowns: [
@@ -181,12 +205,40 @@ export const projectWebNetworkCaptureView = (
total_records: report.total_records,
retained_records: report.records.length,
runtime_attribution: report.runtime_attribution,
...(report.format === "qlog"
? { qlog: summarizeQlogCapture(report.qlog) }
: {}),
},
coverage: completeWithinViewCoverage(
report.records.length,
report.records.length,
),
});
if (view.kind === "qlog") {
if (report.format !== "qlog")
return err(
analysisViewInputError([
{
path: ["view", "kind"],
reason: "invalid_value",
message: "Qlog fact views require retained qlog Evidence.",
},
]),
);
const projected = projectQlogCapturePage(report.qlog, view);
return projected.ok
? ok({
kind: "qlog",
view,
...shared,
...projected.value,
limitations: [
...shared.limitations,
"Qlog fact pages retain all-recorded-events-before-selection scope. Exhausting a page does not establish network completeness, body recovery, retransmission or actual loss.",
],
})
: projected;
}
const records = report.records.slice(view.offset, view.offset + view.limit);
return ok({
kind: "capture",
+76
View File
@@ -0,0 +1,76 @@
import { z } from "zod";
const decimal = z.string().regex(/^(0|[1-9][0-9]*)$/u);
const unsignedFact = z.discriminatedUnion("state", [
z.strictObject({ state: z.literal("reported"), value: decimal }),
z.strictObject({
state: z.literal("unknown"),
reason: z.literal("omitted-null-or-redacted"),
}),
]);
const traceLocation = z.discriminatedUnion("kind", [
z.strictObject({ kind: z.literal("json-pointer"), pointer: z.string() }),
z.strictObject({
kind: z.literal("unknown"),
reason: z.literal("explicit-sensitive-value"),
}),
]);
/** Exact, source-bound transport facts; coverage never establishes network completeness. */
export const qlogCaptureFactsSchema = z.strictObject({
profile: z.literal("aioquic-1.5.0-json-0.3"),
scope: z.literal("all-recorded-events-before-selection"),
body_bytes: z.literal("not-reported"),
clock: z.strictObject({
unit: z.literal("milliseconds"),
domain: z.literal("unix-epoch"),
basis: z.literal("selected-aioquic-profile-not-producer-authentication"),
}),
traces: z.array(
z.strictObject({
trace_index: z.number().int().nonnegative(),
location: traceLocation,
event_count: z.number().int().nonnegative(),
odcid: z.string().nullable(),
vantage_point: z.enum(["client", "server"]).nullable(),
incomplete_fact_records: z.array(z.number().int().nonnegative()),
loss_declarations: z.array(
z.strictObject({
record_ordinal: z.number().int().nonnegative(),
confidence: z.literal("observed"),
packet_number: unsignedFact,
packet_type: z.string().nullable(),
packet_number_space: z
.enum(["initial", "handshake", "application"])
.nullable(),
}),
),
streams: z.array(
z.strictObject({
stream_id: decimal,
direction: z.enum(["sent", "received"]),
confidence: z.literal("derived"),
scope: z.literal("observed-stream-frame-ranges"),
contributions: z.array(
z.strictObject({
record_ordinal: z.number().int().nonnegative(),
frame_index: z.number().int().nonnegative(),
offset: decimal,
length: decimal,
fin: z.boolean().nullable(),
}),
),
covered_ranges: z.array(
z.strictObject({ start: decimal, end: decimal }),
),
unique_bytes: decimal,
frame_length_sum: decimal,
repeated_bytes: decimal,
reported_final_sizes: z.array(decimal),
}),
),
}),
),
});
export type QlogCaptureFacts = z.output<typeof qlogCaptureFactsSchema>;
+81 -59
View File
@@ -1,6 +1,7 @@
import { z } from "zod";
import { jsonValueSchema } from "./jsonValue.js";
import { localPathStringSchema } from "./localPath.js";
import { qlogCaptureFactsSchema } from "./qlogCapture.js";
/** Complete historical evidence budgets; exceeding a budget returns no partial capture. */
export const WEB_NETWORK_CAPTURE_LIMITS = {
@@ -10,12 +11,17 @@ export const WEB_NETWORK_CAPTURE_LIMITS = {
depth: 64,
} as const;
export const WEB_NETWORK_CAPTURE_FORMATS = ["har", "mitmproxy", "saz"] as const;
export const WEB_NETWORK_CAPTURE_FORMATS = [
"har",
"mitmproxy",
"saz",
"qlog",
] as const;
/** Inspect an explicit retained capture without contacting its recorded destinations. */
export const inspectWebNetworkCaptureInputSchema = z.strictObject({
capture_path: localPathStringSchema.describe(
"Absolute local HAR, mitmproxy, or Fiddler SAZ capture path.",
"Absolute local HAR, mitmproxy, Fiddler SAZ or aioquic qlog capture path.",
),
format: z.enum(WEB_NETWORK_CAPTURE_FORMATS),
record_ordinals: z
@@ -123,69 +129,85 @@ export const webNetworkCaptureRecordSchema = z.strictObject({
limitations: z.array(z.string()),
});
/** Decoded records retain unique producer ordinals within their declared coverage. */
export const webNetworkCapturePayloadSchema = z
.strictObject({
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),
})
.superRefine((capture, context) => {
if (capture.records.length > capture.total_records) {
/** The selected offline parser profile, independent of authenticated producer identity. */
export const webNetworkCaptureDecoderSchema = z.strictObject({
id: z.string().min(1),
name: z.string().min(1),
version: z.string().min(1),
});
/** Source coverage is shared by every offline decoder. */
const payloadShape = {
decoder: webNetworkCaptureDecoderSchema,
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),
};
const refineCoverage = (
capture: { total_records: number; records: { ordinal: number }[] },
context: z.RefinementCtx,
): void => {
const seen = new Set<number>();
for (const [index, record] of capture.records.entries()) {
if (record.ordinal >= capture.total_records || seen.has(record.ordinal)) {
context.addIssue({
code: "custom",
path: ["records"],
message: "Retained record count exceeds the declared capture total.",
path: ["records", index, "ordinal"],
message:
"Retained ordinals must be unique and within the declared capture total.",
});
return;
}
const seen = new Set<number>();
for (const [index, record] of capture.records.entries()) {
if (record.ordinal >= capture.total_records || seen.has(record.ordinal)) {
context.addIssue({
code: "custom",
path: ["records", index, "ordinal"],
message:
"Retained ordinals must be unique and within the declared capture total.",
});
return;
}
seen.add(record.ordinal);
}
});
/** Historical capture inspection has file identity, producer provenance and explicit unknowns. */
export const webNetworkCaptureSchema =
webNetworkCapturePayloadSchema.safeExtend({
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(),
seen.add(record.ordinal);
}
};
/** Strict alternatives prevent undefined-valued facets from entering JSON Evidence. */
export const webNetworkCapturePayloadSchema = z
.union([
z.strictObject({ ...payloadShape, qlog: qlogCaptureFactsSchema }),
z.strictObject(payloadShape),
])
.superRefine(refineCoverage);
/** Caller-selected file identity; explicit exclusions remain unknown. */
export const webNetworkCaptureArtifactSchema = 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 SHA-256; null only when explicitly excluded."),
bytes: z.number().int().nonnegative(),
});
const artifactShape = {
artifact: webNetworkCaptureArtifactSchema,
runtime_attribution: z.literal("unknown"),
limitations: z.array(z.string()),
};
/** Qlog transport facts occur exactly on the qlog alternative. */
export const webNetworkCaptureSchema = z
.discriminatedUnion("format", [
z.strictObject({
...payloadShape,
...artifactShape,
format: z.enum(["har", "mitmproxy", "saz"]),
}),
format: z.enum(WEB_NETWORK_CAPTURE_FORMATS),
runtime_attribution: z.literal("unknown"),
limitations: z.array(z.string()),
});
z.strictObject({
...payloadShape,
...artifactShape,
format: z.literal("qlog"),
qlog: qlogCaptureFactsSchema,
}),
])
.superRefine(refineCoverage);
export type InspectWebNetworkCaptureInput = z.output<
typeof inspectWebNetworkCaptureInputSchema
@@ -53,8 +53,30 @@ export const excludeCaptureCoordinates = (
numeric_literals: sidecars(value.container.numeric_literals),
redactions: sidecars(value.container.redactions),
};
const qlog =
value.format === "qlog"
? {
...value.qlog,
traces: value.qlog.traces.map((trace) => {
if (
trace.location.kind !== "json-pointer" ||
!sensitive(trace.location.pointer)
)
return trace;
excluded = true;
return {
...trace,
location: {
kind: "unknown" as const,
reason: "explicit-sensitive-value" as const,
},
};
}),
}
: undefined;
return {
...value,
...(qlog === undefined ? {} : { qlog }),
container,
records,
limitations: excluded