Skip to content

Commit f7849b0

Browse files
committed
fix(tui): keep secret prompt value out of selection copies
Copy-on-select and Ctrl+C resolve the selection through TextareaRenderable.getSelectedText(), which read the real buffer. A masked field now returns an empty string from that method so no copy path can leak the value.
1 parent fe7e4aa commit f7849b0

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎packages/tui/src/component/secret-textarea.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class SecretTextareaRenderable extends TextareaRenderable {
2929
this.requestRender()
3030
}
3131

32+
override getSelectedText(): string {
33+
// Copy-on-select and Ctrl+C resolve the selection through this method, so a
34+
// masked field must never hand out its value there.
35+
if (this._secret) return ""
36+
return super.getSelectedText()
37+
}
38+
3239
protected override renderSelf(buffer: OptimizedBuffer) {
3340
super.renderSelf(buffer)
3441
if (!this._secret) return

‎packages/tui/test/cli/tui/dialog-prompt.test.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ test("dialog prompt masks a secret value without echoing it", async () => {
215215
const frame = await prompt.app.waitForFrame((value) => value.includes("*****"))
216216
expect(frame).not.toContain("draft")
217217

218+
// Selection must not resolve the masked value either.
219+
prompt.app.mockInput.pressKey("END")
220+
prompt.app.mockInput.pressArrow("left", { shift: true })
221+
expect(prompt.app.renderer.getSelection()?.getSelectedText()).toBe("")
222+
expect(textarea.plainText).toBe("draft")
223+
218224
prompt.app.mockInput.pressEnter()
219225

220226
expect(confirmed).toEqual(["draft"])
@@ -277,6 +283,11 @@ test("dialog prompt echoes the value when secret is not set", async () => {
277283
const frame = await prompt.app.waitForFrame((value) => value.includes("draft"))
278284
expect(frame).toContain("draft")
279285

286+
// A normal prompt still exposes its selection.
287+
prompt.app.mockInput.pressKey("END")
288+
prompt.app.mockInput.pressArrow("left", { shift: true })
289+
expect(prompt.app.renderer.getSelection()?.getSelectedText()).toBe("t")
290+
280291
prompt.app.mockInput.pressEnter()
281292

282293
expect(confirmed).toEqual(["draft"])

0 commit comments

Comments
 (0)