#!/bin/bash # Run a command in a private D-Bus session whose accessibility bus lives in a # private runtime directory, so tests can never touch the user's live # accessibility bus. Refuses to run the command if isolation cannot be proven. # Usage: private_session.sh COMMAND... # # Background: at-spi-bus-launcher puts its socket at # $XDG_RUNTIME_DIR/at-spi/bus_, and advertises it in the AT_SPI_BUS # property of its display's root window, which libatspi checks first. A # launcher that sees the user's XDG_RUNTIME_DIR takes over the user's socket # path and deletes it on exit; one that sees DISPLAY=:0 pulls the user's newly # connecting applications onto the test bus. So the private D-Bus session gets # a private runtime directory and no display at all; commands that need a # display start their own (xvfb-run) inside it. set -u if [[ $# -lt 1 ]]; then echo "Usage: $0 COMMAND..." exit 2 fi userDisplay="${DISPLAY:-}" privateRuntime="$(mktemp -d)" chmod 700 "$privateRuntime" trap 'rm -rf "$privateRuntime"' EXIT export XDG_RUNTIME_DIR="$privateRuntime" unset AT_SPI_BUS_ADDRESS DISPLAY WAYLAND_DISPLAY export userDisplay # shellcheck disable=SC2016 # expanded by the inner shell dbus-run-session -- bash -c ' busAddress="$(gdbus call --session --dest org.a11y.Bus --object-path /org/a11y/bus \ --method org.a11y.Bus.GetAddress 2> /dev/null)" case "$busAddress" in *"unix:path=$XDG_RUNTIME_DIR/"*) ;; *) echo "Refusing to run: the accessibility bus is not private ($busAddress)" >&2 exit 90 ;; esac # Tripwire while the launcher is running (it removes the property on exit): # the user display must never advertise the test bus. if [[ -n "$userDisplay" ]] && DISPLAY="$userDisplay" xprop -root AT_SPI_BUS 2> /dev/null | grep -q "$XDG_RUNTIME_DIR"; then echo "Refusing to run: the user display advertises the test accessibility bus" >&2 exit 91 fi gdbus call --session --dest org.a11y.Bus --object-path /org/a11y/bus \ --method org.freedesktop.DBus.Properties.Set org.a11y.Status IsEnabled "" > /dev/null "$@" ' private_session_inner "$@" sessionStatus=$? exit "$sessionStatus"