@@ -10,16 +10,14 @@ Index: code-server/lib/vscode/src/vs/base/common/network.ts
1010===================================================================
1111--- code-server.orig/lib/vscode/src/vs/base/common/network.ts
1212+++ code-server/lib/vscode/src/vs/base/common/network.ts
13- @@ -151,8 +151,10 @@ class RemoteAuthoritiesImpl {
14- }
13+ @@ -157,7 +157,9 @@ class RemoteAuthoritiesImpl {
1514 return URI.from({
1615 scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource,
17- - authority: `${host}:${port}`,
18- - path: `/vscode-remote-resource`,
19- + authority: platform.isWeb ? window.location.host : `${host}:${port}`,
16+ authority: `${host}:${port}`,
17+ - path: this._remoteResourcesPath,
2018+ path: platform.isWeb
21- + ? URI.joinPath(URI.parse( window.location.href), `/vscode-remote-resource`).path
22- + : `/vscode-remote-resource` ,
19+ + ? ( window.location.pathname + "/" + this._remoteResourcesPath).replace(/\/\/+/g, "/")
20+ + : this._remoteResourcesPath ,
2321 query
2422 });
2523 }
@@ -38,40 +36,28 @@ Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench-dev.html
3836
3937 <!-- Disable pinch zooming -->
4038 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
41- @@ -27,23 +27,26 @@
39+ @@ -27,9 +27,9 @@
4240 <meta id="vscode-workbench-builtin-extensions" data-settings="{{WORKBENCH_BUILTIN_EXTENSIONS}}">
4341
4442 <!-- Workbench Icon/Manifest/CSS -->
4543- <link rel="icon" href="/_static/src/browser/media/favicon-dark-support.svg" />
46- - <link rel="alternate icon" href="/_static/src/browser/media/favicon.ico" />
44+ - <link rel="alternate icon" href="/_static/src/browser/media/favicon.ico" type="image/x-icon" />
4745- <link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
4846+ <link rel="icon" href="{{BASE}}/_static/src/browser/media/favicon-dark-support.svg" />
49- + <link rel="alternate icon" href="{{BASE}}/_static/src/browser/media/favicon.ico" />
47+ + <link rel="alternate icon" href="{{BASE}}/_static/src/browser/media/favicon.ico" type="image/x-icon" />
5048+ <link rel="manifest" href="{{VS_BASE}}/manifest.json" crossorigin="use-credentials" />
5149 </head>
5250
5351 <body aria-label="">
54- </body>
55-
56- <!-- Startup (do not modify order of script tags!) -->
57- - <script src="./static/out/vs/loader.js"></script>
58- - <script src="./static/out/vs/webPackagePaths.js"></script>
59- + <script src="{{VS_BASE}}/static/out/vs/loader.js"></script>
60- + <script src="{{VS_BASE}}/static/out/vs/webPackagePaths.js"></script>
52+ @@ -39,7 +39,7 @@
53+ <script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js"></script>
54+ <script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js"></script>
6155 <script>
56+ - const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location.origin).toString();
57+ + const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location).toString();
6258 Object.keys(self.webPackagePaths).map(function (key, index) {
63- - self.webPackagePaths[key] = `${window.location.origin}/static/remote/web/node_modules/${key}/${self.webPackagePaths[key]}`;
64- + self.webPackagePaths[key] = new URL(
65- + `{{VS_BASE}}/static/remote/web/node_modules/${key}/${self.webPackagePaths[key]}`,
66- + window.location,
67- + ).toString();
59+ self.webPackagePaths[key] = `${baseUrl}/remote/web/node_modules/${key}/${self.webPackagePaths[key]}`;
6860 });
69- require.config({
70- - baseUrl: `${window.location.origin}/static/out`,
71- + baseUrl: new URL(`{{VS_BASE}}/static/out`, window.location).toString(),
72- recordStats: true,
73- trustedTypesPolicy: window.trustedTypes?.createPolicy('amdLoader', {
74- createScriptURL(value) {
7561Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.html
7662===================================================================
7763--- code-server.orig/lib/vscode/src/vs/code/browser/workbench/workbench.html
@@ -87,68 +73,32 @@ Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.html
8773
8874 <!-- Disable pinch zooming -->
8975 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
90- @@ -24,10 +24,10 @@
76+ @@ -24,9 +24,9 @@
9177 <meta id="vscode-workbench-auth-session" data-settings="{{WORKBENCH_AUTH_SESSION}}">
9278
9379 <!-- Workbench Icon/Manifest/CSS -->
9480- <link rel="icon" href="/_static/src/browser/media/favicon-dark-support.svg" />
95- - <link rel="alternate icon" href="/_static/src/browser/media/favicon.ico" />
81+ - <link rel="alternate icon" href="/_static/src/browser/media/favicon.ico" type="image/x-icon" />
9682- <link rel="manifest" href="/manifest.json" crossorigin="use-credentials" />
97- - <link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="./static/out/vs/workbench/workbench.web.main.css">
9883+ <link rel="icon" href="{{BASE}}/_static/src/browser/media/favicon-dark-support.svg" />
99- + <link rel="alternate icon" href="{{BASE}}/_static/src/browser/media/favicon.ico" />
84+ + <link rel="alternate icon" href="{{BASE}}/_static/src/browser/media/favicon.ico" type="image/x-icon" />
10085+ <link rel="manifest" href="{{VS_BASE}}/manifest.json" crossorigin="use-credentials" />
101- + <link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="{{VS_BASE}}/static /out/vs/workbench/workbench.web.main.css">
86+ <link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="{{WORKBENCH_WEB_BASE_URL}} /out/vs/workbench/workbench.web.main.css">
10287
10388 </head>
104-
105- @@ -35,14 +35,17 @@
106- </body>
107-
108- <!-- Startup (do not modify order of script tags!) -->
109- - <script src="./static/out/vs/loader.js"></script>
110- - <script src="./static/out/vs/webPackagePaths.js"></script>
111- + <script src="{{VS_BASE}}/static/out/vs/loader.js"></script>
112- + <script src="{{VS_BASE}}/static/out/vs/webPackagePaths.js"></script>
113- <script>
114- Object.keys(self.webPackagePaths).map(function (key, index) {
115- - self.webPackagePaths[key] = `${window.location.origin}/static/node_modules/${key}/${self.webPackagePaths[key]}`;
116- + self.webPackagePaths[key] = new URL(
117- + `{{VS_BASE}}/static/node_modules/${key}/${self.webPackagePaths[key]}`,
118- + window.location,
119- + ).toString();
120- });
121- require.config({
122- - baseUrl: `${window.location.origin}/static/out`,
123- + baseUrl: new URL(`{{VS_BASE}}/static/out`, window.location).toString(),
124- recordStats: true,
125- trustedTypesPolicy: window.trustedTypes?.createPolicy('amdLoader', {
126- createScriptURL(value) {
127- @@ -55,7 +58,7 @@
128- <script>
129- performance.mark('code/willLoadWorkbenchMain');
130- </script>
131- - <script src="./static/out/vs/workbench/workbench.web.main.nls.js"></script>
132- - <script src="./static/out/vs/workbench/workbench.web.main.js"></script>
133- - <script src="./static/out/vs/code/browser/workbench/workbench.js"></script>
134- + <script src="{{VS_BASE}}/static/out/vs/workbench/workbench.web.main.nls.js"></script>
135- + <script src="{{VS_BASE}}/static/out/vs/workbench/workbench.web.main.js"></script>
136- + <script src="{{VS_BASE}}/static/out/vs/code/browser/workbench/workbench.js"></script>
137- </html>
13889Index: code-server/lib/vscode/src/vs/platform/remote/browser/browserSocketFactory.ts
13990===================================================================
14091--- code-server.orig/lib/vscode/src/vs/platform/remote/browser/browserSocketFactory.ts
14192+++ code-server/lib/vscode/src/vs/platform/remote/browser/browserSocketFactory.ts
142- @@ -274,7 +274,7 @@ export class BrowserSocketFactory implem
93+ @@ -274,6 +274,7 @@ export class BrowserSocketFactory implem
14394
144- connect(host: string, port: number, query: string, debugLabel: string, callback: IConnectCallback): void {
95+ connect(host: string, port: number, path: string, query: string, debugLabel: string, callback: IConnectCallback): void {
14596 const webSocketSchema = (/^https:/.test(window.location.href) ? 'wss' : 'ws');
146- - const socket = this._webSocketFactory.create(`${webSocketSchema}://${/:/.test(host) ? `[${host}]` : host}:${port}/?${query}&skipWebSocketFrames=false`, debugLabel);
147- + const socket = this._webSocketFactory.create(`${webSocketSchema}://${window.location. host}${window.location.pathname }?${query}&skipWebSocketFrames=false`, debugLabel);
97+ + path = (window.location.pathname + "/" + path).replace(/\/\/+/g, "/")
98+ const socket = this._webSocketFactory.create(`${webSocketSchema}://${/:/.test( host) ? `[${host}]` : host}:${port}${path }?${query}&skipWebSocketFrames=false`, debugLabel);
14899 const errorListener = socket.onError((err) => callback(err, undefined));
149100 socket.onOpen(() => {
150- errorListener.dispose();
151- @@ -282,6 +282,3 @@ export class BrowserSocketFactory implem
101+ @@ -282,6 +283,3 @@ export class BrowserSocketFactory implem
152102 });
153103 }
154104 }
@@ -159,47 +109,56 @@ Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
159109===================================================================
160110--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts
161111+++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts
162- @@ -253,7 +253 ,10 @@ export class WebClientServer {
112+ @@ -267,14 +267 ,10 @@ export class WebClientServer {
163113 return res.end();
164114 }
165115
166- - const remoteAuthority = req.headers.host;
116+ - let originalHost = req.headers['x-original-host'];
117+ - if (Array.isArray(originalHost)) {
118+ - originalHost = originalHost[0];
119+ - }
120+ - const remoteAuthority = originalHost || req.headers.host;
121+ - if (!remoteAuthority) {
122+ - return serveError(req, res, 400, `Bad request.`);
123+ - }
167124+ // It is not possible to reliably detect the remote authority on the server
168125+ // in all cases. Set this to something invalid to make sure we catch code
169126+ // that is using this when it should not.
170127+ const remoteAuthority = 'remote';
171128
172- function escapeAttribute(value: string): string {
173- return value.replace(/"/g, '"');
174- @@ -275,6 +278,8 @@ export class WebClientServer {
175- accessToken: this._environmentService.args['github-auth'],
129+ function asJSON(value: unknown): string {
130+ return JSON.stringify(value).replace(/"/g, '"');
131+ @@ -297,6 +293,8 @@ export class WebClientServer {
176132 scopes: [['user:email'], ['repo']]
177133 } : undefined;
134+
178135+ const base = relativeRoot(getOriginalUrl(req))
179136+ const vscodeBase = relativePath(getOriginalUrl(req))
180- const data = (await util.promisify(fs.readFile)(filePath)).toString()
181- .replace('{{WORKBENCH_WEB_CONFIGURATION}}', escapeAttribute(JSON.stringify({
182- remoteAuthority,
183- @@ -285,6 +290,7 @@ export class WebClientServer {
184- folderUri: resolveWorkspaceURI(this._environmentService.args['default-folder']),
185- workspaceUri: resolveWorkspaceURI(this._environmentService.args['default-workspace']),
186- productConfiguration: <Partial<IProductConfiguration>>{
187- + rootEndpoint: base,
188- codeServerVersion: this._productService.codeServerVersion,
189- embedderIdentifier: 'server-distro',
190- extensionsGallery: this._webExtensionResourceUrlTemplate ? {
191- @@ -297,7 +303,9 @@ export class WebClientServer {
192- } : undefined
193- }
194- })))
195- - .replace('{{WORKBENCH_AUTH_SESSION}}', () => authSessionInfo ? escapeAttribute(JSON.stringify(authSessionInfo)) : '');
196- + .replace('{{WORKBENCH_AUTH_SESSION}}', () => authSessionInfo ? escapeAttribute(JSON.stringify(authSessionInfo)) : '')
197- + .replace(/{{BASE}}/g, base)
198- + .replace(/{{VS_BASE}}/g, vscodeBase);
199137
200- const cspDirectives = [
201- 'default-src \'self\';',
202- @@ -376,3 +384,70 @@ export class WebClientServer {
138+ const workbenchWebConfiguration = {
139+ remoteAuthority,
140+ @@ -308,6 +306,7 @@ export class WebClientServer {
141+ workspaceUri: resolveWorkspaceURI(this._environmentService.args['default-workspace']),
142+ productConfiguration: <Partial<IProductConfiguration>>{
143+ codeServerVersion: this._productService.codeServerVersion,
144+ + rootEndpoint: base,
145+ embedderIdentifier: 'server-distro',
146+ extensionsGallery: this._webExtensionResourceUrlTemplate ? {
147+ ...this._productService.extensionsGallery,
148+ @@ -328,8 +327,10 @@ export class WebClientServer {
149+ const values: { [key: string]: string } = {
150+ WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
151+ WORKBENCH_AUTH_SESSION: authSessionInfo ? asJSON(authSessionInfo) : '',
152+ - WORKBENCH_WEB_BASE_URL: this._staticRoute,
153+ - WORKBENCH_NLS_BASE_URL: nlsBaseUrl ? `${nlsBaseUrl}${this._productService.commit}/${this._productService.version}/` : '',
154+ + WORKBENCH_WEB_BASE_URL: vscodeBase + this._staticRoute,
155+ + WORKBENCH_NLS_BASE_URL: vscodeBase + (nlsBaseUrl ? `${nlsBaseUrl}${this._productService.commit}/${this._productService.version}/` : ''),
156+ + BASE: base,
157+ + VS_BASE: vscodeBase,
158+ };
159+
160+
161+ @@ -419,3 +420,70 @@ export class WebClientServer {
203162 return res.end(data);
204163 }
205164 }
@@ -286,20 +245,20 @@ Index: code-server/lib/vscode/src/vs/code/browser/workbench/workbench.ts
286245===================================================================
287246--- code-server.orig/lib/vscode/src/vs/code/browser/workbench/workbench.ts
288247+++ code-server/lib/vscode/src/vs/code/browser/workbench/workbench.ts
289- @@ -482 ,6 +482 ,7 @@ function doCreateUri(path: string, query
248+ @@ -485 ,6 +485 ,7 @@ function doCreateUri(path: string, query
290249 });
291250 }
292251
293252+ path = (window.location.pathname + "/" + path).replace(/\/\/+/g, "/")
294253 return URI.parse(window.location.href).with({ path, query });
295254 }
296255
297- @@ -493 ,7 +494 ,7 @@ function doCreateUri(path: string, query
256+ @@ -496 ,7 +497 ,7 @@ function doCreateUri(path: string, query
298257 if (!configElement || !configElementAttribute) {
299258 throw new Error('Missing web configuration element');
300259 }
301- - const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents; workspaceUri?: UriComponents } = JSON.parse(configElementAttribute);
302- + const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents, workspaceUri?: UriComponents } = { ...JSON.parse(configElementAttribute), remoteAuthority: location.host }
260+ - const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents; workspaceUri?: UriComponents; callbackRoute: string } = JSON.parse(configElementAttribute);
261+ + const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents; workspaceUri?: UriComponents; callbackRoute: string } = { ...JSON.parse(configElementAttribute), remoteAuthority: location.host }
303262
304263 // Create workbench
305264 create(document.body, {
@@ -312,10 +271,10 @@ Index: code-server/lib/vscode/src/vs/workbench/services/extensionResourceLoader/
312271 import { TelemetryLevel } from 'vs/platform/telemetry/common/telemetry';
313272 import { getTelemetryLevel, supportsTelemetry } from 'vs/platform/telemetry/common/telemetryUtils';
314273- import { RemoteAuthorities } from 'vs/base/common/network';
274+ import { getRemoteServerRootPath } from 'vs/platform/remote/common/remoteHosts';
315275
316276 export const WEB_EXTENSION_RESOURCE_END_POINT = 'web-extension-resource';
317-
318- @@ -72,7 +71,7 @@ export abstract class AbstractExtensionR
277+ @@ -75,7 +74,7 @@ export abstract class AbstractExtensionR
319278 public getExtensionGalleryResourceURL(galleryExtension: { publisher: string; name: string; version: string }, path?: string): URI | undefined {
320279 if (this._extensionGalleryResourceUrlTemplate) {
321280 const uri = URI.parse(format2(this._extensionGalleryResourceUrlTemplate, { publisher: galleryExtension.publisher, name: galleryExtension.name, version: galleryExtension.version, path: 'extension' }));
0 commit comments