Skip to content

Commit

Permalink
Better check for xdg-dir access (#222)
Browse files Browse the repository at this point in the history
* Better check for xdg-dir access

* Skip xdg-config/kdeglobals:ro
  • Loading branch information
barthalion authored Dec 7, 2023
1 parent eb99b17 commit e1b4457
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions flatpak_builder_lint/checks/finish_args.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from collections import defaultdict
from typing import Optional, Set

Expand All @@ -24,11 +25,16 @@ def _validate(self, appid: Optional[str], finish_args: dict[str, Set[str]]) -> N
self.errors.add("finish-args-fallback-x11-without-wayland")

for xdg_dir in ["xdg-data", "xdg-config", "xdg-cache"]:
if xdg_dir in finish_args["filesystem"]:
self.errors.add(f"finish-args-arbitrary-{xdg_dir}-access")

regexp_arbitrary = f"^{xdg_dir}(:(create|rw|ro)?)?$"
regexp_unnecessary = f"^{xdg_dir}(\\/.*)?(:(create|rw|ro)?)?$"
for fs in finish_args["filesystem"]:
if fs.startswith(f"{xdg_dir}/") and fs.endswith(":create"):
# This is inherited by apps from the KDE runtime
if fs == "xdg-config/kdeglobals:ro":
continue

if re.match(regexp_arbitrary, fs):
self.errors.add(f"finish-args-arbitrary-{xdg_dir}-access")
elif re.match(regexp_unnecessary, fs):
self.errors.add(f"finish-args-unnecessary-{xdg_dir}-access")

for fs in finish_args["filesystem"]:
Expand Down
2 changes: 2 additions & 0 deletions tests/manifests/finish_args.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"--device=shm",
"--filesystem=home",
"--filesystem=host",
"--filesystem=xdg-cache:create",
"--filesystem=xdg-config/autostart",
"--filesystem=xdg-config/kdeglobals:ro",
"--filesystem=xdg-data",
"--filesystem=xdg-data/foo:create",
"--own-name=org.flathub.finish_args",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_manifest_finish_args() -> None:
"finish-args-arbitrary-autostart-access",
"finish-args-arbitrary-dbus-access",
"finish-args-arbitrary-xdg-data-access",
"finish-args-arbitrary-xdg-cache-access",
"finish-args-broken-kde-tray-permission",
"finish-args-flatpak-spawn-access",
"finish-args-incorrect-dbus-gvfs",
Expand Down Expand Up @@ -88,7 +89,6 @@ def test_manifest_finish_args() -> None:
def test_manifest_finish_args_issue_33() -> None:
ret = run_checks("tests/manifests/own_name_substring.json")
found_errors = set(ret["errors"])
print(found_errors)
assert "finish-args-unnecessary-appid-own-name" not in found_errors

ret = run_checks("tests/manifests/own_name_substring2.json")
Expand Down

0 comments on commit e1b4457

Please sign in to comment.