@@ -3,14 +3,11 @@ import { promises as fs } from "fs"
3
3
import { RateLimiter as Limiter } from "limiter"
4
4
import * as os from "os"
5
5
import * as path from "path"
6
+ import { CookieKeys } from "../../common/http"
6
7
import { rootPath } from "../constants"
7
8
import { authenticated , getCookieDomain , redirect , replaceTemplates } from "../http"
8
9
import { getPasswordMethod , handlePasswordValidation , humanPath , sanitizeString , escapeHtml } from "../util"
9
10
10
- export enum Cookie {
11
- Key = "key" ,
12
- }
13
-
14
11
// RateLimiter wraps around the limiter library for logins.
15
12
// It allows 2 logins every minute plus 12 logins every hour.
16
13
export class RateLimiter {
@@ -62,7 +59,7 @@ router.get("/", async (req, res) => {
62
59
res . send ( await getRoot ( req ) )
63
60
} )
64
61
65
- router . post ( "/" , async ( req , res ) => {
62
+ router . post < { } , string , { password : string ; base ?: string } , { to ?: string } > ( "/" , async ( req , res ) => {
66
63
const password = sanitizeString ( req . body . password )
67
64
const hashedPasswordFromArgs = req . args [ "hashed-password" ]
68
65
@@ -87,13 +84,13 @@ router.post("/", async (req, res) => {
87
84
if ( isPasswordValid ) {
88
85
// The hash does not add any actual security but we do it for
89
86
// obfuscation purposes (and as a side effect it handles escaping).
90
- res . cookie ( Cookie . Key , hashedPassword , {
87
+ res . cookie ( CookieKeys . Session , hashedPassword , {
91
88
domain : getCookieDomain ( req . headers . host || "" , req . args [ "proxy-domain" ] ) ,
92
89
// Browsers do not appear to allow cookies to be set relatively so we
93
90
// need to get the root path from the browser since the proxy rewrites
94
91
// it out of the path. Otherwise code-server instances hosted on
95
92
// 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 , ".." , "/" ) : "/" ,
97
94
sameSite : "lax" ,
98
95
} )
99
96
0 commit comments