Repository navigation
fix(server): resolve trusted client IPs for live queries - #437
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2a29284. Configure here.
|
Thanks for digging into this, and for the thorough tests. You're right that anonymous session creation can be abused. While reviewing, we traced it to the cause: Because of that, we don't want to merge the per-IP limiter. As it stands it would also hurt legitimate traffic:
Could you narrow this PR to the parts that stand on their own? We'd be glad to merge:
Please drop the One optional suggestion: resolving the Socket.IO client IP without building a fake Express request (for example, calling Thanks again, this was a useful find. |
|
Thanks, Hayk. I narrowed the PR to the proxy IP and HTTP error-handling changes. Socket.IO now reads the IP directly from the upgrade request, and the tests check the address that live-query methods receive. |
omegascorp
left a comment
There was a problem hiding this comment.
Thank you, looks good
The live-query client IP test from #437 asserted authenticate calls without options. This branch passes persistNewSession: false on the Socket.IO handshake and live-query subscriptions, so assert that. Co-Authored-By: Claude Opus 5.5 <[email protected]>

I moved the shared IP code into
clientIp.tsand switched Socket.IO toproxy-addron the upgrade request. It uses the same trusted proxy settings as HTTP, and live queries get that address inconnectionInfo.ip.I also moved
getCallContextinside the method route'stryblock and wrapped the OAuth linking routes. Those routes return the HTTP status for known Modelence errors and pass unexpected errors to Express.Refs #312.
I ran the affected tests and all 149 passed. They cover trusted proxy chains, forged headers and subscription payloads, and auth errors before a method runs. Lint and build passed, and formatting passed with
--end-of-line autoon Windows. The full suite had 1,460 passes and the same 10 Windows failures I saw before (authCache,deploySpec,dev, andsource).Note
Medium Risk
Changes trusted-proxy and client-IP behavior for WebSocket live queries and auth endpoints; mistakes could mis-attribute IPs for rate limits or alter error responses on OAuth linking.
Overview
Adds shared client IP resolution via a new
clientIpmodule (usingproxy-addr) so HTTP and Socket.IO apply the same trusted-proxy rules—config,MODELENCE_TRUSTED_PROXIES, and optional headers likecf-connecting-iponly when the socket peer is trusted.Socket.IO live queries now take the client address from the WebSocket upgrade request (not spoofable subscription payloads or
handshake.address), soconnectionInfo.ipmatches HTTP for rate limits and auditing behind reverse proxies.Auth error handling is tightened:
handleAuthRequeston OAuth link cookie/nonce routes returnsModelenceErrorstatuses directly; unexpected errors go to Expressnext. The internal method route returns 401 when session lookup fails before the method runs, instead of treating it as a 500.Adds
proxy-addrand tests for proxy chains, forged headers, and auth failures.Reviewed by Cursor Bugbot for commit 0eca775. Bugbot is set up for automated code reviews on this repo. Configure here.