Skip to content

fix(server): parse request URLs against fixed base to prevent Host header crash - #517

Open
Abfa41 wants to merge 1 commit into
AOSSIE-Org:mainfrom
Abfa41:fix/safe-request-url-parsing
Open

Abfa41 wants to merge 1 commit into
AOSSIE-Org:mainfrom
Abfa41:fix/safe-request-url-parsing

Conversation

@Abfa41

@Abfa41 Abfa41 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Addressed Issues:

Fixes #516

Description

Follow-up to #503: replaces remaining new URL() calls that interpolated the untrusted req.headers.host header across the signaling router and route handlers with a shared fixed-base (http://localhost) parser returning 400 Bad Request on invalid request URLs.

  • Added a shared fixed-base URL parser in src/server/signalling/utils.ts that catches malformed targets and returns null.
  • Updated handleApiRequest (src/server/signalling/server.ts), RTC handlers (src/server/signalling/handlers/rtc.ts), and file-share handlers (src/server/signalling/handlers/fileShare.ts) to use the helper and return 400 { error: "Invalid request URL" } instead of throwing an uncaught ERR_INVALID_URL.
  • Added unit tests in utils.test.ts, rtc.test.ts, and fileShare.test.ts covering malformed/missing Host headers and invalid request URLs.

Screenshots/Recordings:

image

All testcases have passed...

Functional Verification

  • Please check off the behaviors verified with this change.

Screen Mirror

  • Screen MIrror works.

Authentication

  • Connection doesn't work without a valid token.

Basic Gestures

  • One-finger tap: Verified as Left Click.

  • Two-finger tap: Verified as Right Click.

  • Click and drag: Verified selection behavior.

  • Pinch to zoom: Verified zoom functionality (if applicable).

Modes & Settings

  • Cursor mode: Cursor moves smoothly and accurately.

  • Scroll mode: Page scrolls as expected.

  • Sensitivity: Verified changes in cursor speed/sensitivity settings.

  • Copy and Paste: Verified both Copy and Paste functionality.

  • Invert Scrolling: Verified scroll direction toggles correctly.

Advanced Input

  • Key combinations: Verified "hold" behavior for modifiers (e.g., Ctrl+C) and held keys are shown in buffer.

  • Keyboard input: Verified Space, Backspace, and Enter keys work correctly.

  • Glide typing: Verified path drawing and text output.

  • Voice input: Verified speech-to-text functionality for full sentences.

  • Backspace doesn't send the previous input.

Any other gesture or input behavior introduced:

  • New Gestures: Verified any other gesture or input behavior introduced in this PR.

Additional Notes:

  • Verified with npm run test (122 tests passing across 19 test files) and npx biome check on all modified/added files.
  • AI assistance (GitHub Copilot) was used to help locate the affected call sites, draft the fix, and write unit tests; all changes were reviewed and verified locally.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.

  • My code follows the project's code style and conventions

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • If applicable, I have made corresponding changes or additions to the documentation

  • If applicable, I have made corresponding changes or additions to tests

  • My changes generate no new warnings or errors

  • I have joined the and I will share a link to this PR with the project maintainers there

  • I have read the

  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

  • Incase of UI change I've added a demo video.

⚠️ AI Notice - Important!
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • Bug Fixes
    • Malformed URLs in file-sharing, WebRTC signaling, and API requests now receive a clear HTTP 400 error instead of causing request handling to fail unexpectedly.
    • Requests with missing or malformed host information can still be handled using their request path.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "instructions" at "reviews"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review.

Walkthrough

Signalling URL handling now uses a shared parser with a fixed base. The API router, RTC handlers, and file-share handlers return HTTP 400 when URL parsing fails. Tests cover malformed request URLs.

Changes

Signalling URL validation

Layer / File(s) Summary
Shared URL parsing and API routing
src/server/signalling/utils.ts, src/server/signalling/utils.test.ts, src/server/signalling/server.ts
Added parseRequestUrl, which parses against http://localhost and returns null on failure. The API router uses it and returns HTTP 400 for invalid URLs.
RTC handler URL validation
src/server/signalling/handlers/rtc.ts, src/server/signalling/handlers/rtc.test.ts
RTC handlers and parsing helpers use parseRequestUrl and respond with HTTP 400 when parsing fails. Tests cover malformed requests across the handlers.
File-share handler URL validation
src/server/signalling/handlers/fileShare.ts, src/server/signalling/handlers/fileShare.test.ts
Browse, download, and delete handlers parse URLs before authentication and respond with HTTP 400 when parsing fails. Tests cover malformed requests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested labels: Typescript Lang

Suggested reviewers: pinjinx, muhammadfaizan-prog

Merge Risk: Minimal · up to 7c3fe

Malformed request URLs now return HTTP 400 instead of risking an uncaught server error. No remaining merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: request URLs now parse against a fixed base to stop a crash caused by the Host header. The changeset matches this. It adds parseRequestUrl with a fixed http://localhos…
Description check Passed The description follows the template structure. It links issue #516 with 'Fixes #516' and gives a clear Description section that explains the fixed-base parser and the 400 responses. It lists unit tes…
Linked Issues check Passed Issue #516 requires that request URLs be parsed against a fixed loopback base and that malformed targets return HTTP 400 without crashing. At the reviewed head, parseRequestUrl in `src/server/signal…
Out of Scope Changes check Passed All changed files relate to the #516 objective. Changes are limited to: the new parseRequestUrl helper in utils.ts; call-site replacements in server.ts, rtc.ts, and fileShare.ts; and tests f…
Full details: Title check

Explanation

The title names the main change: request URLs now parse against a fixed base to stop a crash caused by the Host header. The changeset matches this. It adds parseRequestUrl with a fixed http://localhost base, and the handlers return 400 on invalid URLs. The title is clear and specific, though it is slightly long at 79 characters.

Full details: Description check

Explanation

The description follows the template structure. It links issue #516 with 'Fixes #516' and gives a clear Description section that explains the fixed-base parser and the 400 responses. It lists unit tests added in three files and gives test results (122 passing across 19 files). Functional verification has only one box checked, and the template's manual checks are mostly unchecked. Those checks fit a UI-facing project, and this change is server-side, so they are non-critical here. The screenshot is included. The Checklist has two unchecked items: documentation updates and a demo video. The demo video item is not applicable to a server-only change. The documentation item is unanswered.

Full details: Linked Issues check

Explanation

Issue #516 requires that request URLs be parsed against a fixed loopback base and that malformed targets return HTTP 400 without crashing. At the reviewed head, parseRequestUrl in src/server/signalling/utils.ts parses req.url against http://localhost and returns null on a thrown error. The diff in src/server/signalling/server.ts confirms that handleApiRequest uses this helper and returns 400 { error: "Invalid request URL" } before routing or requireAuth. The PR summary reports that the same helper is applied in handlers/rtc.ts (handleOffer, handleAnswer, handleIce, parseRequestMeta, parseAddress, handleSessionSSE, handleSessionDelete) and handlers/fileShare.ts (handleFileBrowse, handleFileDownload, handleFileDelete). Unit tests cover malformed URLs in utils.test.ts, rtc.test.ts, and fileShare.test.ts. The requireAuth fallback from #503 also uses the fixed base. I inspected utils.ts and the server.ts diff directly. I did not inspect the rtc.ts and fileShare.ts diffs, so their behavior rests on the PR summary and the tests.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the #516 objective. Changes are limited to: the new parseRequestUrl helper in utils.ts; call-site replacements in server.ts, rtc.ts, and fileShare.ts; and tests for these paths. The parseRequestMeta signature change in rtc.ts is a necessary part of the fix, because the helper must write the 400 response. The PR does not show unrelated functional changes. The functional verification checklist in the PR description is not a code requirement and is not assessed here.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each URL with care,
A fixed-base path is waiting there.
If parsing fails, a 400 replies,
No thrown URL can surprise.
The hare hops on through fields of green.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ff5ea6f and 7c3fe86.

Files selected for processing: 7

  • src/server/signalling/handlers/fileShare.test.ts
  • src/server/signalling/handlers/fileShare.ts
  • src/server/signalling/handlers/rtc.test.ts
  • src/server/signalling/handlers/rtc.ts
  • src/server/signalling/server.ts
  • src/server/signalling/utils.test.ts
  • src/server/signalling/utils.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant