Skip to content

feat(browser): redact declared values in session HAR - #2046

Closed
Hyped01 wants to merge 3 commits into
morluto:mainfrom
Hyped01:feat/session-har-2-redaction
Closed

Hyped01 wants to merge 3 commits into
morluto:mainfrom
Hyped01:feat/session-har-2-redaction

Conversation

@Hyped01

@Hyped01 Hyped01 commented Oct 12, 2026

Copy link
Copy Markdown

Stacked on #2045. Only the top commit, 43a0e2ba0, is new here.

Summary

Refs #774. This PR adds sensitive_values (CLI --sensitive-value) and sensitive_query_parameters (CLI --sensitive-query-parameter) to observe_web_session. Declared values are then replaced, with [REDACTED:value-N] markers, in every field the session result and its HAR retain.

Problem and expected behavior

The recorder from #2045 retains URLs, query values, header values and timeline fields verbatim. A user who knows a token, a device ID or a signature value must be able to keep it out of the evidence, including the spellings in which browsers and servers re-encode it.

Change and scope

  • What is checked. src/browser/SessionRedactor.ts checks every retained field, both as written and in its UTF-8 percent-decoded, form-decoded and JSON-unescaped forms, nested up to three levels. That covers URLs, query names and values, headers, timeline fields, target IDs, MIME types, methods and browser metadata (browser, har.log.browser, and therefore the Evidence environment). A value that survives replacement in any of those forms empties the field.
  • URLs are redacted piece by piece, by path segment, query pair and fragment piece:
    • Each piece is redacted as written before it is decoded. A raw +, a lowercase escape or an unreserved escape therefore cannot hide a value, and a piece whose result still spells one is emptied.
    • Unrelated bytes are unchanged and the URL stays valid.
    • A host that spells a value becomes redacted.invalid and keeps its port. A port that spells one loses its digits but keeps its host and the :, a spelling no browser writes, so the removal stays visible. Evidence never derives an origin from such a URL.
    • A value that spans pieces fails the whole URL closed. Placeholders follow the order <scheme>//redacted.invalid/, then urn:redacted, then x:y. An entry that none of these can stand in for is omitted and counted under network_requests or websocket_connections/websocket_frames.
    • The HAR queryString is derived from the redacted URL, so it never reveals what the URL hides.
  • Matching is one Aho-Corasick automaton built once per session, so cost stays linear however many literals are declared. Values are matched as spelled: browsers report hosts lowercased and in punycode, and the docs say to declare that spelling. Literals with unpaired surrogates are accepted.
  • Query parameters. Observed values of named query parameters become declared literals, including values inside retained URL-valued headers.
  • Evidence parameters keep the parameter names and the count of declared literals, never the literals. A request parameter or parameter name that spells one is left empty, and the result says so.
  • Counting. redactions.explicit_value_fields counts the changed HAR and network-target fields.
  • URL-valued headers that are not one absolute URL are redacted as text: relative Location/Content-Location, Link and Refresh. Their markers are not percent-encoded, and a value found only in a decoded spelling empties the header value. The docs say so.
  • Not detected, as the docs state: percent-encoding in a legacy charset, HTML entities, base64 inside headers, and query parameters inside a fragment (declare those values with sensitive_values).

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/browser/SessionRedactor.ts, applied in src/browser/CdpSessionResult.ts.
  • CLI and MCP/tool-catalog contract: additive optional inputs, and an additive redactions.explicit_value_fields output.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: the Evidence parameters record names and counts only.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated:
    • src/browser/SessionRedactor.test.ts:
      • piecewise URL redaction that keeps unrelated bytes;
      • invalid UTF-8, nested and JSON spellings;
      • raw + and lowercase or unreserved escapes;
      • fallbacks and markers;
      • overlapping values;
      • lone surrogates;
      • linear scaling with 3,000 signatures and with nested literals.
    • tests/boundary/browser/cdpObservationSessionNetwork.test.ts:
      • exact field counts;
      • a value that spans query pairs;
      • depth-four literals in query values;
      • emptied flag pairs that keep alignment;
      • browser metadata;
      • an observed query value spelled by every URL's scheme;
      • per-section counts for inadmissible HTTP and WebSocket entries;
      • an end-to-end case where each decoded reading is checked against every decoding of the serialized session;
      • one test per redaction call site: retained capture URLs as a query-value source in a navigation-only session, text-redacted URL-valued headers, redirectURL, query names, statusText, header names, and timeline frame and request IDs and details.
    • MCP tests: Evidence parameter blanking, including a derived origin and a query parameter name.
  • Mutation checks: each of these fails a test.
    • As-written replacement first.
    • The form re-check.
    • The re-check of the encoded result.
    • Every placeholder fallback.
    • Per-section counts.
    • The surrogate guards.
    • The JSON escape set.
    • The Evidence predicate.
  • Remaining proof gaps: the spellings listed above as not detected.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • Per-commit gate: pass (see feat(browser): record observe_web_session traffic as HAR #2045).
  • npx vitest run on 12 browser, CLI, MCP and redactor test files: 104 passed, 2 skipped.
  • exposes CLI-equivalent Evidence results and session tools, an existing MCP test, times out only under heavy machine load. It fails the same way on unmodified main.
  • Cold review with adversarial verification: the final round reported no findings.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; redaction is opt-in.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: redaction fails closed. A field in which any decoding still spells a declared value is emptied, and an unrepresentable entry is omitted and counted.

🤖 Generated with Claude Code

Hyped01 and others added 3 commits October 11, 2026 23:39
inspect_web_network_capture validates request.url with ajv-formats' RFC 3986
`uri` format. Browsers serialize request URLs per WHATWG URL and leave
[ ] { } | ^ and backtick, a `%` that starts no escape, and a backslash in the
query or fragment unescaped, so a HAR that Chrome itself exports for such a
page was rejected whole as a format error.

- A request URL is admitted when the pinned RFC 3986 check accepts it as
  written or with only those characters percent-encoded: each [ ] { } | ^ and
  backtick, each `%` not followed by two hex digits, and each backslash after
  the first `?` or `#`. Spellings that only WHATWG parsing accepts, such as a
  backslash before the first `?` or `#` or a tab, stay rejected: browsers
  never serialize them, and WHATWG alone reads an authority through them.
- The transport-credential header set moves unchanged from CaptureRedaction
  to src/browser/network/TransportCredentials.ts; capture_browser_scenario's
  network headers now use it instead of a private copy, and the session
  HAR recorder in the next change applies the same set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
observe_web_session can now record the selected page's in-scope HTTP
requests and WebSocket connections across main-frame navigations as one
HAR 1.2 log, so a user-driven multi-page flow can be inspected offline with
inspect_web_network_capture. Recording is opt-in through a `network`
selection (CLI: --network); without it the result and Evidence parameters
are unchanged.

- Requests, redirects and WebSocket handshakes use the timeline's origin
  boundary. Excluded traffic is counted in completeness. Recording stops
  right after the event that ends the timeline, so an out-of-scope
  document redirect still completes its in-scope hop.
- Cross-site iframes that the browser runs out of process, and the page's
  dedicated, shared and service workers, are separate targets that are not
  attached, so their traffic is not recorded, and a dedicated worker's
  script request can appear without its response; a limitation, the tool
  description and the docs say so.
- Without a network selection, the navigation-only limitation now says
  that network was not selected, rather than that the tool cannot capture
  headers, bodies or payloads.
- Headers are retained only with `header_values`. Authorization,
  Proxy-Authorization, Cookie and Set-Cookie never are. URL-valued headers
  (Location, Content-Location, Referer, Origin, Link, Refresh) pointing
  outside the selected origins, or without a parseable target, are
  omitted, and userinfo in retained ones is removed; all are counted.
  Link targets, including `anchor` parameters, are read as RFC 8288
  link-values; a Link that does not parse as one, has a `<` inside a target
  or an anchor value it cannot read is omitted. The Refresh delay is matched
  without backtracking, so a page-controlled digit run stays linear. A
  quoted Refresh URL whose quote appears again after its closing quote is
  omitted, since Chromium reads it to the last matching quote.
- har_bytes reports the log's serialized size. REA does not check it
  against inspect_web_network_capture's 32 MiB input budget or 96 MiB reply
  limit, which a log dominated by WebSocket frames can exceed below 32 MiB;
  the tool description and docs say so.
- Timings follow HAR 1.2 (non-negative send/wait/receive, time is their
  sum); a response still loading when recording stopped says so. A request
  that carried an unretained body reports bodySize -1.
- coverage_started_at is taken once the browser has processed
  Network.enable, the earliest instant coverage is guaranteed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds `sensitive_values` (CLI: --sensitive-value) and
`sensitive_query_parameters` (CLI: --sensitive-query-parameter) to
observe_web_session.

- Every retained field (URLs, query parameters, headers, timeline fields,
  target IDs, MIME types, methods and browser metadata) is checked as
  written and in its UTF-8 percent-decoded, form-decoded and JSON-unescaped
  forms, nested up to three levels; a value that survives replacement fails
  the field closed. The docs name the spellings that are not detected.
- URLs are redacted piece by piece: only the host, port, path segments,
  query pairs and fragment pieces that spell a value are rewritten (the
  pieces with percent-encoded markers), so the rest keeps its exact bytes and the URL stays a
  valid URI. A URL-valued header is redacted this way only when its whole
  value is one absolute URL; a relative Location or Content-Location and
  every Link and Refresh value are redacted as text, with markers that are
  not percent-encoded, and emptied when a declared value appears only in a
  decoded spelling. Each piece is redacted as written before it is decoded, so a
  raw '+', a lowercase escape or an unreserved escape cannot hide a value,
  and a piece whose result still spells one is emptied. A host that spells
  a value becomes redacted.invalid and keeps its port; a port that spells
  one loses its digits but keeps its host and the ':' before it; a value
  spanning pieces fails the whole URL closed; a HAR entry no placeholder URL can stand in for is
  omitted and counted under its own completeness section. The HAR
  queryString is derived from the redacted URL, so it never reveals what
  the URL hides.
- One Aho-Corasick matcher over every spelling is built per session, so
  redaction stays linear in the retained text however many query values
  are declared. Declared values with unpaired surrogates are accepted.
- The observed values of named query parameters in the query strings of
  retained URLs (target and timeline URLs, HAR request and WebSocket URLs,
  and in-scope URL-valued header targets of requests, responses and
  WebSocket handshakes) become declared literals; parameters inside a fragment
  are not read and must be declared as sensitive values.
- Evidence parameters keep the parameter names and the number of declared
  literals, never the literals; a request parameter or parameter name that
  spells one is left empty, and the result says so. Evidence never
  derives allowed_origins from a target URL whose host or port was
  redacted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T04:21:22.596062Z 43a0e2b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 43a0e2ba06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +46 to +48
product: redactor.text(input.browser.product),
protocol_version: redactor.text(input.browser.protocol_version),
revision: redactor.text(input.browser.revision),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Redact the composed Evidence environment ID

When sensitive_values contains a literal that spans browser fields—for example FakeChrome/1.0@fake-revision—the per-field calls here see no match, but createBrowserEvidence later concatenates the unchanged product and revision into exactly that environment.id. The Evidence envelope therefore persists a caller-declared secret; check the composed identifier with the same session redactor before emitting it.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

): SessionEntry => {
const { redactor } = context;
const response = exchange.response;
const httpVersion = harHttpVersion(cdpStringValue(response?.protocol));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Redact projected HTTP protocol strings

When a declared literal is HTTP/2 (including one learned from a named sensitive query parameter), a normal CDP value h2 is converted by harHttpVersion into that literal and then copied into both request and response without a SessionRedactor check; unrecognized protocol strings are also copied verbatim. This makes the serialized HAR expose an explicitly marked value, so redact the final projected httpVersion strings.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

},
cache: {},
timings,
...(exchange.error === null ? {} : { _error: exchange.error }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Redact retained network failure codes

When Network.loadingFailed reports a valid code containing a declared literal—for example BLOCKED in net::ERR_BLOCKED_BY_CLIENT—this property copies raw exchange.error; the corresponding timeline detail is redacted, but the serialized HAR still exposes the value and the redaction counter misses it. Pass the failure code through the redactor before retaining it.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

const payload = cdpStringValue(response?.payloadData) ?? "";
const opcode = Math.max(0, Math.trunc(numberValue(response?.opcode) ?? 0));
const timestamp = numberValue(params?.timestamp);
socket.messages.push({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound retained WebSocket frame metadata

When network capture is enabled for a long observation or a target sending high-rate WebSocket frames, every frame appends here with no count or byte budget; socketEntry later duplicates the list into HAR and serialization copies it again. Because observation_ms has no upper bound, the target can exhaust local memory before har_bytes is computed, while completeness never reports truncation; enforce a capacity limit and record dropped coverage.

AGENTS.md reference: AGENTS.md:L46-L46

Useful? React with 👍 / 👎.

const target = this.#sessions.get(event.sessionId);
const params = recordValue(event.params);
const requestId = cdpStringValue(params?.requestId);
if (this.#stopped || target === undefined || requestId === undefined)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report malformed network events instead of dropping them

When an active registered target emits a malformed request or frame event whose requestId is missing or non-string, this guard silently returns without recording an invalid_protocol_value exclusion. The result therefore omits an observed event without preserving a meaningful completeness reason; separate the stopped/unregistered cases from malformed target events and mark the affected section unavailable or excluded.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

@Hyped01 Hyped01 closed this Oct 12, 2026
@Hyped01
Hyped01 deleted the feat/session-har-2-redaction branch October 12, 2026 04:36
@morluto morluto added the enhancement New feature or request label Oct 14, 2026
@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants