tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 112722bb97e564d07e3d0c306535fb016027b017
parent 36a152949e5e2717120dbc17c39315dd619ae5e6
Author: James Teh <jteh@mozilla.com>
Date:   Mon,  8 Dec 2025 06:42:28 +0000

Bug 2001531: about:keyboard: Don't allow printable characters without modifiers. r=mossop,fluent-reviewers,bolsson

Differential Revision: https://phabricator.services.mozilla.com/D273951

Diffstat:
Mbrowser/components/customkeys/CustomKeysParent.sys.mjs | 6++++++
Mbrowser/components/customkeys/content/customkeys.js | 5+++++
Mbrowser/components/customkeys/tests/browser/browser_aboutKeyboard.js | 14++++++++++++++
Mbrowser/locales/en-US/browser/customkeys.ftl | 3+++
4 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/browser/components/customkeys/CustomKeysParent.sys.mjs b/browser/components/customkeys/CustomKeysParent.sys.mjs @@ -182,8 +182,14 @@ export class CustomKeysParent extends JSWindowActorParent { this.sendAsyncMessage("CustomKeys:CapturedKey", data); return; } + data.isValid = true; if (event.key.length == 1) { data.key = event.key.toUpperCase(); + if (!modifiers.length || (event.shiftKey && modifiers.length == 1)) { + // This is a printable character; e.g. a letter, number or punctuation + // mark. That's not a valid shortcut key. + data.isValid = false; + } } else { data.keycode = ShortcutUtils.getKeycodeAttribute(event.key); } diff --git a/browser/components/customkeys/content/customkeys.js b/browser/components/customkeys/content/customkeys.js @@ -152,6 +152,11 @@ async function onKey({ data }) { input.select(); return; } + if (!data.isValid) { + input.value = await document.l10n.formatValue("customkeys-key-invalid"); + input.select(); + return; + } if (await maybeHandleConflict(data)) { const newData = await RPMSendQuery("CustomKeys:ChangeKey", data); updateKey(row, newData); diff --git a/browser/components/customkeys/tests/browser/browser_aboutKeyboard.js b/browser/components/customkeys/tests/browser/browser_aboutKeyboard.js @@ -242,6 +242,13 @@ addAboutKbTask(async function testChange(tab) { 1, "Correct telemetry for change action" ); + info(`Pressing ${consts.unusedKey}`); + EventUtils.synthesizeKey(consts.unusedKey, {}, window); + await SpecialPowers.spawn(tab, [consts], async _consts => { + await content.selected; + is(content.input.value, "Invalid", "Input shows invalid"); + content.selected = ContentTaskUtils.waitForEvent(content.input, "select"); + }); info(`Pressing ${consts.unusedModifiersDisplay}`); EventUtils.synthesizeKey(...consts.unusedModifiersArgs, window); await SpecialPowers.spawn(tab, [consts], async _consts => { @@ -251,6 +258,13 @@ addAboutKbTask(async function testChange(tab) { _consts.unusedModifiersDisplay, "Input shows modifiers as they're pressed" ); + content.selected = ContentTaskUtils.waitForEvent(content.input, "select"); + }); + info(`Pressing Shift+${consts.unusedKey}`); + EventUtils.synthesizeKey(consts.unusedKey, { shiftKey: true }, window); + await SpecialPowers.spawn(tab, [consts], async _consts => { + await content.selected; + is(content.input.value, "Invalid", "Input shows invalid"); info(`Pressing ${_consts.unusedDisplay}`); content.focused = ContentTaskUtils.waitForEvent(content.change, "focus"); }); diff --git a/browser/locales/en-US/browser/customkeys.ftl b/browser/locales/en-US/browser/customkeys.ftl @@ -40,3 +40,6 @@ customkeys-nav-reload-skip-cache = Reload (Override Cache) customkeys-nav-stop = Stop customkeys-caution-message = This feature is experimental and may not work as expected. + +# Displayed in the new key field when the key that was pressed isn't valid. +customkeys-key-invalid = Invalid