@@ -170,6 +170,9 @@ function getAuthMiddleware(authConfig, oidcSettings) {
170170const initialAuthConfig = loadAuthConfig ( ) ;
171171const oidcSettings = loadOidcSettings ( initialAuthConfig ) ;
172172const protectConfig = getAuthMiddleware ( initialAuthConfig , oidcSettings ) ;
173+ const bootstrapAuth = oidcSettings
174+ ? createOidcMiddleware ( oidcSettings , { permissive : true } )
175+ : protectConfig ;
173176
174177/* True when any auth method is configured. Used to keep zero-auth deployments
175178 open (their original behaviour) while closing the gate for everyone else. */
@@ -279,7 +282,7 @@ const app = express()
279282 } ) )
280283 // Middleware to serve any .yml files in USER_DATA_DIR with optional protection
281284 // Note: returns stripped version if auth configured but not yet authenticated
282- . get ( '/*.yml' , protectConfig , ( req , res ) => {
285+ . get ( '/*.yml' , bootstrapAuth , ( req , res ) => {
283286 const ymlFile = req . path . split ( '/' ) . pop ( ) ;
284287 const filePath = path . resolve ( rootDir , process . env . USER_DATA_DIR || 'user-data' , ymlFile ) ;
285288 if ( authIsConfigured ) {
@@ -295,6 +298,10 @@ const app = express()
295298 printWarning ( `Failed to read or parse ${ ymlFile } ` , e ) ;
296299 return safeEnd ( res , errBody ( 'Could not read config' ) , 500 ) ;
297300 }
301+ // Not authenticated, not main conf.yml
302+ if ( ! req . auth && ! guestAccessOn ) {
303+ return res . status ( 401 ) . json ( { success : false , message : 'Unauthorized' } ) ;
304+ }
298305 }
299306 res . sendFile ( filePath , ( err ) => {
300307 if ( err ) safeEnd ( res , errBody ( `Could not read ${ ymlFile } ` ) , 404 ) ;
0 commit comments