fix(core): keep launchd service logs outside protected Downloads

This commit is contained in:
DCCONSTRUCTIONS
2026-09-25 16:40:45 +03:00
parent 2e5d52521f
commit a7c64e009d
8 changed files with 230 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
"""Launch-time journals belong in Library/Logs, outside protected Documents/Downloads.
launchd opens these before the application starts, so an application's existing
folder grant cannot authorize xpcproxy to open a journal inside the checkout.
This does not move evidence or change access to the application's data directory.
"""
import os
import stat
from pathlib import Path
def launchd_log_path(name: str) -> Path:
if Path(name).name != name or not name.endswith(".log"):
raise ValueError("A single journal filename is required")
return Path.home() / "Library/Logs/NODE.DC/MissionCore" / name
def prepare_launchd_log(path: Path) -> None:
if path != launchd_log_path(path.name):
raise ValueError("Unexpected launch journal directory")
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
info = path.parent.lstat()
if path.parent.resolve() != path.parent or info.st_uid != os.getuid():
raise ValueError("Launch journal directory must be owned and canonical")
descriptor = os.open(path, os.O_CREAT | os.O_APPEND | os.O_WRONLY | os.O_NOFOLLOW, 0o600)
try:
info = os.fstat(descriptor)
if not stat.S_ISREG(info.st_mode) or info.st_uid != os.getuid():
raise ValueError("Launch journal must be an owned regular file")
os.fchmod(descriptor, 0o600)
finally:
os.close(descriptor)