@@ -4,13 +4,9 @@ import { RateLimiter as Limiter } from "limiter"
44import * as os from "os"
55import * as path from "path"
66import { rootPath } from "../constants"
7- import { authenticated , getCookieDomain , redirect , replaceTemplates } from "../http"
7+ import { authenticated , Cookie , getCookieDomain , redirect , replaceTemplates } from "../http"
88import { getPasswordMethod , handlePasswordValidation , humanPath , sanitizeString , escapeHtml } from "../util"
99
10- export enum Cookie {
11- Key = "key" ,
12- }
13-
1410// RateLimiter wraps around the limiter library for logins.
1511// It allows 2 logins every minute plus 12 logins every hour.
1612export class RateLimiter {
@@ -62,7 +58,7 @@ router.get("/", async (req, res) => {
6258 res . send ( await getRoot ( req ) )
6359} )
6460
65- router . post ( "/" , async ( req , res ) => {
61+ router . post < { } , string , { password : string ; base ?: string } , { to ?: string } > ( "/" , async ( req , res ) => {
6662 const password = sanitizeString ( req . body . password )
6763 const hashedPasswordFromArgs = req . args [ "hashed-password" ]
6864
@@ -87,13 +83,13 @@ router.post("/", async (req, res) => {
8783 if ( isPasswordValid ) {
8884 // The hash does not add any actual security but we do it for
8985 // obfuscation purposes (and as a side effect it handles escaping).
90- res . cookie ( Cookie . Key , hashedPassword , {
86+ res . cookie ( Cookie . SessionKey , hashedPassword , {
9187 domain : getCookieDomain ( req . headers . host || "" , req . args [ "proxy-domain" ] ) ,
9288 // Browsers do not appear to allow cookies to be set relatively so we
9389 // need to get the root path from the browser since the proxy rewrites
9490 // it out of the path. Otherwise code-server instances hosted on
9591 // separate sub-paths will clobber each other.
96- path : req . body . base ? path . posix . join ( req . body . base , ".." ) : "/" ,
92+ path : req . body . base ? path . posix . join ( req . body . base , ".." , "/" ) : "/" ,
9793 sameSite : "lax" ,
9894 } )
9995
0 commit comments