@@ -63,7 +63,7 @@ import { TelemetryClient } from "vs/server/src/node/insights";
6363import { getLocaleFromConfig , getNlsConfiguration } from "vs/server/src/node/nls" ;
6464import { Protocol } from "vs/server/src/node/protocol" ;
6565import { UpdateService } from "vs/server/src/node/update" ;
66- import { AuthType , getMediaMime , getUriTransformer , localRequire , tmpdir } from "vs/server/src/node/util" ;
66+ import { AuthType , getMediaMime , getUriTransformer , hash , localRequire , tmpdir } from "vs/server/src/node/util" ;
6767import { RemoteExtensionLogFileName } from "vs/workbench/services/remote/common/remoteAgentService" ;
6868import { IWorkbenchConstructionOptions } from "vs/workbench/workbench.web.api" ;
6969
@@ -98,7 +98,11 @@ export interface Response {
9898}
9999
100100export interface LoginPayload {
101- password ?: string [ ] | string ;
101+ password ?: string ;
102+ }
103+
104+ export interface AuthPayload {
105+ key ?: string [ ] ;
102106}
103107
104108export class HttpError extends Error {
@@ -137,6 +141,7 @@ export abstract class Server {
137141 host : options . auth === "password" && options . cert ? "0.0.0.0" : "localhost" ,
138142 ...options ,
139143 basePath : options . basePath ? options . basePath . replace ( / \/ + $ / , "" ) : "" ,
144+ password : options . password ? hash ( options . password ) : undefined ,
140145 } ;
141146 this . protocol = this . options . cert ? "https" : "http" ;
142147 if ( this . protocol === "https" ) {
@@ -357,11 +362,11 @@ export abstract class Server {
357362 }
358363
359364 private async tryLogin ( request : http . IncomingMessage ) : Promise < Response > {
360- const redirect = ( password ? : string | string [ ] | true ) => {
365+ const redirect = ( password : string | true ) => {
361366 return {
362367 redirect : "/" ,
363368 headers : typeof password === "string"
364- ? { "Set-Cookie" : `password =${ password } ; Path=${ this . options . basePath || "/" } ; HttpOnly; SameSite=strict` }
369+ ? { "Set-Cookie" : `key =${ password } ; Path=${ this . options . basePath || "/" } ; HttpOnly; SameSite=strict` }
365370 : { } ,
366371 } ;
367372 } ;
@@ -371,8 +376,11 @@ export abstract class Server {
371376 }
372377 if ( request . method === "POST" ) {
373378 const data = await this . getData < LoginPayload > ( request ) ;
374- if ( this . authenticate ( request , data ) ) {
375- return redirect ( data . password ) ;
379+ const password = this . authenticate ( request , {
380+ key : typeof data . password === "string" ? [ hash ( data . password ) ] : undefined ,
381+ } ) ;
382+ if ( password ) {
383+ return redirect ( password ) ;
376384 }
377385 console . error ( "Failed login attempt" , JSON . stringify ( {
378386 xForwardedFor : request . headers [ "x-forwarded-for" ] ,
@@ -432,19 +440,18 @@ export abstract class Server {
432440 : Promise . resolve ( { } as T ) ;
433441 }
434442
435- private authenticate ( request : http . IncomingMessage , payload ?: LoginPayload ) : string | boolean {
436- if ( this . options . auth !== "password ") {
443+ private authenticate ( request : http . IncomingMessage , payload ?: AuthPayload ) : string | boolean {
444+ if ( this . options . auth === "none ") {
437445 return true ;
438446 }
439447 const safeCompare = localRequire < typeof import ( "safe-compare" ) > ( "safe-compare/index" ) ;
440448 if ( typeof payload === "undefined" ) {
441- payload = this . parseCookies < LoginPayload > ( request ) ;
449+ payload = this . parseCookies < AuthPayload > ( request ) ;
442450 }
443- if ( this . options . password && payload . password ) {
444- const toTest = Array . isArray ( payload . password ) ? payload . password : [ payload . password ] ;
445- for ( let i = 0 ; i < toTest . length ; ++ i ) {
446- if ( safeCompare ( toTest [ i ] , this . options . password ) ) {
447- return toTest [ i ] ;
451+ if ( this . options . password && payload . key ) {
452+ for ( let i = 0 ; i < payload . key . length ; ++ i ) {
453+ if ( safeCompare ( payload . key [ i ] , this . options . password ) ) {
454+ return payload . key [ i ] ;
448455 }
449456 }
450457 }
0 commit comments