@@ -11,7 +11,7 @@ import { App } from "../app"
1111import { AuthType , DefaultedArgs } from "../cli"
1212import { commit , rootPath } from "../constants"
1313import { Heart } from "../heart"
14- import { redirect } from "../http"
14+ import { redirect , ensureAuthenticated } from "../http"
1515import { CoderSettings , SettingsProvider } from "../settings"
1616import { UpdateProvider } from "../update"
1717import { getMediaMime , paths } from "../util"
@@ -58,7 +58,7 @@ export const register = async (
5858 app . router . use ( cookieParser ( ) )
5959 app . wsRouter . use ( cookieParser ( ) )
6060
61- const settings = new SettingsProvider < CoderSettings > ( path . join ( args [ "user-data-dir" ] , "coder.json" ) )
61+ const settings = new SettingsProvider < CoderSettings > ( args [ "user-data-dir" ] + path . sep + "coder.json" )
6262 const updater = new UpdateProvider ( "https://api.github.com/repos/coder/code-server/releases/latest" , settings )
6363
6464 const cookieSessionName = getCookieSessionName ( args [ "cookie-suffix" ] )
@@ -90,7 +90,8 @@ export const register = async (
9090 // TODO: This does *NOT* work if you have a base path since to specify the
9191 // protocol we need to specify the whole path.
9292 if ( args . cert && ! ( req . connection as tls . TLSSocket ) . encrypted ) {
93- return res . redirect ( `https://${ req . headers . host } ${ req . originalUrl } ` )
93+ const host = String ( req . headers . host || "" ) . replace ( / [ ^ a - z A - Z 0 - 9 . : \- [ \] ] / g, "" )
94+ return res . redirect ( `https://${ host } ${ req . originalUrl } ` )
9495 }
9596 next ( )
9697 } )
@@ -114,6 +115,7 @@ export const register = async (
114115 await pathProxy . proxy ( req , res )
115116 } )
116117 app . wsRouter . get ( "/proxy/:port{/*path}" , async ( req ) => {
118+ await ensureAuthenticated ( req )
117119 await pathProxy . wsProxy ( req as unknown as WebsocketRequest )
118120 } )
119121 // These two routes pass through the path directly.
@@ -126,6 +128,7 @@ export const register = async (
126128 } )
127129 } )
128130 app . wsRouter . get ( "/absproxy/:port{/*path}" , async ( req ) => {
131+ await ensureAuthenticated ( req )
129132 await pathProxy . wsProxy ( req as unknown as WebsocketRequest , {
130133 passthroughPath : true ,
131134 proxyBasePath : args [ "abs-proxy-base-path" ] ,
0 commit comments