Skip to content

Commit 0ceec3a

Browse files
committed
dix: Opt-in keyboard isolation from unfocused windows.
Adds "IsolateKeyboard" option to "ServerFlags" section in "xorg.conf". Disabled by default. If enabled: disallows not grabbed raw events, prevents sending keyboard input events to clients with unfocused windows and clients without window to prevent keylogging. If disabled: follows default X behavior. Signed-off-by: itz-me-zappex <85901674+itz-me-zappex@users.noreply.github.com>
1 parent 8a9a14a commit 0ceec3a

File tree

9 files changed

+49
-0
lines changed

9 files changed

+49
-0
lines changed

dix/events.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,15 @@ DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
24892489
if (grab)
24902490
DeliverGrabbedEvent((InternalEvent *) ev, device, FALSE);
24912491

2492+
/*
2493+
* To prevent keylogging, not grabbed event should not be sent
2494+
* to any client.
2495+
*/
2496+
if (globalIsolateKeyboard) {
2497+
free(xi);
2498+
return;
2499+
}
2500+
24922501
filter = GetEventFilter(device, xi);
24932502

24942503
DIX_FOR_EACH_SCREEN({
@@ -2828,6 +2837,25 @@ static int
28282837
DeliverOneEvent(InternalEvent *event, DeviceIntPtr dev, enum InputLevel level,
28292838
WindowPtr win, Window child, GrabPtr grab)
28302839
{
2840+
/*
2841+
* Deliver keyboard events only if client is focused.
2842+
* Even if it does not have a window, that means unfocused.
2843+
* Needed to prevent keylogging.
2844+
*/
2845+
if (globalIsolateKeyboard) {
2846+
WindowPtr focus = inputInfo.keyboard->focus->win;
2847+
2848+
if (focus != win) {
2849+
switch (event->any.type) {
2850+
case ET_KeyPress:
2851+
case ET_KeyRelease:
2852+
return 0;
2853+
default:
2854+
break;
2855+
}
2856+
}
2857+
}
2858+
28312859
xEvent *xE = NULL;
28322860
int count = 0;
28332861
int deliveries = 0;

dix/globals.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,5 @@ int monitorResolution = 0;
122122

123123
Bool explicit_display = FALSE;
124124
char *ConnectionInfo;
125+
126+
Bool globalIsolateKeyboard = FALSE;

hw/xfree86/common/xf86Config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ typedef enum {
657657
FLAG_IGLX,
658658
FLAG_DEBUG,
659659
FLAG_ALLOW_BYTE_SWAPPED_CLIENTS,
660+
FLAG_ISOLATEKEYBOARD,
660661
} FlagValues;
661662

662663
/**
@@ -718,6 +719,8 @@ static OptionInfoRec FlagOptions[] = {
718719
{0}, FALSE},
719720
{FLAG_ALLOW_BYTE_SWAPPED_CLIENTS, "AllowByteSwappedClients", OPTV_BOOLEAN,
720721
{0}, FALSE},
722+
{FLAG_ISOLATEKEYBOARD, "IsolateKeyboard", OPTV_BOOLEAN,
723+
{0}, FALSE},
721724
{-1, NULL, OPTV_NONE,
722725
{0}, FALSE},
723726
};
@@ -754,6 +757,9 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
754757
xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap);
755758
xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom);
756759

760+
xf86GetOptValBool(FlagOptions, FLAG_ISOLATEKEYBOARD, &xf86Info.isolateKeyboard);
761+
globalIsolateKeyboard = xf86Info.isolateKeyboard;
762+
757763
xf86GetOptValBool(FlagOptions, FLAG_IGNORE_ABI, &xf86Info.ignoreABI);
758764
if (xf86Info.ignoreABI) {
759765
LogMessageVerb(X_CONFIG, 1, "Ignoring ABI Version\n");

hw/xfree86/common/xf86Globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ xf86InfoRec xf86Info = {
131131
.autoAddGPU = FALSE,
132132
#endif
133133
.autoBindGPU = TRUE,
134+
.isolateKeyboard = FALSE,
134135
};
135136

136137
const char *xf86ConfigFile = NULL;

hw/xfree86/common/xf86Privstr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ typedef struct {
9494
Bool autoAddGPU;
9595
const char *debug;
9696
Bool autoBindGPU;
97+
98+
Bool isolateKeyboard;
9799
} xf86InfoRec, *xf86InfoPtr;
98100

99101
/* ISC's cc can't handle ~ of UL constants, so explicitly type cast them. */

hw/xfree86/man/xorg.conf.man

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,11 @@ Unset by default.
687687
.TP 7
688688
.BI "Option \*qAllowByteSwappedClients\*q \*q" boolean \*q
689689
Allow clients with a different byte-order than the server. Disabled by default.
690+
.TP 7
691+
.BI "Option \*qIsolateKeyboard\*q \*q" boolean \*q
692+
Disallows all not grabbed raw events and keyboard input events to both
693+
unfocused windows and clients without window to prevent keylogging.
694+
Disabled by default.
690695
.SH "MODULE SECTION"
691696
The
692697
.B Module

hw/xfree86/parser/Flags.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static const xf86ConfigSymTabRec ServerFlagsTab[] = {
8080
{SUSPENDTIME, "suspendtime"},
8181
{OFFTIME, "offtime"},
8282
{DEFAULTLAYOUT, "defaultserverlayout"},
83+
{ISOLATEKEYBOARD, "isolatekeyboard"},
8384
{-1, ""},
8485
};
8586

@@ -127,6 +128,7 @@ xf86parseFlagsSection(XF86ConfFlagsPtr ptr)
127128
case DISABLEMODINDEV:
128129
case MODINDEVALLOWNONLOCAL:
129130
case ALLOWMOUSEOPENFAIL:
131+
case ISOLATEKEYBOARD:
130132
{
131133
int i = 0;
132134

hw/xfree86/parser/xf86tokens.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ typedef enum {
107107
SUSPENDTIME,
108108
OFFTIME,
109109
DEFAULTLAYOUT,
110+
ISOLATEKEYBOARD,
110111

111112
/* Monitor tokens */
112113
MODEL,

include/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ extern _X_EXPORT int defaultColorVisualClass;
1212

1313
extern _X_EXPORT char *SeatId;
1414

15+
extern _X_EXPORT Bool globalIsolateKeyboard;
16+
1517
#endif /* !_XSERV_GLOBAL_H_ */

0 commit comments

Comments
 (0)