Skip to content

[Bug]: uncaught URL parse crash on missing or malformed Host header across API handlers #516

Open

Description

@Abfa41

Description

Following #503 (which fixed new URL() throwing on missing/malformed Host headers inside requireAuth in src/server/signalling/utils.ts), the same unguarded new URL() pattern still exists across the main API router and route handlers:

  1. src/server/signalling/server.ts (handleApiRequest, line 161):

    const url = new URL(
    	req.url ?? "",
    	`http://${req.headers.host ?? "localhost"}`,
    )

    Because this runs at the entry of handleApiRequest before routing or requireAuth, any unauthenticated HTTP request with a malformed Host header (e.g., Host: [) throws an uncaught TypeError [ERR_INVALID_URL] in the raw Node request listener, terminating the host server process.

  2. src/server/signalling/handlers/rtc.ts (handleOffer, handleAnswer, handleIce, parseRequestMeta, parseAddress):
    Uses the same new URL(req.url ?? "", http://${req.headers.host ?? "localhost"}) pattern without a try/catch.

  3. src/server/signalling/handlers/fileShare.ts (handleFileBrowse, handleFileDownload, handleFileDelete):

    const url = new URL(req.url ?? "", `http://${req.headers.host}`)

    Omits even the ?? "localhost" fallback and lacks error handling, crashing on missing or malformed Host headers.

Steps to Reproduce

  1. Start the Rein server (npm run dev or packaged Nitro server).
  2. Send a raw HTTP request with a malformed Host header:
    GET /api/host/status HTTP/1.1
    Host: [
    Connection: close
  3. new URL() throws an unhandled ERR_INVALID_URL exception and crashes the server process.

Expected Behavior

Request URLs should be parsed against a fixed loopback base (http://localhost) rather than interpolating the untrusted Host header, and any malformed request target should cleanly return HTTP 400 Bad Request without crashing the server.

Activity

  1. github-actions commented on Nov 22, 2026

    @github-actions

    Discussions are carried on Discord.

    Instead of commenting here, go to the Discord channel.

    macOS and macOS-related issues are not supported at the moment. We are looking for funding to support macOS and would appreciate sponsorships.

    If you find this project useful, a GitHub star would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions