diff --git a/patches/web-server/proxy-uri.diff b/patches/web-server/proxy-uri.diff index be28869..bf171f9 100644 --- a/patches/web-server/proxy-uri.diff +++ b/patches/web-server/proxy-uri.diff @@ -74,7 +74,7 @@ Index: code-editor-src/src/vs/server/node/proxyServer.ts =================================================================== --- /dev/null +++ code-editor-src/src/vs/server/node/proxyServer.ts -@@ -0,0 +1,204 @@ +@@ -0,0 +1,215 @@ +import proxyServer from "http-proxy"; +import * as http from "http"; +import * as net from "net"; @@ -83,6 +83,7 @@ Index: code-editor-src/src/vs/server/node/proxyServer.ts +import {RemoteAgentConnectionContext} from "../../platform/remote/common/remoteAgentEnvironment.js"; +import {IServerChannel} from "../../base/parts/ipc/common/ipc.js"; +import {Emitter, Event} from "../../base/common/event.js"; ++import {requestHasValidConnectionToken, ServerConnectionToken, ServerConnectionTokenType} from "./serverConnectionToken.js"; + +type ProxyRequest = { + base?: string; @@ -105,7 +106,10 @@ Index: code-editor-src/src/vs/server/node/proxyServer.ts + public readonly onPortRemoved: Event = this._onPortRemoved.event; + public readonly onPortSynced: Event = this._onPortSynced.event; + -+ constructor(_socketServer: SocketServer) { ++ constructor( ++ _socketServer: SocketServer, ++ private readonly _connectionToken: ServerConnectionToken ++ ) { + this.proxy = proxyServer.createProxyServer({}); + this.setupProxy(); + this._socketServer = _socketServer; @@ -184,7 +188,7 @@ Index: code-editor-src/src/vs/server/node/proxyServer.ts + + private writeResponse(res: http.ServerResponse | net.Socket, code: number, message: string) { + if (res instanceof net.Socket) { -+ res.end(`HTTP/1.1 ${code} ${message}`); ++ res.end(`HTTP/1.1 ${code} ${message}\r\n\r\n`); + } else { + res.writeHead(code, message); + res.end(); @@ -201,6 +205,13 @@ Index: code-editor-src/src/vs/server/node/proxyServer.ts + return false; + } + ++ // When connection token auth is enabled, proxied ports require the same token as the workbench ++ if (this._connectionToken.type !== ServerConnectionTokenType.None ++ && !requestHasValidConnectionToken(this._connectionToken, req, url.parse(req.url ?? "", true))) { ++ this.writeResponse(res, 403, "Forbidden"); ++ return true; ++ } ++ + if (!this.validatePort(proxyRequest)) { + this.writeResponse(res, 400, "Bad Request"); + return true; @@ -306,7 +317,7 @@ Index: code-editor-src/src/vs/server/node/remoteExtensionHostAgentServer.ts ); + this._proxyServer = ( + hasWebClient -+ ? this._instantiationService.createInstance(ProxyServer, this._socketServer) ++ ? this._instantiationService.createInstance(ProxyServer, this._socketServer, this._connectionToken) + : null + ); this._logService.info(`Extension host agent started.`); @@ -670,3 +681,34 @@ Index: code-editor-src/src/vs/workbench/services/remote/common/tunnelModel.ts } private async getTunnelRestoreStorageKey(): Promise { +Index: code-editor-src/src/vs/server/node/webClientServer.ts +=================================================================== +--- code-editor-src.orig/src/vs/server/node/webClientServer.ts ++++ code-editor-src/src/vs/server/node/webClientServer.ts +@@ -280,6 +280,8 @@ export class WebClientServer { + queryConnectionToken, + { + sameSite: 'lax', ++ httpOnly: true, ++ secure: true, + maxAge: 60 * 60 * 24 * 7 /* 1 week */ + } + ); +@@ -376,6 +378,8 @@ export class WebClientServer { + + const workbenchWebConfiguration = { + remoteAuthority, ++ // The vscode-tkn cookie is HttpOnly, so the workbench gets the token from its configuration ++ connectionToken: this._connectionToken.type !== ServerConnectionTokenType.None ? this._connectionToken.value : undefined, + userDataPath: this._environmentService.userDataPath, + webviewEndpoint: staticRoute + '/out/vs/workbench/contrib/webview/browser/pre', + serverBasePath: this._basePath, +@@ -467,6 +471,8 @@ export class WebClientServer { + this._connectionToken.value, + { + sameSite: 'lax', ++ httpOnly: true, ++ secure: true, + maxAge: 60 * 60 * 24 * 7 /* 1 week */ + } + );