commit 4dbb815028e72538cafe34bbd4ee462ef44245e6
parent a7f825badc16c6b9d115bdc35e483d9b13de1e1c
Author: Alexandre Lissy <lissyx+mozillians@lissyx.dyndns.org>
Date: Wed, 19 Nov 2025 17:46:18 +0000
Bug 259356 - Update sandbox tests for XDG r=gcp
Differential Revision: https://phabricator.services.mozilla.com/D214377
Diffstat:
11 files changed, 216 insertions(+), 70 deletions(-)
diff --git a/security/sandbox/moz.build b/security/sandbox/moz.build
@@ -10,7 +10,9 @@ BROWSER_CHROME_MANIFESTS += [
"test/browser_bug1717599_XDG-CONFIG-HOME.toml",
"test/browser_profiler.toml",
"test/browser_snap.toml",
- "test/browser_xdg.toml",
+ "test/browser_xdg_default.toml",
+ "test/browser_xdg_mozLegacyHome.toml",
+ "test/browser_xdg_xdgConfigHome.toml",
]
with Files("**"):
diff --git a/security/sandbox/test/browser_content_sandbox_fs_tests.js b/security/sandbox/test/browser_content_sandbox_fs_tests.js
@@ -426,34 +426,33 @@ async function testFileAccessLinuxOnly() {
let configDir = GetHomeSubdir(".config");
const xdgConfigHome = Services.env.get("XDG_CONFIG_HOME");
-
- if (xdgConfigHome.length > 1) {
+ if (xdgConfigHome) {
configDir = GetDir(xdgConfigHome);
configDir.normalize();
-
- tests.push({
- desc: `$XDG_CONFIG_HOME (${configDir.path})`,
- ok: true,
- browser: webBrowser,
- file: configDir,
- minLevel: minHomeReadSandboxLevel(),
- func: readDir,
- });
}
- // $HOME/.config/ or $XDG_CONFIG_HOME/ should have rdonly access
tests.push({
- desc: `${configDir.path} dir`,
- ok: true,
+ desc: `$XDG_CONFIG_HOME (${configDir.path})`,
+ ok: true, // access should not be granted outside of XDG support
browser: webBrowser,
file: configDir,
minLevel: minHomeReadSandboxLevel(),
func: readDir,
});
+
+ tests.push({
+ desc: `XDG_CONFIG_HOME=${configDir.path} dir should have rdonly`,
+ ok: true, // should be allowed only if XDG support is there
+ browser: webBrowser,
+ file: configDir,
+ minLevel: minHomeReadSandboxLevel(),
+ func: readDir,
+ });
+
if (fileContentProcessEnabled) {
tests.push({
desc: `${configDir.path} dir`,
- ok: true,
+ ok: true, // should be allowed only if XDG support is there
browser: fileBrowser,
file: configDir,
minLevel: 0,
@@ -461,11 +460,10 @@ async function testFileAccessLinuxOnly() {
});
}
- if (xdgConfigHome.length > 1) {
- // When XDG_CONFIG_HOME is set, dont allow $HOME/.config
+ if (isXdgEnabled() && xdgConfigHome) {
const homeConfigDir = GetHomeSubdir(".config");
tests.push({
- desc: `${homeConfigDir.path} dir`,
+ desc: `XDG_CONFIG_HOME=${homeConfigDir.path} dir should deny $HOME/.config`,
ok: false,
browser: webBrowser,
file: homeConfigDir,
@@ -489,7 +487,7 @@ async function testFileAccessLinuxOnly() {
// Checking $HOME/.config is already done above.
const homeConfigPrefix = GetHomeSubdir(".configlol");
tests.push({
- desc: `${homeConfigPrefix.path} dir`,
+ desc: `No XDG_CONFIG_HOME we dont allow ${homeConfigPrefix.path} access`,
ok: false,
browser: webBrowser,
file: homeConfigPrefix,
@@ -498,7 +496,7 @@ async function testFileAccessLinuxOnly() {
});
if (fileContentProcessEnabled) {
tests.push({
- desc: `${homeConfigPrefix.path} dir`,
+ desc: `No XDG_CONFIG_HOME we dont allow ${homeConfigPrefix.path} access`,
ok: false,
browser: fileBrowser,
file: homeConfigPrefix,
@@ -625,7 +623,7 @@ async function testFileAccessLinuxOnly() {
});
// Only needed to perform cleanup
- if (xdgConfigHome.length > 1) {
+ if (isXdgEnabled()) {
tests.push({
desc: `$XDG_CONFIG_HOME (${configDir.path}) cleanup`,
ok: true,
diff --git a/security/sandbox/test/browser_content_sandbox_fs_xdg.js b/security/sandbox/test/browser_content_sandbox_fs_xdg.js
@@ -1,31 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-/* import-globals-from browser_content_sandbox_utils.js */
-"use strict";
-
-Services.scriptloader.loadSubScript(
- "chrome://mochitests/content/browser/" +
- "security/sandbox/test/browser_content_sandbox_utils.js",
- this
-);
-
-Services.scriptloader.loadSubScript(
- "chrome://mochitests/content/browser/" +
- "security/sandbox/test/browser_content_sandbox_fs_tests.js",
- this
-);
-
-add_task(async function () {
- // Ensure that XDG_CONFIG_HOME is there
- const xdgConfigHome = Services.env.get("XDG_CONFIG_HOME");
- Assert.greater(xdgConfigHome.length, 1, "XDG_CONFIG_HOME is defined");
-
- // If it is there, do actual testing
- sanityChecks();
-
- // The linux only tests are the ones that can behave differently based on
- // existence of XDG_CONFIG_HOME
- add_task(testFileAccessLinuxOnly); // eslint-disable-line no-undef
-
- add_task(cleanupBrowserTabs); // eslint-disable-line no-undef
-});
diff --git a/security/sandbox/test/browser_content_sandbox_fs_xdg_default.js b/security/sandbox/test/browser_content_sandbox_fs_xdg_default.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+/* import-globals-from browser_content_sandbox_utils.js */
+"use strict";
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/" +
+ "security/sandbox/test/browser_content_sandbox_utils.js",
+ this
+);
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/" +
+ "security/sandbox/test/browser_content_sandbox_fs_tests.js",
+ this
+);
+
+SimpleTest.requestCompleteLog();
+
+add_setup(async function setup() {
+ const xdgConfigHome = Services.env.exists("XDG_CONFIG_HOME");
+ Assert.equal(xdgConfigHome, false, `XDG_CONFIG_HOME is not set`);
+
+ const mozLegacyHome = Services.env.exists("MOZ_LEGACY_HOME");
+ Assert.equal(mozLegacyHome, false, "MOZ_LEGACY_HOME is not set");
+
+ // If it is there, do actual testing
+ sanityChecks();
+});
+
+add_task(async function () {
+ // Make sure we dont break others.
+ add_task(testFileAccessAllPlatforms); // eslint-disable-line no-undef
+
+ // The linux only tests are the ones that can behave differently based on
+ // existence of XDG_CONFIG_HOME
+ add_task(testFileAccessLinuxOnly); // eslint-disable-line no-undef
+
+ add_task(cleanupBrowserTabs); // eslint-disable-line no-undef
+});
diff --git a/security/sandbox/test/browser_content_sandbox_fs_xdg_mozLegacyHome.js b/security/sandbox/test/browser_content_sandbox_fs_xdg_mozLegacyHome.js
@@ -0,0 +1,42 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+/* import-globals-from browser_content_sandbox_utils.js */
+"use strict";
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/" +
+ "security/sandbox/test/browser_content_sandbox_utils.js",
+ this
+);
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/" +
+ "security/sandbox/test/browser_content_sandbox_fs_tests.js",
+ this
+);
+
+SimpleTest.requestCompleteLog();
+
+add_setup(async function setup() {
+ const xdgConfigHome = Services.env.exists("XDG_CONFIG_HOME");
+ Assert.equal(xdgConfigHome, true, "XDG_CONFIG_HOME is defined");
+
+ if (isXdgEnabled()) {
+ const mozLegacyHome = Services.env.get("MOZ_LEGACY_HOME");
+ Assert.equal(mozLegacyHome, 1, "MOZ_LEGACY_HOME is set to 1");
+ }
+
+ // If it is there, do actual testing
+ sanityChecks();
+});
+
+add_task(async function () {
+ // Make sure we dont break others.
+ add_task(testFileAccessAllPlatforms); // eslint-disable-line no-undef
+
+ // The linux only tests are the ones that can behave differently based on
+ // existence of XDG_CONFIG_HOME
+ add_task(testFileAccessLinuxOnly); // eslint-disable-line no-undef
+
+ add_task(cleanupBrowserTabs); // eslint-disable-line no-undef
+});
diff --git a/security/sandbox/test/browser_content_sandbox_fs_xdg_xdgConfigHome.js b/security/sandbox/test/browser_content_sandbox_fs_xdg_xdgConfigHome.js
@@ -0,0 +1,38 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+/* import-globals-from browser_content_sandbox_utils.js */
+"use strict";
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/" +
+ "security/sandbox/test/browser_content_sandbox_utils.js",
+ this
+);
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/" +
+ "security/sandbox/test/browser_content_sandbox_fs_tests.js",
+ this
+);
+
+SimpleTest.requestCompleteLog();
+
+add_setup(async function setup() {
+ // Ensure that XDG_CONFIG_HOME is there
+ const xdgConfigHome = Services.env.get("XDG_CONFIG_HOME");
+ Assert.greater(xdgConfigHome.length, 1, "XDG_CONFIG_HOME is defined");
+
+ // If it is there, do actual testing
+ sanityChecks();
+});
+
+add_task(async function () {
+ // Make sure we dont break others.
+ add_task(testFileAccessAllPlatforms); // eslint-disable-line no-undef
+
+ // The linux only tests are the ones that can behave differently based on
+ // existence of XDG_CONFIG_HOME
+ add_task(testFileAccessLinuxOnly); // eslint-disable-line no-undef
+
+ add_task(cleanupBrowserTabs); // eslint-disable-line no-undef
+});
diff --git a/security/sandbox/test/browser_content_sandbox_utils.js b/security/sandbox/test/browser_content_sandbox_utils.js
@@ -44,6 +44,18 @@ function sanityChecks() {
}
}
+function isXdgEnabled() {
+ try {
+ return Services.prefs.getBoolPref("widget.support-xdg-config");
+ } catch (ex) {
+ // if the pref is not there it means we dont have XDG support
+ if (ex.name === "NS_ERROR_UNEXPECTED") {
+ return false;
+ }
+ throw ex;
+ }
+}
+
// Creates file at |path| and returns a promise that resolves with an object
// with .ok boolean to indicate true if the file was successfully created,
// otherwise false. Include imports so this can be safely serialized and run
@@ -376,6 +388,7 @@ function GetProfileEntry(name) {
}
function GetDir(path) {
+ info(`GetDir(${path})`);
let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
dir.initWithPath(path);
Assert.ok(dir.isDirectory(), `${path} is a directory`);
diff --git a/security/sandbox/test/browser_xdg.toml b/security/sandbox/test/browser_xdg.toml
@@ -1,17 +0,0 @@
-# Any copyright is dedicated to the Public Domain.
-# http://creativecommons.org/publicdomain/zero/1.0/
-[DEFAULT]
-skip-if = [
- "ccov",
- "os == 'linux' && (asan || tsan)", # bug 1784517
-]
-tags = "contentsandbox"
-support-files = [
- "browser_content_sandbox_utils.js",
- "browser_content_sandbox_fs_tests.js",
-]
-test-directories = "/tmp/.xdg_config_home_test"
-environment = "XDG_CONFIG_HOME=/tmp/.xdg_config_home_test"
-
-["browser_content_sandbox_fs_xdg.js"]
-run-if = ["os == 'linux'"]
diff --git a/security/sandbox/test/browser_xdg_default.toml b/security/sandbox/test/browser_xdg_default.toml
@@ -0,0 +1,20 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+[DEFAULT]
+skip-if = [
+ "ccov",
+ "os == 'linux' && (asan || tsan)", # bug 1784517
+]
+tags = "contentsandbox"
+support-files = [
+ "browser_content_sandbox_utils.js",
+ "browser_content_sandbox_fs_tests.js",
+]
+# .config needs to exists for the sandbox to properly add it
+test-directories = ["/tmp/.xdg_default_test", "/tmp/.xdg_default_test/.config"]
+environment = [
+ "HOME=/tmp/.xdg_default_test",
+]
+
+["browser_content_sandbox_fs_xdg_default.js"]
+run-if = ["os == 'linux'"]
diff --git a/security/sandbox/test/browser_xdg_mozLegacyHome.toml b/security/sandbox/test/browser_xdg_mozLegacyHome.toml
@@ -0,0 +1,21 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+[DEFAULT]
+skip-if = [
+ "ccov",
+ "os == 'linux' && (asan || tsan)", # bug 1784517
+]
+tags = "contentsandbox"
+support-files = [
+ "browser_content_sandbox_utils.js",
+ "browser_content_sandbox_fs_tests.js",
+]
+test-directories = ["/tmp/.xdg_mozLegacyHome_test/.config", "/tmp/.xdg_config_home_test"]
+environment = [
+ "XDG_CONFIG_HOME=/tmp/.xdg_config_home_test",
+ "HOME=/tmp/.xdg_mozLegacyHome_test",
+ "MOZ_LEGACY_HOME=1",
+]
+
+["browser_content_sandbox_fs_xdg_mozLegacyHome.js"]
+run-if = ["os == 'linux'"]
diff --git a/security/sandbox/test/browser_xdg_xdgConfigHome.toml b/security/sandbox/test/browser_xdg_xdgConfigHome.toml
@@ -0,0 +1,20 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+[DEFAULT]
+skip-if = [
+ "ccov",
+ "os == 'linux' && (asan || tsan)", # bug 1784517
+]
+tags = "contentsandbox"
+support-files = [
+ "browser_content_sandbox_utils.js",
+ "browser_content_sandbox_fs_tests.js",
+]
+test-directories = "/tmp/.xdg_config_home_test"
+environment = [
+ "XDG_CONFIG_HOME=/tmp/.xdg_config_home_test",
+ "MOZ_LEGACY_HOME=0",
+]
+
+["browser_content_sandbox_fs_xdg_xdgConfigHome.js"]
+run-if = ["os == 'linux'"]