From aca1aca29c493249bb965919257d86dfeb259ab3 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Tue, 17 May 2022 04:20:30 -0700 Subject: [PATCH] Accept connections from localhost coming from port 3000 Summary: ^ flipper-server verifies the origin of incoming connections as a way of preventing any host from connecting to flipper. That's good. This change expand the list of allowed origins to include localhost:3000 which is the default origin for Electron apps. Error without this change: ``` Refused socket connection from cross domain request, origin: http://localhost:3000, host: localhost:52342. Expected origins: http://localhost:52342 or http://[::1]:52342 or http://::1:52342. Expected hosts: localhost:52342 or [::1]:52342 or ::1:52342 ``` Reviewed By: passy Differential Revision: D36440363 fbshipit-source-id: 883cadb49f245bca5d0a53a4f58c08cf45dd0189 --- desktop/flipper-server/src/startServer.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/desktop/flipper-server/src/startServer.tsx b/desktop/flipper-server/src/startServer.tsx index 47f6c7891..522c220f3 100644 --- a/desktop/flipper-server/src/startServer.tsx +++ b/desktop/flipper-server/src/startServer.tsx @@ -211,8 +211,14 @@ function addWebsocket(server: http.Server, config: Config) { const localhostIPV4 = `localhost:${config.port}`; const localhostIPV6 = `[::1]:${config.port}`; const localhostIPV6NoBrackets = `::1:${config.port}`; + const localhostIPV4Electron = 'localhost:3000'; - const possibleHosts = [localhostIPV4, localhostIPV6, localhostIPV6NoBrackets]; + const possibleHosts = [ + localhostIPV4, + localhostIPV6, + localhostIPV6NoBrackets, + localhostIPV4Electron, + ]; const possibleOrigins = possibleHosts.map((host) => `http://${host}`); const verifyClient: VerifyClientCallbackSync = ({origin, req}) => {