Skip to content

Commit

Permalink
Fetch web worker extension host from localhost instead of cdn (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
minestarks authored Oct 20, 2023
1 parent 411f119 commit 8f05c12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ export default async function createApp(config: IConfig): Promise<Koa> {
allowMethods: ['GET'],
credentials: true,
origin: (ctx: Koa.Context) => {
const origin = ctx.get('Origin');
if (
/^https:\/\/[^.]+\.vscode-cdn\.net$/.test(ctx.get('Origin')) || // needed for the webviewContent
/^https:\/\/[^.]+\.vscode-webview\.net$/.test(ctx.get('Origin'))
/^https:\/\/[^.]+\.vscode-cdn\.net$/.test(origin) || // needed for the webviewContent
/^https:\/\/[^.]+\.vscode-webview\.net$/.test(origin) ||
new RegExp(`^${ctx.protocol}://[^.]+\\.${ctx.host}$`).test(origin) // match subdomains of localhost
) {
return ctx.get('Origin');
return origin;
}

return undefined as any;
},
})
);

if (config.build.type !== 'sources') {
if (config.build.type !== 'sources' && config.build.type !== 'static') {
// CSP: frame-ancestors
app.use((ctx, next) => {
ctx.set('Content-Security-Policy', `frame-ancestors 'none'`);
Expand Down
6 changes: 5 additions & 1 deletion src/server/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ export default function (config: IConfig): Router.Middleware {
const productOverrides = await getProductOverrides(config.build.location);
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, config.esm, builtInExtensions, productOverrides);
} else if (config.build.type === 'static') {
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/build`, false, config.esm);
const baseUrl = `${ctx.protocol}://${ctx.host}/static/build`;
const baseUrlTemplate = `${ctx.protocol}://{{uuid}}.${ctx.host}/static/build`;
ctx.state.workbench = new Workbench(baseUrl, false, config.esm, [], {
webEndpointUrlTemplate: baseUrlTemplate,
});
} else if (config.build.type === 'cdn') {
ctx.state.workbench = new Workbench(config.build.uri, false, config.esm);
}
Expand Down

0 comments on commit 8f05c12

Please sign in to comment.