Skip to content

Commit 8653c8f

Browse files
fix(server): keep sensitive values out of settings reads, startup logs and preview snapshots (pingdotgg#20446)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent aa28bde commit 8653c8f

11 files changed

Lines changed: 558 additions & 44 deletions

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ function makeSession(frame?: ReturnType<typeof makeFrame>) {
8080
if (method === "Page.getLayoutMetrics") return { cssVisualViewport: { pageX: 0, pageY: 0 } };
8181
if (method === "Page.captureScreenshot") return { data: "ZnJhbWU=" };
8282
if (method === "Page.getFrameTree") return { frameTree: { frame: { id: "main" } } };
83-
if (method === "Page.createIsolatedWorld") return { executionContextId: 7 };
83+
// Snapshots read password fields from their own isolated world in each frame.
84+
if (method === "Page.createIsolatedWorld") {
85+
return {
86+
executionContextId: (input as { worldName?: string }).worldName === "t3-preview" ? 1 : 7,
87+
};
88+
}
89+
if (method === "Runtime.evaluate" && (input as { contextId?: number }).contextId === 1) {
90+
return { result: { value: [] } };
91+
}
8492
if (method === "Page.addScriptToEvaluateOnNewDocument") frame?.recording.resolve();
8593
if (method === "Input.dispatchKeyEvent" && (input as { commands?: unknown }).commands) {
8694
if (focusedFrame) focusedFrame.copy = keyCopy || focusedFrame.copy;

‎apps/server/src/preview/ServerBrowserPage.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,60 @@ describe("server browser element refs", () => {
124124
expect(await page.getByRole("textbox", { name: "parent" }).inputValue()).toBe("");
125125
});
126126

127+
it("shows dotted fields as dots wherever their value appears, keeping text values and refs", async () => {
128+
await page.setContent(`
129+
<table><tr><td>password:</td><td><input id="pw" type="password" aria-label="Password"></td></tr></table>
130+
<input aria-label="Username" value="maria">
131+
<input type="password" aria-label='saved" [ref=e2]: x' placeholder="hint" value="saved-pass">
132+
<input type="password" role="combobox" aria-label="Code" value="role-pass">
133+
<input aria-label="PIN" style="-webkit-text-security: disc" value="styled-pass">
134+
<div contenteditable style="-webkit-text-security: disc">editable-pass</div>
135+
<iframe srcdoc="<input type=password aria-label=child value=frame-pass>"></iframe>
136+
<iframe id="blank" src="javascript:false"></iframe>
137+
<p>Order styled-pass-2</p>
138+
<script>
139+
// A frame that never commits a document, filled by its parent.
140+
blank.contentDocument.body.innerHTML = "<input type=password aria-label=blank value=blank-pass>";
141+
// Page script can't change the value the snapshot sees.
142+
Object.defineProperty(HTMLInputElement.prototype, "value", { get: () => "" });
143+
</script>`);
144+
await page.frameLocator("iframe[srcdoc]").getByRole("textbox").waitFor();
145+
await ServerBrowserPage.type(page, { locator: "#pw", text: "typed-pass" });
146+
const result = await takeSnapshot();
147+
const tree = String(result.accessibilityTree);
148+
expect(tree).toContain('textbox "blank"');
149+
expect(tree).not.toMatch(
150+
/typed-pass|saved-pass|role-pass|styled-pass|editable-pass|frame-pass|blank-pass/,
151+
);
152+
expect(result.visibleText).not.toContain("editable-pass");
153+
// Page text masks the same values, so it can't be compared against the tree.
154+
expect(result.visibleText).toContain("Order ••••••••-2");
155+
expect(tree).toMatch(/row "password: •+"/);
156+
expect(tree).toMatch(/textbox "Username" [^\n]*: maria$/m);
157+
const line = tree.split("\n").find((line) => line.includes('textbox "Password"'));
158+
expect(line).toMatch(/: •+$/);
159+
await ServerBrowserPage.type(page, { locator: locators(line)[0]!, text: "next", clear: true });
160+
expect(await page.locator("#pw").inputValue()).toBe("next");
161+
});
162+
163+
it("masks dotted values in page text next to punctuation, with odd spaces, and at the cut", async () => {
164+
await page.setContent(`
165+
<input type="password" aria-label="PIN" value="123">
166+
<input type="password" aria-label="Phrase" value="open&nbsp;sesame">
167+
<p>PIN: 123. Code (123) id 1234</p>
168+
<p>open&nbsp;sesame</p>`);
169+
const text = (await takeSnapshot()).visibleText;
170+
expect(text).toContain("PIN: ••••••••. Code (••••••••) id 1234");
171+
expect(text).not.toMatch(/open|sesame/);
172+
await page.setContent(`
173+
<p>${"x".repeat(19_995)}long-secret</p>
174+
<input type="password" aria-label="Long" value="long-secret">`);
175+
const cut = (await takeSnapshot()).visibleText;
176+
expect(cut.length).toBe(20_000);
177+
// Masked before the cut, so no prefix of the value is left.
178+
expect(cut.slice(-8)).toBe("xxx•••••");
179+
});
180+
127181
it("rejects refs from another tab", async () => {
128182
await page.setContent("<button>same label</button>");
129183
const locator = buttonLocator((await takeSnapshot()).accessibilityTree, "same label");

0 commit comments

Comments
 (0)