Skip to content

Commit 932f03b

Browse files
committed
Allow webextension to manage Mockttp
1 parent 0286053 commit 932f03b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/constants.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ export const ALLOWED_ORIGINS = IS_PROD_BUILD
2121
// resolving to localhost and never hitting the network).
2222
/^https?:\/\/localhost(:\d+)?$/,
2323
/^http:\/\/local\.httptoolkit\.tech(:\d+)?$/,
24-
/^https:\/\/app\.httptoolkit\.tech$/
25-
]
24+
/^https:\/\/app\.httptoolkit\.tech$/,
25+
];
26+
27+
export const MOCKTTP_ALLOWED_ORIGINS = [
28+
...ALLOWED_ORIGINS,
29+
// The Chromium webextension is allowed to make requests from the
30+
// browser directly into the Mockttp admin API (but not into our API server).
31+
'chrome-extension://jggocihfdfgogbofcmdlfbakdkgdkdoe'
32+
];
2633

2734
// The range of ports that should be used by invisible ephemeral services, such as Firefox's
2835
// certificate check server and Chrome's "hide warning" server. These ports are extra likely

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import updateCommand from '@oclif/plugin-update/lib/commands/update';
1010
import { HttpToolkitServerApi } from './api-server';
1111
import { checkBrowserConfig } from './browsers';
1212
import { reportError } from './error-tracking';
13-
import { ALLOWED_ORIGINS } from './constants';
13+
import { MOCKTTP_ALLOWED_ORIGINS } from './constants';
1414

1515
import { delay } from './util/promise';
1616
import { isErrorLike } from './util/error';
@@ -121,7 +121,7 @@ export async function runHTK(options: {
121121
},
122122
corsOptions: {
123123
strict: true, // For the standalone admin API, require valid CORS headers
124-
origin: ALLOWED_ORIGINS, // Only allow requests from our origins, to avoid XSRF
124+
origin: MOCKTTP_ALLOWED_ORIGINS, // Only allow mock admin control from our origins
125125
maxAge: 86400, // Cache CORS responses for as long as possible
126126
allowPrivateNetworkAccess: true // Allow access from non-local domains in Chrome 102+
127127
},

0 commit comments

Comments
 (0)