Skip to content

Remove early redaction of secrets; use Reveal for sensitive headers (#3077) - #3078

Merged
cliffhall merged 6 commits into
v2/mainfrom
v2/fix/3077-reveal-instead-of-early-redaction
Nov 30, 2026
Merged

cliffhall merged 6 commits into
v2/mainfrom
v2/fix/3077-reveal-instead-of-early-redaction

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #3077, closes #3023, closes #3076

Thanks to @mikecat (#3023) and @CloneOfAlex (#3076) for the reports, and @aniket-r2Dev2 for tracing the capture-time redaction on #3023.

Why

The Network tab is meant to mask secrets for display (••••••••) and show them on Reveal (#1386). Since #1561/#1593 the fetch tracker redacted headers and bodies before recording the entry, so Reveal showed [REDACTED] (#3023). Headers never got the mask/reveal treatment at all: the six names core knew were redacted and couldn't be revealed, and every other credential header (X-Auth-Token, Api-Key, Ocp-Apim-Subscription-Key, …) was shown in plain text (#3076). Five separate lists decided what a secret is, and they had drifted.

What changed

  • One list — core/mcp/sensitiveNames.ts. It replaces the fetch tracker's header and body sets, --oauth-debug's SENSITIVE_FIELDS, the CLI's isSensitiveHeader and the web mask's JSON/form keys. Field names match exactly, so OAuth metadata like token_endpoint stays readable. Header names match by fragment (the CLI's rule), plus DPoP and Ocp-Apim-Subscription-Key, minus WWW-Authenticate, which is a challenge rather than a credential.
  • The live fetch log keeps real values. createFetchTracker no longer redacts headers or bodies. Three things are still removed at capture, because nothing could reveal them: the URL's credential query parameters (the URL shows in every collapsed row), whsec_ webhook secrets (Events (#3026) phase 4: webhook subscription management #3031, found by value rather than name), and truncated JSON (it can't be masked).
  • Sinks redact with the new redactFetchRequestEntry: the InspectorClient fetch log line (which reaches the backend's log file), Network Export, and the TUI's request list and details, which have no reveal control.
  • Headers get mask/reveal in NetworkEntry, with one toggle per headers table, sharing the body's SecretsToggle. A masked MCP header is neither decoded nor mismatch-flagged, since that tooltip would quote the secret. A value that is already [REDACTED] is never offered for reveal.
  • The web mask follows core's rules. A number under a sensitive key, such as a JSON-RPC error code, is left alone. A JSON body labeled with another content type is still masked if it parses as JSON.

The pre-redirect OAuth log now uses sessionStorage, not disk

Before the OAuth redirect, the Network log was POSTed to /api/storage, which wrote it to ~/.mcp-inspector/storage/inspector-session-<authId>.json and never deleted it. Now that entries keep real values, it rides in the tab's sessionStorage instead (src/lib/fetchLogSessionStorage.ts):

  • It is needed only across one full-page redirect that comes back to the same tab, and sessionStorage is scoped to that tab and origin.
  • It never leaves the browser.
  • That tab's sessionStorage already holds the backend API token. That token is strictly stronger (it drives the backend, including launching stdio servers), so storing the log there adds no new reader.
  • It is read once: FetchRequestLogState deletes it as soon as it has restored it. A StrictMode-destroyed instance leaves it for the live one.
  • The write is synchronous, so it finishes before navigation. A quota failure drops the log, exactly as the 64KB keepalive POST it replaces could.

RemoteInspectorClientStorage had no other caller, so it and its test are removed. /api/storage itself stays (it also serves oauth/client). Files written by earlier builds are not cleaned up.

Screenshots

New Groups/NetworkEntry/CredentialHeaders story (1280×900).

Masked by default: the authorization and x-auth-token headers, the form code, and the JSON tokens. www-authenticate stays readable.

masked

After Reveal on all three sections, the real values are shown:

revealed

Testing

npm run local:gate passes. New or changed tests cover:

  • the shared list;
  • capture keeping values while redactFetchRequestEntry redacts them;
  • Export redacting entries;
  • the backend log file not containing a configured X-Auth-Token value (an integration test);
  • header mask/reveal and no Reveal over [REDACTED] values;
  • the sessionStorage adapter;
  • read-once hydration;
  • the CLI's broadened header rule.

🤖 Generated with Claude Code

…#3077)

The fetch tracker redacted headers and bodies before an entry was
recorded (#1561, #1593), so the Network tab's Reveal toggle (#1386)
revealed `[REDACTED]` (#3023), and credential headers outside core's
six-name list were shown in plain text with no masking at all (#3076).

- One list: core/mcp/sensitiveNames.ts replaces the five lists the
  tracker, --oauth-debug, `servers/show` and the web mask kept. Field
  names match exactly; header names by fragment (plus DPoP and
  Ocp-Apim-Subscription-Key, minus WWW-Authenticate).
- The live fetch log keeps real header and body values. The URL query,
  `whsec_` webhook secrets and truncated JSON are still removed at
  capture, where no reveal could bring them back.
- Sinks redact with `redactFetchRequestEntry`: the InspectorClient log
  line, Network export and the TUI's request view.
- NetworkEntry masks credential headers behind their own Reveal, and a
  value already `[REDACTED]` is never offered for reveal.
- The pre-redirect OAuth Network log rides in the tab's sessionStorage
  and is deleted once restored, instead of a never-deleted file under
  ~/.mcp-inspector/storage. RemoteInspectorClientStorage is removed.

Closes #3077, closes #3023, closes #3076

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>

Copilot AI 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.

🟡 Changes recommended

A blocked sessionStorage getter can crash OAuth recovery during render, and repeated redaction of the full retained request history can stall the TUI on routine updates.

2 open issues
What changed in this PR

This PR restores meaningful Reveal controls in the Network tab while keeping exported logs, backend logs, and TUI output redacted, addressing #3077, #3023, and #3076.

Changes:

  • Centralizes sensitive-name matching and moves header/body redaction from capture to output boundaries.
  • Adds header mask/reveal controls alongside body masking.
  • Replaces disk-backed OAuth Network-log persistence with read-once, tab-scoped sessionStorage.
File Description
core/​mcp/​state/​fetchRequestLogState.ts Deletes saved logs after restoration.
core/​mcp/​sensitiveNames.ts Defines shared sensitive field and header rules.
core/​mcp/​remote/​sessionStorage.ts Removes disk-backed session adapter.
core/​mcp/​remote/​index.ts Removes obsolete adapter exports.
core/​mcp/​inspectorClient.ts Redacts fetch entries before logging.
core/​mcp/​fetchTracking.ts Preserves live values and adds output redaction.
core/​cli/​handlers/​servers-list.ts Uses shared header sensitivity rules.
core/​auth/​oauthDebug.ts Uses shared sensitive field names.
core/​auth/​oauth-persist.ts Updates a storage-related comment.
clients/​web/​src/​utils/​maskSecrets.ts Aligns body masking and adds header masking.
clients/​web/​src/​utils/​maskSecrets.test.ts Tests shared masking and redacted-value handling.
clients/​web/​src/​test/​integration/​mcp/​remote/​transport.test.ts Checks credential exclusion from backend logs.
clients/​web/​src/​test/​core/​mcp/​state/​fetchRequestLogState.test.ts Tests read-once restoration and destroy handling.
clients/​web/​src/​test/​core/​mcp/​sensitiveNames.test.ts Tests shared name predicates.
clients/​web/​src/​test/​core/​mcp/​remote/​sessionStorage.test.ts Removes obsolete adapter tests.
clients/​web/​src/​test/​core/​mcp/​fetchTracking.test.ts Tests live capture and redacted output copies.
clients/​web/​src/​test/​core/​auth/​oauthDebug.test.ts Updates shared-list commentary.
clients/​web/​src/​lib/​fetchLogSessionStorage.ts Adds browser session-storage adapter.
clients/​web/​src/​lib/​fetchLogSessionStorage.test.ts Tests storage round trips and failures.
clients/​web/​src/​hooks/​useOAuthRecovery.ts Uses tab-scoped storage across redirects.
clients/​web/​src/​hooks/​useOAuthRecovery.test.tsx Updates storage mocks.
clients/​web/​src/​hooks/​useExportActions.ts Redacts Network exports.
clients/​web/​src/​hooks/​useExportActions.test.tsx Tests export credential redaction.
clients/​web/​src/​hooks/​useConnectionLifecycle.ts Uses the storage interface type.
clients/​web/​src/​hooks/​useConnectionLifecycle.test.tsx Updates storage fixture typing.
clients/​web/​src/​components/​groups/​NetworkEntry/​NetworkEntry.tsx Adds header Reveal controls and guards masked tooltips.
clients/​web/​src/​components/​groups/​NetworkEntry/​NetworkEntry.test.tsx Tests header masking and Reveal behavior.
clients/​web/​src/​components/​groups/​NetworkEntry/​NetworkEntry.stories.tsx Adds interactive credential-header story.
clients/​web/​src/​App.test.tsx Removes obsolete remote-storage mock.
clients/​web/​README.md Documents masking and redirect storage.
clients/​tui/​src/​App.tsx Redacts request entries for display and copying.
clients/​cli/​__tests__/​servers-list.test.ts Tests broadened credential-header redaction.

Review effort: Balanced

Comment thread clients/tui/src/App.tsx
Comment on lines +765 to +768
const inspectorFetchRequests = useMemo(
() => recordedFetchRequests.map(redactFetchRequestEntry),
[recordedFetchRequests],
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 5e0f418. Redaction moved to clients/tui/src/utils/redactedFetchRequests.ts, which caches each redacted copy in a WeakMap keyed by entry identity. That's exact because FetchRequestLogState replaces an entry object when it updates one, so only new or updated entries pay for the body parse, and dropped ones are collected. Tested in __tests__/redactedFetchRequests.test.ts.

)

Reading window.sessionStorage can throw a SecurityError where storage
is blocked; the adapter is built during render, so it now takes a getter
resolved inside each settled call. The TUI redacted its whole retained
history on every log update; it now caches redacted copies by entry
identity, which is exact because the log replaces entries it updates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1 (both fixed in 5e0f418):

  • High: a blocked sessionStorage getter can throw during render. Fixed. The adapter takes a storage getter resolved inside each settled call; regression test added.
  • Medium: the TUI re-redacts the whole history on every update. Fixed. Redacted copies are cached per entry identity (WeakMap), so only new or updated entries are reprocessed.

Copilot AI 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.

🟡 Changes recommended

Webhook secret matching against raw JSON misses escaped whsec_ values in request and response bodies, allowing the Network preview to expose secrets without a Reveal control.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread core/mcp/fetchTracking.ts Resolved
Capture now matches whsec_ secrets against a JSON body's decoded string
values, so a \/ or \u escape no longer cuts the match short. The body
is re-serialized only when a secret was found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 2 (fixed in c0e474f):

  • JSON-escaped whsec_ secrets survived capture. Fixed. Webhook secrets are now matched against decoded JSON string values, on both the request and response paths, with tests.

Copilot AI 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.

🟡 Changes recommended

Request-body logging can overflow on deeply nested valid JSON before the request is sent, so recursive traversal and serialization need guards that omit the recorded body on failure to avoid exposing secrets.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread core/mcp/fetchTracking.ts Resolved
The webhook-secret walk and re-serialization run before the request is
sent; nesting that JSON.parse accepts can overflow them. Guard both and
record a withheld marker rather than throwing or keeping the raw body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 3 (fixed in b354971):

  • Deeply nested JSON could overflow the capture-time webhook walk before the request was sent. Fixed. The walk is guarded and the recorded body is withheld on failure, with a test.

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because duplicate JSON keys can bypass secret masking and expose credentials in the default preview and copy action without Reveal.

1 open issue
1 resolved since last review

Review effort: Balanced

… masked (#3077)

JSON.parse keeps the last of duplicate keys, so a body whose sensitive
key resolved to an empty value showed its raw text, earlier duplicate
included. Such a body is now displayed in its parsed form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 4 (no inline comments; headline finding fixed in 375a88b):

  • Duplicate JSON keys could hide a secret from masking. JSON.parse keeps the last duplicate, so {"access_token":"s","access_token":""} had nothing to mask, and the raw text, s included, was shown. Fixed. A JSON body that names a sensitive key is now always displayed in its parsed form; ordinary bodies are still shown exactly as received. Tests added in maskSecrets.test.ts and NetworkEntry.test.tsx.

Copilot AI 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.

🔵 Needs a closer look

Critical secret-exposure risks spanning duplicate-key JSON handling, clipboard behavior, and synthetic Protocol responses require human assessment.

1 open issue

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed. Round 5 posted no inline comments and an empty open-issue list. Its headline names areas but no concrete defect: duplicate-key JSON was fixed in round 4; the copy button copies the displayed (masked unless revealed) text; and the Protocol tab is outside this PR. So the loop stops on a round with no in-scope findings. Rounds 1–4 were fixed in 5e0f418, c0e474f, b354971 and 375a88b.

@cliffhall
cliffhall merged commit b1cad2e into v2/main Nov 30, 2026
11 checks passed
@cliffhall
cliffhall deleted the v2/fix/3077-reveal-instead-of-early-redaction branch November 30, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

2 participants