SandboxBroker::Policy::Lookup bypasses nested FORCE_DENY via `//` in path
The Firefox sandbox broker's policy lookup does not normalise repeated slashes in paths, so a path with an extra slash before a denied directory fails to match the FORCE_DENY rule while still matching the enclosing recursive allow. An attacker who already has code execution in a content process could use this to read files the policy intended to deny, such as cookies and saved logins on some Linux layouts.
Originally disclosed on Mozilla
- Fixed in 11 days
- Paid in 19 days
- Disclosed after 11 days
Created attachment 9573343
TestBroker_DoubleSlash.cpp
Steps to reproduce:
Checked out the firefox-152.0a1-nightly source tarball and configured a build with the default mozconfig plus `ac_add_options --enable-tests`.
Reviewed SandboxBroker::Policy::Lookup at
security/sandbox/linux/broker/SandboxBroker.cpp:422-448 and its upstream
path-validation callers SandboxBroker::Policy::ValidatePath at :144-169
and Policy::ConvertRelativePath at :612-618. No normalization of repeated
`/` characters is performed before the path is compared against policy
entries via StringBeginsWith, and `realpath()` is only invoked on paths
that contain `..`.
Wrote security/sandbox/linux/gtest/TestBroker_DoubleSlash.cpp (attached)
— four tests that:
1. Build a SandboxBroker::Policy in memory with a recursive `MAY_READ`
allow on `/tmp/sbtest/outer` nested around a `FORCE_DENY` on
`/tmp/sbtest/outer/secret`, then call `FixRecursivePermissions()`.
2. Call `Policy::Lookup` on the canonical path
`/tmp/sbtest/outer/secret/cookies.sqlite` and record the returned
permission mask.
3. Call `Policy::Lookup` on the same file spelled with one extra `/`
before the denied segment
(`/tmp/sbtest/outer//secret/cookies.sqlite`) and record the mask.
4. Assert that the canonical path carries the `FORCE_DENY` bit and the
`//` path does not, and that `..` paths are still rejected — proving
the normalization logic exists but is incomplete.
A fourth test (`RealWorldMozillaConfigDenyBypass`) reproduces the exact
`$HOME/.config/` recursive allow + `$HOME/.config/mozilla/` deny shape
set up by SandboxBrokerPolicyFactory.cpp:582-612 and observes the same
`0x83` vs `0x3` divergence on a path of the form
`$HOME/.config//mozilla/firefox/<profile>/logins.json`.
Registered the test in sibling moz.build add
`"TestBroker_DoubleSlash.cpp",` to `UNIFIED_SOURCES` in
security/sandbox/linux/gtest/moz.build in sorted order (between
`TestBroker.cpp` and `TestBrokerPolicy.cpp`).
Ran:
./mach build
./mach gtest 'SandboxBrokerDoubleSlash*'
All four tests pass on the above Nightly revision (output log attached,
see "Test results" under the actual-results section below).
Attacker primitive (what a compromised content process would place on
the wire to reach the real broker, the GTest reaches the gap directly
because SandboxBroker::Policy is a free in-memory structure):
SandboxBrokerClient::Open(
path = "$HOME/.config//mozilla/firefox/<profile_id>/cookies.sqlite",
flags = O_RDONLY)
Equivalent over the raw broker socket: a
`SandboxBrokerCommon::Request{SANDBOX_FILE_OPEN, O_RDONLY, 0}` header
followed by the `//`-crafted path, `sendmsg`'d on the broker fd owned by
the content process.
Note on attacker model: this primitive has no JS/WebIDL binding, so only
an attacker who has already achieved code execution inside a content
process (e.g. via a memory-safety bug) can send it. The broker is
expected to canonicalize caller-supplied paths before matching them
against its policy, that's the gap here.
Actual results:
Three gaps in the broker policy layer compound to let a `//`-containing
path bypass a nested FORCE_DENY rule.
SandboxBroker::Policy::ValidatePath
(security/sandbox/linux/broker/SandboxBroker.cpp:144-169) rejects
`/../` traversal but does not reject or normalize repeated `/`. The
existing loop iterates looking for `/../`:
for (size_t i = 0; i < len; i++) {
if (path[i] == '/' && (len - i) > 3) {
if (path[i + 1] == '.' && path[i + 2] == '.' && path[i + 3] == '/') {
return false;
}
}
}
return true;
SandboxBroker::Policy::ConvertRelativePath
(security/sandbox/linux/broker/SandboxBroker.cpp:612-618) only invokes
`realpath()` when the path contains `..`:
if (strstr(aPath, "..") != nullptr) {
return RealPath(aPath, aBufSize, aPathLen);
}
return aPathLen;
So `//` survives uncanonicalized into Lookup.
SandboxBroker::Policy::Lookup
(security/sandbox/linux/broker/SandboxBroker.cpp:422-448) matches by
raw byte-string prefix via StringBeginsWith:
int perms = mMap.Get(aPath); // exact-string hashmap, no normalization
...
for (const auto& entry : mMap) {
if ((entry.GetData() & RECURSIVE) &&
StringBeginsWith(aPath, entry.GetKey())) {
...
}
}
The FORCE_DENY entry for a nested subdir has a policy key ending in
`/secret/`; the lookup input `<outer>//secret/...` fails that match at
the `/` vs `s` boundary character. The enclosing recursive allow's key
`<outer>/` does not care about the extra `/` and still matches. Net: the
allow wins and the deny is silently dropped.
The Linux kernel, meanwhile, collapses runs of `/` to a single `/` in
`sys_open`, so the file the broker's subsequent `open(2)` at
SandboxBroker.cpp:868 actually opens is the one the policy intended to
deny.
Exhaustive grep of security/sandbox/linux/broker/SandboxBroker.cpp for
any canonicalization that would collapse `//` before StringBeginsWith:
zero matches. Exhaustive grep for `//` in nearby comments describing
policy matching: zero matches acknowledging this case.
Observable post-conditions (demonstrated by the attached GTest):
Policy::Lookup("/tmp/sbtest/outer/secret/cookies.sqlite")
→ 0x83 (MAY_ACCESS | MAY_READ | FORCE_DENY)
Policy::Lookup("/tmp/sbtest/outer//secret/cookies.sqlite")
→ 0x3 (MAY_ACCESS | MAY_READ) ← FORCE_DENY bit missing
Downstream:
SandboxBrokerClient::Open follows the (buggy) permission mask from
Lookup; the FORCE_DENY bit being absent allows the open to proceed. The
kernel then opens the real `/tmp/sbtest/outer/secret/cookies.sqlite`
file because `sys_open` normalizes `//` to `/`.
On default Linux layouts the Firefox profile sits at `~/.mozilla/firefox`,
which is not in any allow rule; the `~/.config/mozilla` deny at
SandboxBrokerPolicyFactory.cpp:609 is defense-in-depth on that layout.
On Snap / Flatpak / XDG-migrated layouts where the profile lives under
`~/.config/mozilla/firefox/<id>/`, bypassing the deny reads
`cookies.sqlite`, `logins.json`, `key4.db`, `cert9.db`, `places.sqlite`
— cross-origin cookie and credential theft from a compromised content
process.
Test results (2026-04-24):
Currently running suites: SandboxBrokerDoubleSlash
SUITE_START: gtest - running 0 tests
TEST_START: SandboxBrokerDoubleSlash.BaselineDenyWorksWithCanonicalPath
TEST_END: PASS
TEST_START: SandboxBrokerDoubleSlash.DoubleSlashBypassesNestedDeny
[DoubleSlashBypassesNestedDeny] canonical = 0x83 bypass = 0x3
(MAY_ACCESS=0x1 MAY_READ=0x2 FORCE_DENY=0x80)
TEST_END: PASS
TEST_START: SandboxBrokerDoubleSlash.DotDotStillRejected
TEST_END: PASS
TEST_START: SandboxBrokerDoubleSlash.RealWorldMozillaConfigDenyBypass
[RealWorldMozillaConfigDenyBypass] canonical = 0x83 bypass = 0x3
TEST_END: PASS
SUITE_END
Ran 4 checks (4 tests)
Expected results: 4
Unexpected results: 0
OK
Ran 4 test(s) from 1 test suite(s) (0 disabled), with 0 failure(s).
All four tests pass, confirming that (1) the canonical-path FORCE_DENY
fires as intended, (2) a path with one extra `/` before the denied
segment receives MAY_READ without FORCE_DENY, (3) the existing `..`
traversal normalization is intact and this bug is a normalization gap
specific to repeated `/`, and (4) the same bypass applies to the exact
`$HOME/.config/mozilla` deny shape Mozilla already configures.
Expected results:
Under Firefox's content-sandbox model, the broker's policy decision and
the kernel's subsequent `open(2)` on the same path must agree on which
file is being opened. Any caller-supplied path that the kernel will
canonicalize before resolving must be canonicalized by the broker before
it is matched against policy, otherwise the policy evaluates one string
and the syscall executes a different-but-kernel-equivalent one, as
happens here with `//`.
The established precedent in the same file is the `/../` rejection in
ValidatePath; `//` should be handled the same way. A minimal patch is a
5-line rejection at the entry to ValidatePath:
// In SandboxBroker::Policy::ValidatePath, alongside the existing
// '/../' rejection:
for (size_t i = 1; i < len; i++) {
if (path[i - 1] == '/' && path[i] == '/') {
return false;
}
}
Alternatively, canonicalize at the broker receive site by collapsing
runs of `/` to a single `/` before calling `Policy::Lookup`. Rejection
is stricter, matches how `..` is already handled, and has no performance
cost on normal paths.
Additionally, the byte-prefix matching in `Policy::Lookup` via
`StringBeginsWith` is a general hazard, any future normalization gap
(e.g. `/./`, unicode-normal-form variation on filesystems that do NFD,
trailing `/`, case on case-insensitive mounts) would reproduce the same
class of bypass. A longer-term improvement would be to build the policy
map keyed on an already-canonical form of the path and canonicalize
lookup inputs the same way, rather than relying on byte-prefix matching
of ad-hoc strings.
Whichever approach Mozilla prefers, a regression test in the shape of
the attached TestBroker_DoubleSlash.cpp, exact deny nested under a
recursive allow, probed with both canonical and `//` paths, would keep
the primitive covered going forward.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The broker compares raw path strings against policy entries without collapsing repeated slashes, and only calls realpath() when the path contains '..', so a path with '//' fails to match a nested deny rule but still matches the enclosing recursive allow.
Impact
A compromised content process could read files that the policy intended to deny, such as cookies and saved logins, but only on Linux layouts where the profile sits under a denied directory; the report notes this is defence-in-depth on default layouts.
What the attacker needed
Code execution in a content process; Linux layout with profile under a denied dir
The fix
The report suggests rejecting paths containing '//' in ValidatePath, or collapsing repeated slashes before lookup; it does not say a fix was applied.
How it was found
- Build a policy with a recursive allow on an outer directory and a FORCE_DENY on a nested secret directory.
- Look up the canonical path of a file inside the denied directory and record the permission mask.
- Look up the same file with an extra slash before the denied segment and record the mask.
- Observe that the canonical path includes the FORCE_DENY bit but the double-slash path does not.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Firefox runs web content in a restricted process that must ask a separate 'broker' process before opening files. The broker checks the requested path against a list of allowed and denied folders. This report shows that writing an extra slash in the path makes the broker miss a deny rule, so it allows a file it should refuse.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.