Risk 1/5 · Low
vesktop.sh
Result #2009
Comment
The change is mostly a launcher refactor, but it introduces a notable security regression: it now loads and tokenizes multiple user-controlled flag files from XDG config paths and passes their contents directly to Electron. That is expected for a launcher, but the new implementation also changes argument ordering and removes the previous explicit `@options@` handling and `--wayland` gating, which is not itself a security issue. The main concern is that the script now prints the exact flag file path being loaded and uses `read -ra` word-splitting on each line, which can alter quoting semantics and make it easier for a malicious local config file to inject arbitrary Electron flags. However, this is limited to the local user’s own config directory and does not create a privilege escalation or supply-chain compromise. No network access, root writes, or persistence mechanisms were added. Overall low risk.
@@ -2,38 +2,72 @@
set -e
_APPDIR="/usr/lib/@appname@"
_RUNNAME="${_APPDIR}/@runname@"
-_OPTIONS="@options@"
-export PATH="${_APPDIR}:${PATH}"
-export LD_LIBRARY_PATH="${_APPDIR}/swiftshader:${_APPDIR}/lib:${LD_LIBRARY_PATH}"
+
+# Base environment variables
export ELECTRON_IS_DEV=0
export ELECTRON_FORCE_IS_PACKAGED=true
export ELECTRON_DISABLE_SECURITY_WARNINGS=true
export NODE_ENV=production
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
-_FLAGS_FILE="${XDG_CONFIG_HOME}/@appname@-flags.conf"
+export LD_LIBRARY_PATH="${_APPDIR}/lib:${LD_LIBRARY_PATH}"
+
+# 1. Display System Optimization (X11 & Wayland)
+# Use 'auto' to allow modern Electron (v20+) to detect the best platform
+# This helps with Wayland window decorations, fractional scaling, and GPU acceleration
+export ELECTRON_OZONE_PLATFORM_HINT="${ELECTRON_OZONE_PLATFORM_HINT:-auto}"
+
+# 2. Desktop Environment (DE) Compatibility
+# Set CHROME_DESKTOP to match the .desktop file for correct taskbar icon grouping
+export CHROME_DESKTOP="@appname@.desktop"
+
+# Fix for Electron's trash implementation on different DEs
+case "${XDG_CURRENT_DESKTOP}" in
+ KDE)
+ export ELECTRON_TRASH="kioclient5"
+ ;;
+ GNOME)
+ export ELECTRON_TRASH="gio"
+ ;;
+ XFCE)
+ export ELECTRON_TRASH="gvfs-trash"
+ ;;
+ *)
+ # Default fallback
+ ;;
+esac
+
+# 3. Load user-defined flags
+# The script checks for flags in the following order (later files override/append to earlier ones):
+# 1. System-wide Electron flags: $XDG_CONFIG_HOME/electron-flags.conf
+# 2. Version-specific Electron flags: $XDG_CONFIG_HOME/electron@electronversion@-flags.conf
+# 3. App-specific global flags: $XDG_CONFIG_HOME/@appname@-flags.conf
+# 4. App-specific directory flags: $XDG_CONFIG_HOME/@cfgdirname@/@appname@-flags.conf
+_FLAG_SOURCES=(
+ "${XDG_CONFIG_HOME}/electron-flags.conf"
+ "${XDG_CONFIG_HOME}/electron@electronversion@-flags.conf"
+ "${XDG_CONFIG_HOME}/@appname@-flags.conf"
+ "${XDG_CONFIG_HOME}/@cfgdirname@/@appname@-flags.conf"
+)
+
declare -a flags
-if [[ -f "${_FLAGS_FILE}" ]]; then
- mapfile -t < "${_FLAGS_FILE}"
-fi
-for line in "${MAPFILE[@]}"; do
- if [[ ! "${line}" =~ ^[[:space:]]*#.* ]] && [[ -n "${line}" ]]; then
- flags+=("${line}")
- fi
-done
-_WAYLAND_OPTION=false
-for arg in "$@"; do
- if [[ "${arg}" == "--wayland" ]]; then
- _WAYLAND_OPTION=true
- break
+for _FLAGS_FILE in "${_FLAG_SOURCES[@]}"; do
+ if [[ -f "${_FLAGS_FILE}" ]]; then
+ echo "Loading flags from ${_FLAGS_FILE}"
+ while read -r line || [[ -n "$line" ]]; do
+ [[ "${line}" =~ ^[[:space:]]*#.* ]] || [[ -z "${line}" ]] || {
+ read -ra line_flags <<< "$line"
+ flags+=("${line_flags[@]}")
+ }
+ done < "${_FLAGS_FILE}"
fi
done
-if [[ "${_WAYLAND_OPTION}" == true ]]; then
- echo "Forcing Wayland"
- flags+=("--enable-features=UseOzonePlatform,WaylandWindowDecorations,VaapiVideoDecodeLinuxGL" "--ozone-platform=wayland")
+
+# 4. Sandbox and Execution Permissions
+# Disable sandbox if running as root without ELECTRON_RUN_AS_NODE
+_SANDBOX_ARG=()
+if [[ "${EUID}" -eq 0 ]] && [[ "${ELECTRON_RUN_AS_NODE}" != "1" ]]; then
+ _SANDBOX_ARG=("--no-sandbox")
fi
+
cd "${_APPDIR}"
-if [[ "${EUID}" -ne 0 ]] || [[ "${ELECTRON_RUN_AS_NODE}" ]]; then
- exec electron@electronversion@ "${_RUNNAME}" "${_OPTIONS}" "${flags[@]}" "$@" || exit $?
-else
- exec electron@electronversion@ "${_RUNNAME}" "${_OPTIONS}" --no-sandbox "${flags[@]}" "$@" || exit $?
-fi
\ No newline at end of file
+exec electron@electronversion@ "${flags[@]}" "${_SANDBOX_ARG[@]}" "${_RUNNAME}" "$@"
\ No newline at end of file