@@ -177,8 +177,6 @@ export const adminApis = {
177
177
178
178
for ( const [ k , was ] of typedEntries ( adminApis ) )
179
179
( adminApis [ k ] as any ) = ( ( params , ctx ) => {
180
- if ( ! allowAdmin ( ctx ) )
181
- return new ApiError ( HTTP_FORBIDDEN )
182
180
if ( ctxAdminAccess ( ctx ) )
183
181
return was ( params , ctx )
184
182
const props = { possible : anyAccountCanLoginAdmin ( ) }
@@ -193,8 +191,10 @@ export const favicon = defineConfig('favicon', '')
193
191
export const title = defineConfig ( 'title' , "File server" )
194
192
195
193
export function ctxAdminAccess ( ctx : Koa . Context ) {
196
- return ! ctx . ips . length // we consider localhost_admin only if no proxy is being used
197
- && localhostAdmin . get ( ) && isLocalHost ( ctx )
194
+ if ( preventAdminAccess ( ctx ) )
195
+ return false
196
+ // for extra security, skip localhost_admin via proxy, even tho this prevents using it with local proxies, which is legit in principle
197
+ return ! ctx . ips . length && localhostAdmin . get ( ) && isLocalHost ( ctx )
198
198
|| ctx . state . account && accountCanLoginAdmin ( ctx . state . account )
199
199
}
200
200
@@ -213,6 +213,6 @@ export function anyAccountCanLoginAdmin() {
213
213
return Boolean ( _ . find ( accounts . get ( ) , accountCanLoginAdmin ) )
214
214
}
215
215
216
- export function allowAdmin ( ctx : Koa . Context ) {
217
- return isLocalHost ( ctx ) || adminNet . compiled ( ) ( ctx . ip )
216
+ export function preventAdminAccess ( ctx : Koa . Context ) {
217
+ return ! isLocalHost ( ctx ) && ! adminNet . compiled ( ) ( ctx . ip )
218
218
}
0 commit comments