fix: GTK-Theme-Validierung entfernt — GTK löst Theme-Namen selbst auf

Die Regex VALID_THEME_NAME blockierte Theme-Namen mit '+' (z.B.
catppuccin-mocha-lavender-standard+default). Da GTK den Theme-Namen
intern über Standardverzeichnisse auflöst, ist eigene Validierung
unnötig und kontraproduktiv.
This commit is contained in:
nevaforget 2026-03-26 15:37:02 +01:00
parent 3dfa596f9a
commit cab1997dff
4 changed files with 8 additions and 34 deletions

View File

@ -1,15 +1,12 @@
# ABOUTME: Configuration loading from moongreet.toml. # ABOUTME: Configuration loading from moongreet.toml.
# ABOUTME: Parses appearance and behavior settings with wallpaper path resolution. # ABOUTME: Parses appearance and behavior settings with wallpaper path resolution.
import re
import tomllib import tomllib
from contextlib import AbstractContextManager from contextlib import AbstractContextManager
from dataclasses import dataclass from dataclasses import dataclass
from importlib.resources import as_file, files from importlib.resources import as_file, files
from pathlib import Path from pathlib import Path
VALID_THEME_NAME = re.compile(r"^[A-Za-z0-9_-]+$")
DEFAULT_CONFIG_PATHS = [ DEFAULT_CONFIG_PATHS = [
Path("/etc/moongreet/moongreet.toml"), Path("/etc/moongreet/moongreet.toml"),
] ]
@ -56,7 +53,7 @@ def load_config(config_path: Path | None = None) -> Config:
config.background = bg_path config.background = bg_path
gtk_theme = appearance.get("gtk-theme") gtk_theme = appearance.get("gtk-theme")
if gtk_theme and VALID_THEME_NAME.match(gtk_theme): if gtk_theme:
config.gtk_theme = gtk_theme config.gtk_theme = gtk_theme
return config return config

View File

@ -2,12 +2,9 @@
# ABOUTME: Provides User dataclass and helper functions for the greeter UI. # ABOUTME: Provides User dataclass and helper functions for the greeter UI.
import configparser import configparser
import re
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
VALID_THEME_NAME = re.compile(r"^[A-Za-z0-9_-]+$")
NOLOGIN_SHELLS = {"/usr/sbin/nologin", "/sbin/nologin", "/bin/false", "/usr/bin/nologin"} NOLOGIN_SHELLS = {"/usr/sbin/nologin", "/sbin/nologin", "/bin/false", "/usr/bin/nologin"}
MIN_UID = 1000 MIN_UID = 1000
MAX_UID = 65533 MAX_UID = 65533
@ -106,8 +103,7 @@ def get_user_gtk_theme(config_dir: Path | None = None) -> str | None:
if config.has_option("Settings", "gtk-theme-name"): if config.has_option("Settings", "gtk-theme-name"):
theme = config.get("Settings", "gtk-theme-name") theme = config.get("Settings", "gtk-theme-name")
# Validate against path traversal — only allow safe theme names if theme:
if theme and VALID_THEME_NAME.match(theme):
return theme return theme
return None return None

View File

@ -62,16 +62,6 @@ class TestLoadConfig:
assert config.gtk_theme is None assert config.gtk_theme is None
def test_rejects_gtk_theme_with_path_traversal(self, tmp_path: Path) -> None:
toml_file = tmp_path / "moongreet.toml"
toml_file.write_text(
"[appearance]\n"
'gtk-theme = "../../etc/evil"\n'
)
config = load_config(toml_file)
assert config.gtk_theme is None
def test_resolves_relative_path_against_config_dir(self, tmp_path: Path) -> None: def test_resolves_relative_path_against_config_dir(self, tmp_path: Path) -> None:
toml_file = tmp_path / "moongreet.toml" toml_file = tmp_path / "moongreet.toml"

View File

@ -186,27 +186,18 @@ class TestGetUserGtkTheme:
assert result is None assert result is None
def test_handles_interpolation_characters(self, tmp_path: Path) -> None: def test_passes_theme_with_special_characters(self, tmp_path: Path) -> None:
"""Theme names with % characters are rejected by validation.""" """Theme names with special characters are passed through to GTK."""
gtk_dir = tmp_path / ".config" / "gtk-4.0" gtk_dir = tmp_path / ".config" / "gtk-4.0"
gtk_dir.mkdir(parents=True) gtk_dir.mkdir(parents=True)
settings = gtk_dir / "settings.ini" settings = gtk_dir / "settings.ini"
settings.write_text("[Settings]\ngtk-theme-name=My%Theme\n") settings.write_text(
"[Settings]\ngtk-theme-name=catppuccin-mocha-lavender-standard+default\n"
)
result = get_user_gtk_theme(config_dir=gtk_dir) result = get_user_gtk_theme(config_dir=gtk_dir)
assert result is None assert result == "catppuccin-mocha-lavender-standard+default"
def test_rejects_path_traversal_theme_name(self, tmp_path: Path) -> None:
"""Theme names with path traversal characters should be rejected."""
gtk_dir = tmp_path / ".config" / "gtk-4.0"
gtk_dir.mkdir(parents=True)
settings = gtk_dir / "settings.ini"
settings.write_text("[Settings]\ngtk-theme-name=../../../../etc/evil\n")
result = get_user_gtk_theme(config_dir=gtk_dir)
assert result is None
def test_ignores_symlinked_accountsservice_icon(self, tmp_path: Path) -> None: def test_ignores_symlinked_accountsservice_icon(self, tmp_path: Path) -> None:
"""AccountsService icon as symlink should be ignored to prevent traversal.""" """AccountsService icon as symlink should be ignored to prevent traversal."""