Skip to content

Commit af7ad0d

Browse files
cliffhallclaude
andcommitted
test(network): address #1387 fourth-pass nits — content-type contract, key, form test (#1386)
Fourth-pass review (LGTM) — minor, non-blocking items: - Documented the content-type matching contract on `maskSecretsInBody`: substring match (`*json*` / `*x-www-form-urlencoded*`), and we trust the wire's own label (a mislabeled body renders raw — acceptable for the screen-share threat model) (finding #1). - Key `<BodyPreview>` by content-type + body (not body alone) so a header-only change would also reset the reveal state (finding #3; not reachable today). - Storybook `AuthSuccess`: assert revealed count `>=` reveal-button count to mirror the `hidden >= 2` check, so adding a non-masked body later can't drift the assertion silently (finding #4). - Added a `NetworkEntry` unit test for form-encoded request-body masking (code/code_verifier) — previously exercised only via the Storybook play. Finding #2 (silent decodeURIComponent fallback on malformed keys) acknowledged as a known quirk outside the threat model; no change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent e499830 commit af7ad0d

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

‎clients/web/src/components/groups/NetworkEntry/NetworkEntry.stories.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ export const AuthSuccess: Story = {
125125
for (const button of revealButtons) {
126126
await userEvent.click(button);
127127
}
128-
await expect(canvas.getAllByText("Secrets revealed").length).toBe(
129-
revealButtons.length,
130-
);
128+
await expect(
129+
canvas.getAllByText("Secrets revealed").length,
130+
).toBeGreaterThanOrEqual(revealButtons.length);
131131
await expect(canvasElement.textContent).toContain("eyJhbGciOiJSUzI1");
132132
},
133133
};

‎clients/web/src/components/groups/NetworkEntry/NetworkEntry.test.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,37 @@ describe("NetworkEntry", () => {
233233
expect(container.textContent).not.toContain("super-secret-token");
234234
});
235235

236+
it("masks a form-encoded request body (code/verifier) until revealed", async () => {
237+
const user = userEvent.setup();
238+
const authEntry: FetchRequestEntry = {
239+
...baseEntry,
240+
category: "auth",
241+
url: "http://localhost:3001/token",
242+
requestHeaders: { "content-type": "application/x-www-form-urlencoded" },
243+
requestBody:
244+
"grant_type=authorization_code&code=SECRETCODE&code_verifier=SECRETVERIFIER",
245+
responseStatus: undefined,
246+
responseStatusText: undefined,
247+
responseHeaders: undefined,
248+
responseBody: undefined,
249+
};
250+
const { container } = renderWithMantine(
251+
<NetworkEntry entry={authEntry} isListExpanded={true} />,
252+
);
253+
expect(screen.getByText("Secrets hidden")).toBeInTheDocument();
254+
expect(container.textContent).not.toContain("SECRETCODE");
255+
expect(container.textContent).not.toContain("SECRETVERIFIER");
256+
expect(container.textContent).toContain("••••••••");
257+
// Non-secret param stays visible.
258+
expect(container.textContent).toContain("grant_type=authorization_code");
259+
260+
await user.click(
261+
screen.getByRole("button", { name: "Reveal secrets in body" }),
262+
);
263+
expect(container.textContent).toContain("SECRETCODE");
264+
expect(container.textContent).toContain("SECRETVERIFIER");
265+
});
266+
236267
it("does not add a reveal toggle for non-secret bodies", () => {
237268
renderWithMantine(<NetworkEntry entry={baseEntry} isListExpanded={true} />);
238269
expect(screen.queryByText("Secrets hidden")).not.toBeInTheDocument();

‎clients/web/src/components/groups/NetworkEntry/NetworkEntry.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ function BodyPreview({
141141
}) {
142142
// Reveal state for masked secrets. Hooks run before any early return so the
143143
// order stays stable across the too-large / has-secrets branches. The reveal
144-
// state resets when the body content changes because callers key
145-
// `<BodyPreview>` by `body` (remounting on swap), so a previously-revealed
146-
// view never persists across a content change.
144+
// state resets when the body or its content-type changes because callers key
145+
// `<BodyPreview>` by both (remounting on swap), so a previously-revealed view
146+
// never persists across a content (or masking) change.
147147
const [revealed, setRevealed] = useState(false);
148148

149149
const tooLarge = body.length > MAX_INLINE_BODY_CHARS;
@@ -242,7 +242,7 @@ export function NetworkEntry({ entry, isListExpanded }: NetworkEntryProps) {
242242
Request Body
243243
</Text>
244244
<BodyPreview
245-
key={entry.requestBody}
245+
key={`${entry.requestHeaders["content-type"] ?? ""}|${entry.requestBody}`}
246246
body={entry.requestBody}
247247
contentType={entry.requestHeaders["content-type"]}
248248
/>
@@ -263,7 +263,7 @@ export function NetworkEntry({ entry, isListExpanded }: NetworkEntryProps) {
263263
</Text>
264264
{entry.responseBody ? (
265265
<BodyPreview
266-
key={entry.responseBody}
266+
key={`${entry.responseHeaders?.["content-type"] ?? ""}|${entry.responseBody}`}
267267
body={entry.responseBody}
268268
contentType={entry.responseHeaders?.["content-type"]}
269269
/>

‎clients/web/src/utils/maskSecrets.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ function maskFormBody(body: string): MaskResult {
149149
* Bodies with no sensitive keys return unchanged with `hasSecrets: false` so
150150
* callers can skip the reveal affordance. The caller keeps the original string
151151
* for the revealed view.
152+
*
153+
* `contentType` is matched by substring (`*json*`, `*x-www-form-urlencoded*`)
154+
* and we trust the wire's own label — a body mislabeled by the server (e.g.
155+
* JSON sent as `text/html`) takes the "no masking" branch and renders raw.
156+
* That's acceptable: the threat model is a screen-share viewer, not an
157+
* adversary who controls the response's content-type.
152158
*/
153159
export function maskSecretsInBody(
154160
body: string,

0 commit comments

Comments
 (0)