Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connect): trust localhost subdomains #16721

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

martykan
Copy link
Member

Description

Treat subdomains of localhost (eg. https://subdomain.localhost/) the same way we treat localhost itself.

Related Issue

Resolve #16671

@martykan martykan marked this pull request as ready for review January 30, 2025 20:33
Copy link

coderabbitai bot commented Jan 30, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error Error: http://10.0.0.28:4873/@trezor%2feslint: no such package available
at params.callback [as _callback] (/opt/yarn-v1.22.22/lib/cli.js:66685:18)
at self.callback (/opt/yarn-v1.22.22/lib/cli.js:141415:22)
at Request.emit (node:events:519:28)
at Request. (/opt/yarn-v1.22.22/lib/cli.js:142387:10)
at Request.emit (node:events:519:28)
at IncomingMessage. (/opt/yarn-v1.22.22/lib/cli.js:142309:12)
at Object.onceWrapper (node:events:633:28)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

Walkthrough

The pull request introduces modifications to the getHost function in the urlUtils.ts file to improve handling of localhost subdomains. Specifically, the changes add a conditional check to ensure that when a URL contains a subdomain with 'localhost', the function correctly returns 'localhost' as the host. A corresponding test case has been added to the urlUtils.test.ts file to validate this new behavior. The modification aims to enhance the function's ability to process URLs with localhost subdomains, such as those potentially used in local development environments like Tauri.

Assessment against linked issues

Objective Addressed Explanation
Trust .localhost URLs
Handle subdomain.localhost URLs
Comply with RFC 6761 localhost domain considerations

The changes directly address the requirements outlined in issue #16671 by modifying the getHost function to recognize and handle localhost subdomains. The implementation ensures that URLs like http://tauri.localhost:8088/ will be correctly processed, aligning with the RFC 6761 specifications for localhost domain names. The added test case further validates the new functionality, providing confidence in the implementation's correctness.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/connect/src/utils/urlUtils.ts (1)

19-20: Consider using a more robust localhost check.

While the current implementation works for basic cases, it might be vulnerable to edge cases. Consider using a more comprehensive check that accounts for various localhost formats.

Here's a suggested improvement:

-        if (parts[parts.length - 1] === 'localhost') return 'localhost';
+        // Check if any part of the domain is localhost
+        if (parts.some(part => part.toLowerCase() === 'localhost')) return 'localhost';

This change would:

  1. Handle case sensitivity (e.g., 'LocalHost')
  2. Work even if 'localhost' appears in different positions
packages/connect/src/utils/__tests__/urlUtils.test.ts (1)

19-19: Enhance test coverage for localhost subdomain handling.

While the basic case is covered, consider adding more test cases to ensure robust handling of localhost subdomains.

Add these test cases:

         expect(getHost('http://subdomain.localhost:8088/')).toEqual('localhost');
+        // Multiple subdomains
+        expect(getHost('http://sub1.sub2.localhost')).toEqual('localhost');
+        // Case sensitivity
+        expect(getHost('http://sub.LOCALHOST')).toEqual('localhost');
+        // Different protocols
+        expect(getHost('https://sub.localhost')).toEqual('localhost');
+        expect(getHost('ws://sub.localhost')).toEqual('localhost');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4387e33 and 19a1ae4.

📒 Files selected for processing (2)
  • packages/connect/src/utils/__tests__/urlUtils.test.ts (1 hunks)
  • packages/connect/src/utils/urlUtils.ts (1 hunks)
🔇 Additional comments (1)
packages/connect/src/utils/urlUtils.ts (1)

19-21: Verify security implications of trusting localhost subdomains.

The current implementation treats all subdomains of localhost as trusted. While this aligns with the PR objectives, it's important to ensure this doesn't introduce security vulnerabilities.

Let's check for any security considerations in the codebase:

✅ Verification successful

Localhost subdomain handling follows secure practices

The implementation aligns with standard web security practices where localhost is treated as a secure origin. The code is primarily used in development/testing contexts, and the security implications of localhost access are well understood and appropriately handled in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for security-related comments or validations around localhost
rg -i "localhost.*security|security.*localhost" 

# Check how localhost is used in other parts of the codebase
rg -i "localhost" --type ts

Length of output: 16830

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.

Trezor connect trust .localhost urls
1 participant