Closed Bug 2023420 Opened 8 months ago Closed 8 months ago

Sandbox escape: PTCPSocket/PTCPServerSocket IPC lacks parent-side authorization — compromised content process can open arbitrary TCP connections from parent

Categories

(Core :: Networking, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 2017857

People

(Reporter: s3zer0, Unassigned)

Details

(Keywords: ai-involved, reporter-external, Whiteboard: [client-bounty-form])

Background

The mozTCPSocket API (originally added for Firefox OS / B2G in Bug 797561) is gated at the JavaScript level via [Func="mozilla::dom::TCPSocket::ShouldTCPSocketExist"] in the WebIDL, which checks IsSystemPrincipal(). This prevents normal web content from accessing the API through JavaScript.

However, the underlying IPC protocol (PTCPSocket, managed by PNecko) has no corresponding parent-side authorization. A compromised content process that can send raw IPC messages bypasses the JavaScript gate entirely.

Vulnerability Details

PTCPSocket (outbound connections):

  1. PNecko.ipdl declares manages PTCPSocket; with no [ChildProc=...] restriction. PNecko is managed by PContent, so every web content process has a PNecko actor.

  2. NeckoParent::AllocPTCPSocketParent() (netwerk/ipc/NeckoParent.cpp) performs zero authorization checks:

PTCPSocketParent* NeckoParent::AllocPTCPSocketParent(
    const nsAString& /* host */, const uint16_t& /* port */) {
  TCPSocketParent* p = new TCPSocketParent();
  p->AddIPDLReference();
  return p;
}
  1. TCPSocketParent::RecvOpen() (dom/network/TCPSocketParent.cpp) creates a real TCP connection in the parent process with no validation:
mozilla::ipc::IPCResult TCPSocketParent::RecvOpen(
    const nsString& aHost, const uint16_t& aPort,
    const bool& aUseSSL, const bool& aUseArrayBuffers) {
  mSocket = new TCPSocket(nullptr, aHost, aPort, aUseSSL, aUseArrayBuffers);
  mSocket->SetSocketBridgeParent(this);
  NS_ENSURE_SUCCESS(mSocket->Init(nullptr), IPC_OK());
  return IPC_OK();
}
  1. TCPSocket::Init() (dom/network/TCPSocket.cpp), when running in the parent process (XRE_IsContentProcess() returns false), calls sts->CreateTransport() to open a real TCP socket to the attacker-specified host:port with no security checks.

  2. The connection is fully bidirectional: data received on the socket is sent back to the content process via FireArrayBufferDataEvent() / FireStringDataEvent() → PTCPSocketParent::SendCallback().

PTCPServerSocket (listening sockets):

The identical pattern exists for PTCPServerSocket:

  • NeckoParent::AllocPTCPServerSocketParent() — zero checks
  • NeckoParent::RecvPTCPServerSocketConstructor() — calls Init() directly
  • TCPServerSocketParent::Init() — opens a listening socket in the parent process

Attack Chain

Compromised content process
  → PContent → PNecko (every content process has one)
    → PTCPSocket("target.internal", 80)    // no ChildProc restriction
      → NeckoParent::AllocPTCPSocketParent // no authorization check
        → TCPSocketParent::RecvOpen        // no authorization check
          → TCPSocket::Init()              // parent process path
            → CreateTransport(host, port)  // real TCP connection!
              → bidirectional data via SendCallback

Contrast with Properly Defended NeckoParent Handlers

Other handlers in the same file correctly validate the caller:

  • RecvGetPageThumbStream: enforces PRIVILEGEDABOUT_REMOTE_TYPE process check
  • RecvGetExtensionStream: validates moz-extension scheme, host registration, and directory containment
  • RecvPUDPSocketConstructor: rejects requests from content processes

PTCPSocket and PTCPServerSocket are missing equivalent checks.

Root Cause

The mozTCPSocket API was added for Firefox OS (B2G) where it was gated by app permissions. When Firefox OS was discontinued, the JavaScript-level gate (ShouldTCPSocketExist → IsSystemPrincipal()) was retained, but it only controls WebIDL visibility and does not protect the IPC boundary. The Fission IPC hardening effort (Bug 1484019) does not include PTCPSocket/PTCPServerSocket in its tracked sub-bugs.

Historical context:

  • Bug 782542 (2012): Necko IPC security added, but focused on cookie/cache AppID validation, not TCPSocket
  • Bug 891954 (2013): Necko IPC security disabled for desktop e10s (only relevant for B2G multi-app model)
  • Bug 1322254 (2020): UsingNeckoIPCSecurity code entirely removed as dead code

Steps to Reproduce

From a compromised content process (e.g., after exploiting a JIT or memory corruption bug):

  1. Send PTCPSocket constructor message via the existing PNecko actor:
    PNecko::SendPTCPSocketConstructor("192.168.1.1", 22)

  2. Send RecvOpen on the constructed actor:
    PTCPSocket::SendOpen("192.168.1.1", 22, false, true)

  3. The parent process opens a TCP connection to 192.168.1.1:22 and begins relaying data bidirectionally via SendCallback.

  4. For a listening socket:
    PNecko::SendPTCPServerSocketConstructor(4444, 5, true)
    This opens port 4444 on the victim's machine.

Attack Scenarios

  1. Internal network SSRF: Access cloud metadata endpoints (169.254.169.254), internal databases, admin panels from the parent process
  2. Port scanning: Probe internal network topology from the parent process
  3. Listening sockets: Open arbitrary ports on the victim's machine (reverse shell listener, pivot point)
  4. Data exfiltration: Bypass content sandbox network restrictions for data theft
  5. TLS connections: useSSL=true enables encrypted connections to internal services

Impact

  • Severity: sec-high / sec-critical (sandbox escape — full network access from parent process)
  • Affected: All platforms, all Firefox versions with e10s/Fission (the IPC path has been unprotected since Bug 891954 in 2013)
  • Prerequisite: Code execution in a content process (standard sandbox escape threat model, cf. CVE-2025-2857, CVE-2024-9680)

Affected Files

  • netwerk/ipc/PNecko.ipdl — manages PTCPSocket/PTCPServerSocket, no ChildProc restriction
  • netwerk/ipc/NeckoParent.cpp — AllocPTCPSocketParent, AllocPTCPServerSocketParent (no checks)
  • dom/network/TCPSocketParent.cpp — RecvOpen (no checks)
  • dom/network/TCPSocket.cpp — ShouldTCPSocketExist (JS-only gate), Init() (no parent-side check)
  • dom/network/PTCPSocket.ipdl — protocol definition
  • dom/network/TCPServerSocketParent.cpp — same pattern for listening sockets
Flags: sec-bounty?
Group: firefox-core-security → network-core-security
Component: Security → Networking
Product: Firefox → Core

Seems like a dupe of bug 2017857

Status: UNCONFIRMED → RESOLVED
Closed: 8 months ago
Duplicate of bug: CVE-2026-6761
Resolution: --- → DUPLICATE
Flags: sec-bounty? → sec-bounty-
Group: network-core-security
You need to log in before you can comment on or make changes to this bug.