@@ -63,7 +63,7 @@ import { TelemetryClient } from "vs/server/src/node/insights";
63
63
import { getLocaleFromConfig , getNlsConfiguration } from "vs/server/src/node/nls" ;
64
64
import { Protocol } from "vs/server/src/node/protocol" ;
65
65
import { 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" ;
67
67
import { RemoteExtensionLogFileName } from "vs/workbench/services/remote/common/remoteAgentService" ;
68
68
import { IWorkbenchConstructionOptions } from "vs/workbench/workbench.web.api" ;
69
69
@@ -98,7 +98,11 @@ export interface Response {
98
98
}
99
99
100
100
export interface LoginPayload {
101
- password ?: string [ ] | string ;
101
+ password ?: string ;
102
+ }
103
+
104
+ export interface AuthPayload {
105
+ key ?: string [ ] ;
102
106
}
103
107
104
108
export class HttpError extends Error {
@@ -137,6 +141,7 @@ export abstract class Server {
137
141
host : options . auth === "password" && options . cert ? "0.0.0.0" : "localhost" ,
138
142
...options ,
139
143
basePath : options . basePath ? options . basePath . replace ( / \/ + $ / , "" ) : "" ,
144
+ password : options . password ? hash ( options . password ) : undefined ,
140
145
} ;
141
146
this . protocol = this . options . cert ? "https" : "http" ;
142
147
if ( this . protocol === "https" ) {
@@ -357,11 +362,11 @@ export abstract class Server {
357
362
}
358
363
359
364
private async tryLogin ( request : http . IncomingMessage ) : Promise < Response > {
360
- const redirect = ( password ? : string | string [ ] | true ) => {
365
+ const redirect = ( password : string | true ) => {
361
366
return {
362
367
redirect : "/" ,
363
368
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` }
365
370
: { } ,
366
371
} ;
367
372
} ;
@@ -371,8 +376,11 @@ export abstract class Server {
371
376
}
372
377
if ( request . method === "POST" ) {
373
378
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 ) ;
376
384
}
377
385
console . error ( "Failed login attempt" , JSON . stringify ( {
378
386
xForwardedFor : request . headers [ "x-forwarded-for" ] ,
@@ -432,19 +440,18 @@ export abstract class Server {
432
440
: Promise . resolve ( { } as T ) ;
433
441
}
434
442
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 ") {
437
445
return true ;
438
446
}
439
447
const safeCompare = localRequire < typeof import ( "safe-compare" ) > ( "safe-compare/index" ) ;
440
448
if ( typeof payload === "undefined" ) {
441
- payload = this . parseCookies < LoginPayload > ( request ) ;
449
+ payload = this . parseCookies < AuthPayload > ( request ) ;
442
450
}
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 ] ;
448
455
}
449
456
}
450
457
}
0 commit comments