@@ -3,14 +3,11 @@ import { promises as fs } from "fs"
33import { RateLimiter as Limiter } from "limiter"
44import * as os from "os"
55import * as path from "path"
6+ import { CookieKeys } from "../../common/http"
67import { rootPath } from "../constants"
78import { authenticated , getCookieDomain , redirect , replaceTemplates } from "../http"
89import { getPasswordMethod , handlePasswordValidation , humanPath , sanitizeString , escapeHtml } from "../util"
910
10- export enum Cookie {
11- Key = "key" ,
12- }
13-
1411// RateLimiter wraps around the limiter library for logins.
1512// It allows 2 logins every minute plus 12 logins every hour.
1613export class RateLimiter {
@@ -62,7 +59,7 @@ router.get("/", async (req, res) => {
6259 res . send ( await getRoot ( req ) )
6360} )
6461
65- router . post ( "/" , async ( req , res ) => {
62+ router . post < { } , string , { password : string ; base ?: string } , { to ?: string } > ( "/" , async ( req , res ) => {
6663 const password = sanitizeString ( req . body . password )
6764 const hashedPasswordFromArgs = req . args [ "hashed-password" ]
6865
@@ -87,13 +84,13 @@ router.post("/", async (req, res) => {
8784 if ( isPasswordValid ) {
8885 // The hash does not add any actual security but we do it for
8986 // obfuscation purposes (and as a side effect it handles escaping).
90- res . cookie ( Cookie . Key , hashedPassword , {
87+ res . cookie ( CookieKeys . Session , hashedPassword , {
9188 domain : getCookieDomain ( req . headers . host || "" , req . args [ "proxy-domain" ] ) ,
9289 // Browsers do not appear to allow cookies to be set relatively so we
9390 // need to get the root path from the browser since the proxy rewrites
9491 // it out of the path. Otherwise code-server instances hosted on
9592 // separate sub-paths will clobber each other.
96- path : req . body . base ? path . posix . join ( req . body . base , ".." ) : "/" ,
93+ path : req . body . base ? path . posix . join ( req . body . base , ".." , "/" ) : "/" ,
9794 sameSite : "lax" ,
9895 } )
9996
0 commit comments