Add support to binding both IPv6 and IPv4 ports
Summary: Add support for binding the same port in flipper in both the IPv6 and IPv4 interfaces Reviewed By: mweststrate Differential Revision: D34591022 fbshipit-source-id: e28239c24425885ee442d93b84bb38902d521a0c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7222437beb
commit
5b5ce92519
@@ -57,17 +57,22 @@ function startAssetServer(
|
|||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
server.listen(config.port, 'localhost', () => resolve({app, server}));
|
server.listen(config.port, undefined, () => resolve({app, server}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addWebsocket(server: http.Server, config: Config) {
|
function addWebsocket(server: http.Server, config: Config) {
|
||||||
const validHost = `localhost:${config.port}`;
|
const localhostIPV4 = `localhost:${config.port}`;
|
||||||
|
const localhostIPV6 = `[::1]:${config.port}`;
|
||||||
const io = new socketio.Server(server, {
|
const io = new socketio.Server(server, {
|
||||||
maxHttpBufferSize: WEBSOCKET_MAX_MESSAGE_SIZE,
|
maxHttpBufferSize: WEBSOCKET_MAX_MESSAGE_SIZE,
|
||||||
allowRequest(req, callback) {
|
allowRequest(req, callback) {
|
||||||
const noOriginHeader = req.headers.origin === undefined;
|
const noOriginHeader = req.headers.origin === undefined;
|
||||||
if (noOriginHeader && req.headers.host === validHost) {
|
if (
|
||||||
|
noOriginHeader &&
|
||||||
|
(req.headers.host === localhostIPV4 ||
|
||||||
|
req.headers.host === localhostIPV6)
|
||||||
|
) {
|
||||||
// no origin header? Either the request is not cross-origin,
|
// no origin header? Either the request is not cross-origin,
|
||||||
// or the request is not originating from a browser, so should be OK to pass through
|
// or the request is not originating from a browser, so should be OK to pass through
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
@@ -79,7 +84,7 @@ function addWebsocket(server: http.Server, config: Config) {
|
|||||||
// directly from intern. But before that, we should either authenticate the request somehow,
|
// directly from intern. But before that, we should either authenticate the request somehow,
|
||||||
// and discuss security impact and for example scope the files that can be read by Flipper.
|
// and discuss security impact and for example scope the files that can be read by Flipper.
|
||||||
console.warn(
|
console.warn(
|
||||||
`Refused sockect connection from cross domain request, origin: ${req.headers.origin}, host: ${req.headers.host}. Expected: ${validHost}`,
|
`Refused sockect connection from cross domain request, origin: ${req.headers.origin}, host: ${req.headers.host}. Expected: ${localhostIPV4} or ${localhostIPV6}`,
|
||||||
);
|
);
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user