From d78a8ee50bff51ca73b4bdbe69eba3cc43367699 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Mon, 24 Jun 2024 08:24:21 -0700 Subject: [PATCH] Inspector: Enforce device and appId filters if both are given to /open-debugger Summary: Previously, if the `/open-debugger` endpoint was provided with both `device` and `appId` query params, we would: - Try to find a target with a matching `device` (note that these logical "devices" are unique per-app) - if found, use it. Otherwise, - Try to find a target with a matching `appId` - if found, use that. This could go "wrong" in two ways: - If a `device` is given with a spurious `appId`, we'd open to a target with an `appId` differing from the one specified. - If the `device` has gone away but there is a different target with the same app, we'd use that as a fallback (right app, wrong device). This applies the filters more strictly so that if both are given, both must match. Changelog: [General][Changed]: Inspector: Enforce device and appId filters if both are given to /open-debugger Differential Revision: D58951952 --- packages/dev-middleware/src/index.flow.js | 1 + .../src/middleware/openDebuggerMiddleware.js | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/dev-middleware/src/index.flow.js b/packages/dev-middleware/src/index.flow.js index 6bd13afb5f84..6ac97fdc41d3 100644 --- a/packages/dev-middleware/src/index.flow.js +++ b/packages/dev-middleware/src/index.flow.js @@ -18,3 +18,4 @@ export type { CustomMessageHandlerConnection, CreateCustomMessageHandlerFn, } from './inspector-proxy/CustomMessageHandler'; +export type {PageDescription} from './inspector-proxy/types'; diff --git a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js index 7aa102ab7baa..413ce6447e1d 100644 --- a/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js +++ b/packages/dev-middleware/src/middleware/openDebuggerMiddleware.js @@ -78,14 +78,11 @@ export default function openDebuggerMiddleware({ (launchType === 'launch' ? 'Launching' : 'Redirecting to') + ' JS debugger (experimental)...', ); - if (typeof device === 'string') { - target = targets.find( - _target => _target.reactNative.logicalDeviceId === device, - ); - } - if (!target && typeof appId === 'string') { - target = targets.find(_target => _target.description === appId); - } + target = targets.find( + _target => + (appId == null || _target.description === appId) && + (device == null || _target.reactNative.logicalDeviceId === device), + ); } else if (targets.length > 0) { logger?.info( (launchType === 'launch' ? 'Launching' : 'Redirecting to') +