config.def.h: add an option allowwindowops, by default off (secure)

Similar to the xterm AllowWindowOps option, this is an option to allow or
disallow certain (non-interactive) operations that can be insecure or
exploited.

NOTE: xsettitle() is not guarded by this because st does not support printing
the window title. Else this could be exploitable (arbitrary code execution).
Similar problems have been found in the past in other terminal emulators.

The sequence for base64-encoded clipboard copy is now guarded because it allows
a sequence written to the terminal to manipulate the clipboard of the running
user non-interactively, for example:

printf '\x1b]52;0;ZWNobyBoaQ0=\a'
This commit is contained in:
Hiltjo Posthuma 2020-05-30 21:56:18 +02:00
parent 0f8b40652b
commit a2a704492b
3 changed files with 6 additions and 1 deletions

View file

@ -43,6 +43,10 @@ static unsigned int tripleclicktimeout = 600;
/* alt screens */ /* alt screens */
int allowaltscreen = 1; int allowaltscreen = 1;
/* allow certain non-interactive (insecure) window operations such as:
setting the clipboard text */
int allowwindowops = 0;
/* /*
* draw latency range in ms - from new content/keypress/etc until drawing. * draw latency range in ms - from new content/keypress/etc until drawing.
* within this range, st draws when content stops arriving (idle). mostly it's * within this range, st draws when content stops arriving (idle). mostly it's

2
st.c
View file

@ -1861,7 +1861,7 @@ strhandle(void)
xsettitle(strescseq.args[1]); xsettitle(strescseq.args[1]);
return; return;
case 52: case 52:
if (narg > 2) { if (narg > 2 && allowwindowops) {
dec = base64dec(strescseq.args[2]); dec = base64dec(strescseq.args[2]);
if (dec) { if (dec) {
xsetsel(dec); xsetsel(dec);

1
st.h
View file

@ -118,6 +118,7 @@ extern char *stty_args;
extern char *vtiden; extern char *vtiden;
extern wchar_t *worddelimiters; extern wchar_t *worddelimiters;
extern int allowaltscreen; extern int allowaltscreen;
extern int allowwindowops;
extern char *termname; extern char *termname;
extern unsigned int tabspaces; extern unsigned int tabspaces;
extern unsigned int defaultfg; extern unsigned int defaultfg;