Skip to content

Commit f828c69

Browse files
committed
Tighten up CORS to ensure MitM HTTP isn't enough to start an interceptor
1 parent 06dae9d commit f828c69

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/error-tracking.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as Sentry from '@sentry/node';
2+
import { IS_PROD_BUILD } from './util';
23

34
let sentryInitialized = false;
45

56
export function initErrorTracking() {
67
const packageJson = require('../package.json');
78

89
let { SENTRY_DSN } = process.env;
9-
if (!SENTRY_DSN && process.env.HTTPTOOLKIT_SERVER_BINPATH) {
10+
if (!SENTRY_DSN && IS_PROD_BUILD) {
1011
// If we're a built binary, use the standard DSN automatically
1112
SENTRY_DSN = 'https://[email protected]/1371158';
1213
}

src/httptoolkit-server.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GraphQLScalarType } from 'graphql';
66
import { HtkConfig } from './config';
77
import { reportError } from './error-tracking';
88
import { buildInterceptors, Interceptor } from './interceptors';
9+
import { IS_PROD_BUILD } from './util';
910

1011
const packageJson = require('../package.json');
1112

@@ -160,10 +161,24 @@ export class HttpToolkitServer extends events.EventEmitter {
160161
port: { port: 45457, host: 'localhost' },
161162
playground: false,
162163
cors: {
163-
origin: [
164-
/https?:\/\/localhost(:\d+)?$/,
165-
/\.httptoolkit\.tech(:\d+)?$/
166-
]
164+
origin: IS_PROD_BUILD
165+
? [
166+
// Prod builds only allow HTTPS app.httptoolkit.tech usage. This
167+
// ensures that no other sites/apps can communicate with your server
168+
// whilst you have the app open. If they could (requires an HTTP mitm),
169+
// they would be able to start proxies & interceptors. It's not remote
170+
// execution, but it's definitely not desirable.
171+
/^https:\/\/app\.httptoolkit\.tech$/
172+
]
173+
: [
174+
// Dev builds can use the main site, or local sites, even if those
175+
// use HTTP. Note that HTTP here could technically open you to the risk
176+
// above, but it'd require a DNS MitM too (to stop local.httptoolkit.tech
177+
// resolving to localhost and never hitting the network).
178+
/^https?:\/\/localhost(:\d+)?$/,
179+
/^http:\/\/local\.httptoolkit\.tech(:\d+)?$/,
180+
/^https:\/\/app\.httptoolkit\.tech$/
181+
]
167182
}
168183
});
169184
}

src/interceptors/fresh-chrome.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { promisify } from 'util';
22
import * as fs from 'fs';
3-
import * as path from 'path';
43

54
import * as _ from 'lodash';
65
import { generateSPKIFingerprint } from 'mockttp';

src/util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export function delay(durationMs: number): Promise<void> {
22
return new Promise((resolve) => setTimeout(resolve, durationMs));
3-
}
3+
}
4+
5+
export const IS_PROD_BUILD = !!process.env.HTTPTOOLKIT_SERVER_BINPATH;

0 commit comments

Comments
 (0)