You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): parse request URLs against fixed base to prevent Host header crash - #517
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:
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.
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"
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.
Malformed request URLs now return HTTP 400 instead of risking an uncaught server error. No remaining merge-blocking risk is identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
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
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
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
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addressed Issues:
Fixes #516
Description
Follow-up to #503: replaces remaining
new URL()calls that interpolated the untrustedreq.headers.hostheader across the signaling router and route handlers with a shared fixed-base (http://localhost) parser returning400 Bad Requeston invalid request URLs.src/server/signalling/utils.tsthat catches malformed targets and returnsnull.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 return400 { error: "Invalid request URL" }instead of throwing an uncaughtERR_INVALID_URL.utils.test.ts,rtc.test.ts, andfileShare.test.tscovering malformed/missingHostheaders and invalid request URLs.Screenshots/Recordings:
All testcases have passed...
Functional Verification
Screen Mirror
Authentication
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:
Additional Notes:
npm run test(122 tests passing across 19 test files) andnpx biome checkon all modified/added files.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.
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