Skip to content

feat: remove authenticated socket logic #598

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Conversation

RohitR311
Copy link
Collaborator

@RohitR311 RohitR311 commented May 18, 2025

What this PR does?

Removes the authenticated socket middleware logic and operates solely on the basis of user id

Summary by CodeRabbit

  • Refactor
    • Improved input handling by passing user ID explicitly to event handlers, simplifying authentication flow.
    • Updated socket connection setup to require user ID directly, removing internal authentication and user context registration.
    • Streamlined event registration and browser management for a more consistent user experience.

@RohitR311 RohitR311 requested a review from amhsirak May 18, 2025 06:19
@RohitR311 RohitR311 added the Type: Enhancement Improvements to existing features label May 18, 2025
Copy link

coderabbitai bot commented May 18, 2025

Walkthrough

This change refactors browser management and socket connection logic to remove implicit user authentication via sockets. User ID is now explicitly passed as an argument to relevant functions and event handlers, eliminating authentication middleware and context registration. Function signatures and event handler registrations are updated accordingly.

Changes

File(s) Change Summary
server/src/browser-management/controller.ts Removed registerBrowserUserContext import and usage. Updated createSocketConnection to accept and use userId. Changed socket namespace string format. Removed debug log and user context registration for browser creation.
server/src/browser-management/inputHandlers.ts Refactored all input handler functions to accept userId explicitly instead of extracting it from the socket. Removed dependencies on socket authentication types and interfaces. Updated function signatures and event listener registrations. Simplified handler logic by removing authentication checks and context extraction.
server/src/socket-connection/connection.ts Removed all authentication middleware, user context map, and the registerBrowserUserContext function. Changed createSocketConnection to require userId as an argument, passing it to input handler registration. Updated logic to assume user ID is provided externally. Removed authentication middleware from socket namespaces.

Sequence Diagram(s)

sequenceDiagram
    participant Controller
    participant SocketConnection
    participant InputHandlers
    participant Client

    Controller->>SocketConnection: createSocketConnection(namespace, userId, callback)
    SocketConnection->>Client: Accepts socket connection
    SocketConnection->>InputHandlers: registerInputHandlers(socket, userId)
    Client->>InputHandlers: Event (e.g., mousedown, keydown)
    InputHandlers->>InputHandlers: Handler(eventData, userId)
Loading

Possibly related PRs

Suggested labels

Type: Chore, Type: Infra

Suggested reviewers

  • amhsirak

Poem

A rabbit hops through code so bright,
Passing user IDs left and right.
No more secrets in the socket’s core,
Explicit is better—no guessing anymore!
Authentication hops away,
Simpler flows are here to stay.
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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 (4)
server/src/browser-management/controller.ts (1)

18-22: JSDoc is out-of-sync with the actual function signature

initializeRemoteBrowserForRecording now receives only userId, but the docstring still documents an options parameter.
Keeping comments accurate is key for IDE tooltips and generated docs.

- * @param options {@link RemoteBrowserOptions} to be used when launching the browser
+ * @param userId The id of the user who owns the browser session
server/src/socket-connection/connection.ts (1)

5-11: Missing documentation for the new userId parameter

The header still lists only io and callback. Please add userId to avoid confusion.

- * @param io dynamic namespace on the socket.io server
- * @param callback function called after the connection is created providing the socket resource
+ * @param io      Dynamic namespace on the socket.io server
+ * @param userId  The id of the user that owns the connection (used by input handlers)
+ * @param callback Function called after the connection is created providing the socket resource
server/src/browser-management/inputHandlers.ts (2)

15-27: Update JSDoc after signature change

handleWrapper no longer receives a socket, but the comment still describes that parameter. The same mismatch exists for most wrapper helpers below.

- * @param socket - socket with authenticated request
+ * @param userId – id of the user whose active browser should receive the event

Search & update similar blocks (onMousedown, onWheel, …) to keep generated docs valid.


480-496: registerInputHandlers now needs userId – reflect that in typings & docs

The function signature was updated, but the docstring (and external typings, if any) still show a single socket parameter. Please add the second parameter to avoid type-checking surprises for consumers.

- * @param socket websocket with established connection
+ * @param socket Websocket with established connection
+ * @param userId Id of the user owning the remote browser
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4cb9f2 and 1cb1a9b.

📒 Files selected for processing (3)
  • server/src/browser-management/controller.ts (3 hunks)
  • server/src/browser-management/inputHandlers.ts (16 hunks)
  • server/src/socket-connection/connection.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
server/src/browser-management/controller.ts (1)
server/src/server.ts (1)
  • io (79-79)
server/src/browser-management/inputHandlers.ts (1)
src/components/recorder/canvas.tsx (1)
  • Coordinates (24-27)
🔇 Additional comments (1)
server/src/socket-connection/connection.ts (1)

12-22: Potential security regression after dropping socket authentication

createSocketConnection now blindly trusts the userId supplied by the caller.
Because the namespace (io.of(id)) is public, any client that guesses or obtains the browser-id can open a socket and emit inputs that will be processed under the provided userId.

At minimum, consider:

  1. Generating an unguessable one-time token and verifying it in the connection handshake, or
  2. Re-introducing a lightweight auth check (e.g. signed JWT in the query string).

If this is handled elsewhere, please document it next to this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants