Skip to content

Commit 6769556

Browse files
committed
fix: devtools csp to use 127.0.0.1
1 parent e563e4f commit 6769556

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

lib/common/services/net-service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Net implements INet {
1818
private $errors: IErrors,
1919
private $childProcess: IChildProcess,
2020
private $logger: ILogger,
21-
private $osInfo: IOsInfo
21+
private $osInfo: IOsInfo,
2222
) {}
2323

2424
public async getFreePort(): Promise<number> {
@@ -76,13 +76,13 @@ export class Net implements INet {
7676
server.close();
7777
});
7878

79-
server.listen(port, "localhost");
79+
server.listen(port, "127.0.0.1");
8080
});
8181
}
8282

8383
public async getAvailablePortInRange(
8484
startPort: number,
85-
endPort?: number
85+
endPort?: number,
8686
): Promise<number> {
8787
endPort = endPort || 65534;
8888
while (!(await this.isPortAvailable(startPort))) {
@@ -96,7 +96,7 @@ export class Net implements INet {
9696
}
9797

9898
public async waitForPortToListen(
99-
waitForPortListenData: IWaitForPortListenData
99+
waitForPortListenData: IWaitForPortListenData,
100100
): Promise<boolean> {
101101
if (!waitForPortListenData) {
102102
this.$errors.fail("You must pass port and timeout for check.");
@@ -126,8 +126,8 @@ export class Net implements INet {
126126
if (!currentPlatformData) {
127127
this.$errors.fail(
128128
`Unable to check for free ports on ${platform}. Supported platforms are: ${_.keys(
129-
platformData
130-
).join(", ")}`
129+
platformData,
130+
).join(", ")}`,
131131
);
132132
}
133133

lib/device-sockets/ios/app-debug-socket-proxy-factory.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export class AppDebugSocketProxyFactory
2121
private $lockService: ILockService,
2222
private $options: IOptions,
2323
private $tempService: ITempService,
24-
private $net: INet
24+
private $net: INet,
2525
) {
2626
super();
2727
}
2828

2929
public getTCPSocketProxy(
3030
deviceIdentifier: string,
31-
appId: string
31+
appId: string,
3232
): net.Server {
3333
return this.deviceTcpServers[`${deviceIdentifier}-${appId}`];
3434
}
@@ -37,18 +37,18 @@ export class AppDebugSocketProxyFactory
3737
device: Mobile.IiOSDevice,
3838
appId: string,
3939
projectName: string,
40-
projectDir: string
40+
projectDir: string,
4141
): Promise<net.Server> {
4242
const cacheKey = `${device.deviceInfo.identifier}-${appId}`;
4343
const existingServer = this.deviceTcpServers[cacheKey];
4444
if (existingServer) {
4545
this.$errors.fail(
46-
`TCP socket proxy is already running for device '${device.deviceInfo.identifier}' and app '${appId}'`
46+
`TCP socket proxy is already running for device '${device.deviceInfo.identifier}' and app '${appId}'`,
4747
);
4848
}
4949

5050
this.$logger.info(
51-
"\nSetting up proxy...\nPress Ctrl + C to terminate, or disconnect.\n"
51+
"\nSetting up proxy...\nPress Ctrl + C to terminate, or disconnect.\n",
5252
);
5353

5454
const server = net.createServer({
@@ -69,7 +69,7 @@ export class AppDebugSocketProxyFactory
6969
const appDebugSocket = await device.getDebugSocket(
7070
appId,
7171
projectName,
72-
projectDir
72+
projectDir,
7373
);
7474
this.$logger.info("Backend socket created.");
7575

@@ -112,7 +112,7 @@ export class AppDebugSocketProxyFactory
112112
device: Mobile.IiOSDevice,
113113
appId: string,
114114
projectName: string,
115-
projectDir: string
115+
projectDir: string,
116116
): Promise<ws.Server> {
117117
const existingWebProxy =
118118
this.deviceWebServers[`${device.deviceInfo.identifier}-${appId}`];
@@ -130,22 +130,22 @@ export class AppDebugSocketProxyFactory
130130
device: Mobile.IiOSDevice,
131131
appId: string,
132132
projectName: string,
133-
projectDir: string
133+
projectDir: string,
134134
): Promise<ws.Server> {
135135
let clientConnectionLockRelease: () => void;
136136
const cacheKey = `${device.deviceInfo.identifier}-${appId}`;
137137
const existingServer = this.deviceWebServers[cacheKey];
138138
if (existingServer) {
139139
this.$errors.fail(
140-
`Web socket proxy is already running for device '${device.deviceInfo.identifier}' and app '${appId}'`
140+
`Web socket proxy is already running for device '${device.deviceInfo.identifier}' and app '${appId}'`,
141141
);
142142
}
143143

144144
// NOTE: We will try to provide command line options to select ports, at least on the localhost.
145145
const localPort = await this.$net.getAvailablePortInRange(41000);
146146

147147
this.$logger.info(
148-
"\nSetting up debugger proxy...\nPress Ctrl + C to terminate, or disconnect.\n"
148+
"\nSetting up debugger proxy...\nPress Ctrl + C to terminate, or disconnect.\n",
149149
);
150150

151151
// NB: When the inspector frontend connects we might not have connected to the inspector backend yet.
@@ -156,17 +156,18 @@ export class AppDebugSocketProxyFactory
156156
let currentAppSocket: net.Socket = null;
157157
let currentWebSocket: ws = null;
158158
const server = new ws.Server(<any>{
159+
host: "127.0.0.1",
159160
port: localPort,
160161
verifyClient: async (
161162
info: any,
162-
callback: (res: boolean, code?: number, message?: string) => void
163+
callback: (res: boolean, code?: number, message?: string) => void,
163164
) => {
164165
let acceptHandshake = true;
165166
clientConnectionLockRelease = null;
166167

167168
try {
168169
clientConnectionLockRelease = await this.$lockService.lock(
169-
`debug-connection-${device.deviceInfo.identifier}-${appId}.lock`
170+
`debug-connection-${device.deviceInfo.identifier}-${appId}.lock`,
170171
);
171172

172173
this.$logger.info("Frontend client connected.");
@@ -184,7 +185,7 @@ export class AppDebugSocketProxyFactory
184185
appDebugSocket = await device.getDebugSocket(
185186
appId,
186187
projectName,
187-
projectDir
188+
projectDir,
188189
);
189190
currentAppSocket = appDebugSocket;
190191
this.$logger.info("Backend socket created.");
@@ -198,7 +199,7 @@ export class AppDebugSocketProxyFactory
198199
this.emit(CONNECTION_ERROR_EVENT_NAME, err);
199200
acceptHandshake = false;
200201
this.$logger.warn(
201-
`Cannot connect to device socket. The error message is '${err.message}'.`
202+
`Cannot connect to device socket. The error message is '${err.message}'.`,
202203
);
203204
}
204205

@@ -225,7 +226,7 @@ export class AppDebugSocketProxyFactory
225226
webSocket.send(message);
226227
} else {
227228
this.$logger.trace(
228-
`Received message ${message}, but unable to send it to webSocket as its state is: ${webSocket.readyState}`
229+
`Received message ${message}, but unable to send it to webSocket as its state is: ${webSocket.readyState}`,
229230
);
230231
}
231232
});

lib/services/debug-service-base.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {
88

99
export abstract class DebugServiceBase
1010
extends EventEmitter
11-
implements IDeviceDebugService {
11+
implements IDeviceDebugService
12+
{
1213
constructor(
1314
protected device: Mobile.IDevice,
14-
protected $devicesService: Mobile.IDevicesService
15+
protected $devicesService: Mobile.IDevicesService,
1516
) {
1617
super();
1718
}
@@ -20,20 +21,21 @@ export abstract class DebugServiceBase
2021

2122
public abstract debug(
2223
debugData: IDebugData,
23-
debugOptions: IDebugOptions
24+
debugOptions: IDebugOptions,
2425
): Promise<IDebugResultInfo>;
2526

2627
public abstract debugStop(): Promise<void>;
2728

2829
protected getCanExecuteAction(
29-
deviceIdentifier: string
30+
deviceIdentifier: string,
3031
): (device: Mobile.IDevice) => boolean {
3132
return (device: Mobile.IDevice): boolean => {
3233
if (deviceIdentifier) {
3334
let isSearchedDevice =
3435
device.deviceInfo.identifier === deviceIdentifier;
3536
if (!isSearchedDevice) {
36-
const deviceByDeviceOption = this.$devicesService.getDeviceByDeviceOption();
37+
const deviceByDeviceOption =
38+
this.$devicesService.getDeviceByDeviceOption();
3739
isSearchedDevice =
3840
deviceByDeviceOption &&
3941
device.deviceInfo.identifier ===
@@ -49,7 +51,7 @@ export abstract class DebugServiceBase
4951

5052
protected getChromeDebugUrl(
5153
debugOptions: IDebugOptions,
52-
port: number
54+
port: number,
5355
): string {
5456
// corresponds to 55.0.2883 Chrome version
5557
// SHA is taken from https://chromium.googlesource.com/chromium/src/+/55.0.2883.100
@@ -74,7 +76,7 @@ export abstract class DebugServiceBase
7476
chromeDevToolsPrefix = `https://chrome-devtools-frontend.appspot.com/serve_file/@${commitSHA}`;
7577
}
7678

77-
const chromeUrl = `${chromeDevToolsPrefix}/inspector.html?ws=localhost:${port}`;
79+
const chromeUrl = `${chromeDevToolsPrefix}/inspector.html?ws=127.0.0.1:${port}`;
7880
return chromeUrl;
7981
}
8082
}

0 commit comments

Comments
 (0)