@@ -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 { ensureAuthenticated , redirect } 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 > ( path . join ( paths . data , "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 ( / [ ^ \w : . \- [ \] ] / g, "" )
94+ return res . redirect ( `https://${ host } ${ req . originalUrl } ` )
9495 }
9596 next ( )
9697 } )
@@ -110,22 +111,22 @@ export const register = async (
110111 app . router . use ( "/" , domainProxy . router )
111112 app . wsRouter . use ( "/" , domainProxy . wsRouter . router )
112113
113- app . router . all ( "/proxy/:port{/*path}" , async ( req , res ) => {
114+ app . router . all ( "/proxy/:port{/*path}" , ensureAuthenticated , async ( req , res ) => {
114115 await pathProxy . proxy ( req , res )
115116 } )
116- app . wsRouter . get ( "/proxy/:port{/*path}" , async ( req ) => {
117+ app . wsRouter . get ( "/proxy/:port{/*path}" , ensureAuthenticated , async ( req ) => {
117118 await pathProxy . wsProxy ( req as unknown as WebsocketRequest )
118119 } )
119120 // These two routes pass through the path directly.
120121 // So the proxied app must be aware it is running
121122 // under /absproxy/<someport>/
122- app . router . all ( "/absproxy/:port{/*path}" , async ( req , res ) => {
123+ app . router . all ( "/absproxy/:port{/*path}" , ensureAuthenticated , async ( req , res ) => {
123124 await pathProxy . proxy ( req , res , {
124125 passthroughPath : true ,
125126 proxyBasePath : args [ "abs-proxy-base-path" ] ,
126127 } )
127128 } )
128- app . wsRouter . get ( "/absproxy/:port{/*path}" , async ( req ) => {
129+ app . wsRouter . get ( "/absproxy/:port{/*path}" , ensureAuthenticated , async ( req ) => {
129130 await pathProxy . wsProxy ( req as unknown as WebsocketRequest , {
130131 passthroughPath : true ,
131132 proxyBasePath : args [ "abs-proxy-base-path" ] ,
0 commit comments