diff --git a/src/moongreet/config.py b/src/moongreet/config.py index 2fd6808..d7c1251 100644 --- a/src/moongreet/config.py +++ b/src/moongreet/config.py @@ -1,15 +1,12 @@ # ABOUTME: Configuration loading from moongreet.toml. # ABOUTME: Parses appearance and behavior settings with wallpaper path resolution. -import re import tomllib from contextlib import AbstractContextManager from dataclasses import dataclass from importlib.resources import as_file, files from pathlib import Path -VALID_THEME_NAME = re.compile(r"^[A-Za-z0-9_-]+$") - DEFAULT_CONFIG_PATHS = [ Path("/etc/moongreet/moongreet.toml"), ] @@ -56,7 +53,7 @@ def load_config(config_path: Path | None = None) -> Config: config.background = bg_path gtk_theme = appearance.get("gtk-theme") - if gtk_theme and VALID_THEME_NAME.match(gtk_theme): + if gtk_theme: config.gtk_theme = gtk_theme return config diff --git a/src/moongreet/users.py b/src/moongreet/users.py index cf1f508..7af37a2 100644 --- a/src/moongreet/users.py +++ b/src/moongreet/users.py @@ -2,12 +2,9 @@ # ABOUTME: Provides User dataclass and helper functions for the greeter UI. import configparser -import re from dataclasses import dataclass 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"} MIN_UID = 1000 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"): theme = config.get("Settings", "gtk-theme-name") - # Validate against path traversal — only allow safe theme names - if theme and VALID_THEME_NAME.match(theme): + if theme: return theme return None diff --git a/tests/test_config.py b/tests/test_config.py index 2cdd64b..0b7f872 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -62,16 +62,6 @@ class TestLoadConfig: 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: toml_file = tmp_path / "moongreet.toml" diff --git a/tests/test_users.py b/tests/test_users.py index f357f8c..09bae44 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -186,27 +186,18 @@ class TestGetUserGtkTheme: assert result is None - def test_handles_interpolation_characters(self, tmp_path: Path) -> None: - """Theme names with % characters are rejected by validation.""" + def test_passes_theme_with_special_characters(self, tmp_path: Path) -> None: + """Theme names with special characters are passed through to GTK.""" 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=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) - assert result is None - - 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 + assert result == "catppuccin-mocha-lavender-standard+default" def test_ignores_symlinked_accountsservice_icon(self, tmp_path: Path) -> None: """AccountsService icon as symlink should be ignored to prevent traversal."""