diff --git a/docs/guides/web/browser-observation.md b/docs/guides/web/browser-observation.md index 2f1f1003dd..7000b02a0e 100644 --- a/docs/guides/web/browser-observation.md +++ b/docs/guides/web/browser-observation.md @@ -489,7 +489,7 @@ REA retains local observation data and removes only URL userinfo credentials, ex - DOM snapshots retain node types, node names, value lengths, and attribute names, but not text or attribute values. `dom.node_value_length_unit` is `utf16-code-units` for web observations and applies to every node's `node_value_length`; it counts JavaScript string code units, not Unicode code points or UTF-8 bytes. Electron observations declare `utf8-bytes` instead. A snapshot without the unit is malformed; REA does not infer a unit or convert stored lengths. - Supported DOM URL attributes are projected separately as resolved destinations. Empty `action` on HTML or XHTML forms and empty `formaction` on HTML or XHTML submit controls resolve to the document URL; other relative URL attributes resolve against the captured document base. - Accessibility structure and reported roles are retained by default, while names and descriptions require `include_accessibility_text: true`. The browser protocol may omit an individual role; that role remains unknown for comparison. Other observed accessibility differences can still establish a change. -- Network observations retain method, status, MIME type, size, type, initiator stack location, and complete URLs with userinfo credentials removed. Redirects reported by CDP are attached as ordered `redirects` on the one request ID, with the prior request URL, CDP response URL, method/type, response status/MIME/encoded length, request timestamp, and the next `requestWillBeSent` event timestamp. CDP delivers `redirectResponse` with that next request event, so the latter is an event boundary rather than an exact response timestamp. Redirect response headers and bodies are discarded; hops outside the selected origins are discarded with the request chain. Headers are discarded after an allowlisted projection of length/encoding, structured CSP/Link/policy fields, and untrusted agent hints. Cookies and authorization headers are never retained. +- Network observations retain method, status, MIME type, size, type, initiator stack location, and complete URLs with userinfo credentials removed. Redirects reported by CDP are attached as ordered `redirects` on the one request ID (an empty list when the request was not redirected; a request without the list is refused as malformed), with the prior request URL, CDP response URL, method/type, response status/MIME/encoded length, request timestamp, and the next `requestWillBeSent` event timestamp. CDP delivers `redirectResponse` with that next request event, so the latter is an event boundary rather than an exact response timestamp. Redirect response headers and bodies are discarded; hops outside the selected origins are discarded with the request chain. Headers are discarded after an allowlisted projection of length/encoding, structured CSP/Link/policy fields, and untrusted agent hints. Cookies and authorization headers are never retained. - Request/response bodies are not requested or parsed by default. When selected, only allowed-origin JSON media types are read, converted immediately to complete value-free typed paths, types and observation counts, and discarded. Each path segment is either `{ "kind": "property", "name": "raw property name" }` or `{ "kind": "array-element" }`; array-element types include primitives and nested arrays. Literal `*` properties remain distinct from array elements. `Network.getResponseBody` is never sent unless JSON body shape capture is selected. A JSON-typed request body that CDP reports through `hasPostData` but omits from `postData`, or that cannot be parsed as JSON, makes `json_body_shapes` unavailable. That request's `body_shapes.status` is `partial`, not `included`, when only its response shape was captured. Base64 response bytes must be valid UTF-8 before JSON interpretation; invalid bytes leave the response shape unavailable and preserve any observed request shape and network metadata. Producer-decoded strings and genuine U+FFFD characters retain their reported meaning. Comparison uses body shapes only when both captures selected them, and compares request/response shapes only where both observations provide those facts. Unavailable or truncated selected coverage makes equivalence unknown; observed differences still report changed. For normalized passive inputs with complete request inventories on both sides, request additions and removals remain observable even when selected body shapes, diff --git a/src/domain/browserObservationSchemas.ts b/src/domain/browserObservationSchemas.ts index 5f055d7474..7b4b6256d9 100644 --- a/src/domain/browserObservationSchemas.ts +++ b/src/domain/browserObservationSchemas.ts @@ -105,21 +105,19 @@ const browserNetworkRequestSchema = z.object({ status: z.number().nullable(), mime_type: z.string().nullable(), encoded_data_length: z.number().min(0).nullable(), - redirects: z - .array( - z.object({ - url: z.string(), - response_url: z.string(), - method: z.string(), - resource_type: z.string().nullable(), - status: z.number().nullable(), - mime_type: z.string().nullable(), - encoded_data_length: z.number().min(0).nullable(), - request_timestamp: z.number().nullable(), - redirect_event_timestamp: z.number().nullable(), - }), - ) - .optional(), + redirects: z.array( + z.object({ + url: z.string(), + response_url: z.string(), + method: z.string(), + resource_type: z.string().nullable(), + status: z.number().nullable(), + mime_type: z.string().nullable(), + encoded_data_length: z.number().min(0).nullable(), + request_timestamp: z.number().nullable(), + redirect_event_timestamp: z.number().nullable(), + }), + ), initiator: z.object({ type: z.string(), url: z.string().nullable(), diff --git a/src/domain/webCaptureDiff.network.test.ts b/src/domain/webCaptureDiff.network.test.ts index a2f4970d1f..b1793e352f 100644 --- a/src/domain/webCaptureDiff.network.test.ts +++ b/src/domain/webCaptureDiff.network.test.ts @@ -50,13 +50,28 @@ const redirectCapture = (resourceType: string | null): WebPageInspection => { return capture; }; +it("refuses a captured request without its redirect list", () => { + const capture = unselectedShapes(passiveNetworkCapture()); + const { redirects: _redirects, ...request } = capture.network.requests[0]!; + const malformed = { + ...capture, + network: { ...capture.network, requests: [request] }, + }; + expect( + browserCaptureComparisonInputSchema.safeParse({ + before: { inspection: malformed }, + after: { inspection: capture }, + }).success, + ).toBe(false); +}); + describe("nullable redirect resource types", () => { it.each([true, false])( "retains uncertainty when a redirect type is omitted (reversed=%s)", (reversed) => { const before = redirectCapture("Document"); const after = structuredClone(before); - after.network.requests[0]!.redirects![0]!.resource_type = null; + after.network.requests[0]!.redirects[0]!.resource_type = null; const [left, right] = reversed ? ([after, before] as const) : ([before, after] as const); @@ -73,7 +88,7 @@ describe("nullable redirect resource types", () => { (resourceType) => { const before = redirectCapture("Document"); const after = structuredClone(before); - after.network.requests[0]!.redirects![0]!.resource_type = resourceType; + after.network.requests[0]!.redirects[0]!.resource_type = resourceType; expect(compare(before, after)).toMatchObject({ status: resourceType === "Document" ? "unchanged" : "changed", total_changes: resourceType === "Document" ? 0 : 1, diff --git a/src/domain/webCaptureDiff.ts b/src/domain/webCaptureDiff.ts index 9f0663fe6f..12bab30070 100644 --- a/src/domain/webCaptureDiff.ts +++ b/src/domain/webCaptureDiff.ts @@ -427,7 +427,7 @@ const sharedNetworkMetadata = ( for (const request of inspection.network.requests) { const identity = networkIdentity(request); retainKnownFields(identity, request, networkResponseFields); - for (const [index, redirect] of (request.redirects ?? []).entries()) + for (const [index, redirect] of request.redirects.entries()) retainKnownFields( redirectNetworkIdentity(identity, index), redirect, @@ -642,7 +642,7 @@ const networkMap = ( values.push( digestCanonicalValue({ ...response, - redirects: (request.redirects ?? []).map( + redirects: request.redirects.map( ( { request_timestamp: _requestTimestamp, diff --git a/tests/fixtures/passiveNetworkCapture.ts b/tests/fixtures/passiveNetworkCapture.ts index f8ac116442..0e85b77efa 100644 --- a/tests/fixtures/passiveNetworkCapture.ts +++ b/tests/fixtures/passiveNetworkCapture.ts @@ -59,6 +59,7 @@ export const passiveNetworkCapture = (paths: readonly string[] = ["/a"]) => { status: 200, mime_type: "text/html", encoded_data_length: 10, + redirects: [], initiator: { type: "parser", url: null, line: null, column: null }, body_shapes: { status: "unavailable", request: null, response: null }, })),