Why is `xhost` considered dangerous?

Viewed 1046

I've been using xhost from x11-xserver-utils, but looking at the package page it says:

" - xhost, a very dangerous program that you should never use;"

I haven't found a clear answer for the non-initiated: Why is xhost dangerous?

I've been using it so I can run programs with graphical user interfaces within docker containers in linux. Should I worry? I usually do it as follows:

xhost +
xhost local:root

docker run -it -v/tmp/.X11-unix -e DISPLAY=unix$DISPLAY image_name

Is there a known safe alternative to this?

1 Answers

The whole purpose of xhost is to broaden access to your X server (which amounts, more or less, to the desktop in modern-ish X-based systems). If used carelessly, you can grant access to processes you don't control -- perhaps processes owned by intruders -- to display things on, and interact with, your display. That interaction might amount to popping up spurious authentication dialogs, for example. There's the potential to consume keystrokes.

I suspect xhost was more of a risk when X-based systems were truly multi-user; that is, when multiple X terminals were connected to a single minicomputer. These days, access to your X server probably depends on access to your computer -- X desktops don't allow remote (network) log-in by default these days.

I still use xhost all the time on my personal computers, but I'd be reluctant to use it in any sort of production environment.

Concerning your docker example -- I don't see this as enormously risky. However, an alternative approach that I've used from time to time is to embed a VNC server in the docker image, and access it using a VNC viewer. You're essentially providing the image with a private X desktop, avoid the need to share. However, this is fiddly to set up, and the appearance isn't as nice as interacting directly with the desktop.

Related