@@ -39,6 +39,13 @@ describe('server maintenance', () => {
3939 expect ( isAllowedIp ( 'localhost' , [ '10.0.0.1' ] ) ) . toBe ( true )
4040 } )
4141
42+ test ( 'isAllowedIp can reject proxy loopback outside development' , async ( ) => {
43+ const { isAllowedIp } = await import ( '../src/maintenance' )
44+ expect ( isAllowedIp ( '127.0.0.1' , [ ] , false ) ) . toBe ( false )
45+ expect ( isAllowedIp ( '::1' , [ ] , false ) ) . toBe ( false )
46+ expect ( isAllowedIp ( '127.0.0.1' , [ '127.0.0.1' ] , false ) ) . toBe ( true )
47+ } )
48+
4249 test ( 'isAllowedIp checks against allowed list' , async ( ) => {
4350 const { isAllowedIp } = await import ( '../src/maintenance' )
4451 expect ( isAllowedIp ( '10.0.0.1' , [ '10.0.0.1' , '10.0.0.2' ] ) ) . toBe ( true )
@@ -126,6 +133,29 @@ describe('server maintenance', () => {
126133 process . env . APP_COMING_SOON_SECRET = previousSecret
127134 } )
128135
136+ test ( 'maintenanceGate does not treat a production proxy as a localhost bypass' , async ( ) => {
137+ const { maintenanceGate } = await import ( '../src/maintenance' )
138+ const previousMode = process . env . APP_COMING_SOON
139+ const previousAppEnv = process . env . APP_ENV
140+
141+ process . env . APP_COMING_SOON = 'true'
142+ process . env . APP_ENV = 'production'
143+
144+ const response = await maintenanceGate ( new Request ( 'http://127.0.0.1/' ) )
145+ expect ( response ?. status ) . toBe ( 302 )
146+ expect ( response ?. headers . get ( 'Location' ) ) . toBe ( '/coming-soon' )
147+
148+ if ( previousMode === undefined )
149+ delete process . env . APP_COMING_SOON
150+ else
151+ process . env . APP_COMING_SOON = previousMode
152+
153+ if ( previousAppEnv === undefined )
154+ delete process . env . APP_ENV
155+ else
156+ process . env . APP_ENV = previousAppEnv
157+ } )
158+
129159 test ( 'maintenanceHtml includes retry info when provided' , async ( ) => {
130160 const { maintenanceHtml } = await import ( '../src/maintenance' )
131161 const html = maintenanceHtml ( { time : Date . now ( ) , retry : 300 } )
0 commit comments