Session preload: leave programs a Chromium app starts from its own folder alone (#3121)

The browser flags were added to every program beside chrome-sandbox
that had no --type switch. Chrome's crash handler is such a program, so
it was started with --no-sandbox, rejected it and exited. A Chromium app
that starts a program from its own folder already passes that program
the arguments it needs, so those programs are left unchanged. Another
Chromium app started from it still gets the flags.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-24 00:12:02 -05:00
1 parent e349d2544e
commit a03ec8eb57
2 files changed
+36 -1

No files matched your search

+20 -1
View File
@@ -58,6 +58,25 @@ static int beside_chrome_sandbox(const char *path) {
return found; return found;
} }
static char *folder_of(const char *path) {
char *real = realpath(path, NULL);
char *slash = real ? strrchr(real, '/') : NULL;
if (slash) *slash = 0;
return real;
}
static int started_by_its_own_app(const char *path) {
char self[4096];
ssize_t n = readlink("/proc/self/exe", self, sizeof self - 1);
if (n <= 0) return 0;
self[n] = 0;
char *mine = folder_of(self), *theirs = folder_of(path);
int same = mine && theirs && !strcmp(mine, theirs) && beside_chrome_sandbox(self);
free(mine);
free(theirs);
return same;
}
static char *const *chromium_argv(const char *path, char *const argv[], char *const envp[]) { static char *const *chromium_argv(const char *path, char *const argv[], char *const envp[]) {
if (!path || !argv || !argv[0]) return argv; if (!path || !argv || !argv[0]) return argv;
int argc = 0, sandbox = 1, ozone = 0; int argc = 0, sandbox = 1, ozone = 0;
@@ -69,7 +88,7 @@ static char *const *chromium_argv(const char *path, char *const argv[], char *co
} }
const char *display = env_value(envp, "DISPLAY"); const char *display = env_value(envp, "DISPLAY");
int x11 = !ozone && display && *display; int x11 = !ozone && display && *display;
if ((!sandbox && !x11) || !beside_chrome_sandbox(path)) return argv; if ((!sandbox && !x11) || !beside_chrome_sandbox(path) || started_by_its_own_app(path)) return argv;
char **out = calloc((size_t)argc + 3, sizeof *out); char **out = calloc((size_t)argc + 3, sizeof *out);
if (!out) return argv; if (!out) return argv;
int n = 0; int n = 0;
+16
View File
@@ -122,6 +122,22 @@ class WebhelperPreloadTest(unittest.TestCase):
(root / "bin/app").touch() (root / "bin/app").touch()
self.assertEqual(self.argv(str(root / "bin/app")), [str(root / "bin/app"), "--no-sandbox"]) self.assertEqual(self.argv(str(root / "bin/app")), [str(root / "bin/app"), "--no-sandbox"])
def test_a_chromium_app_starting_a_program_from_its_own_folder_leaves_it_alone(self):
handler = self.chromium("chrome-app", "chrome_crashpad_handler")
browser = self.tmp / "chrome-app/chrome"
shutil.copy(self.program, browser)
out = subprocess.run([str(browser), handler, "--database=/tmp/x"], env={"TEST_DISPLAY": ":0"},
capture_output=True, text=True, check=True).stdout.splitlines()
self.assertEqual([handler, "--database=/tmp/x"], out)
def test_a_chromium_app_starting_another_chromium_app_still_flags_it(self):
other = self.chromium("other-app", "chrome")
editor = self.tmp / "editor-app/code"
self.chromium("editor-app", "code")
shutil.copy(self.program, editor)
out = subprocess.run([str(editor), other], env={}, capture_output=True, text=True, check=True).stdout.splitlines()
self.assertEqual([other, "--no-sandbox"], out)
def test_with_an_x_display_chromium_apps_use_x11(self): def test_with_an_x_display_chromium_apps_use_x11(self):
chrome = self.chromium("chromium-x11", "chrome") chrome = self.chromium("chromium-x11", "chrome")
self.assertEqual(self.argv(chrome, "--new-window", display=":0"), self.assertEqual(self.argv(chrome, "--new-window", display=":0"),