@@ -87,7 +87,19 @@ export function setupGeneralRPC({
8787
8888 return {
8989 getServerConfig ( ) : NuxtOptions {
90- return nuxt . options as unknown as NuxtOptions
90+ // This method is intentionally reachable without a dev auth token (the
91+ // client reads it eagerly across many views), so strip the private
92+ // `runtimeConfig` values — they can hold secrets — from the payload.
93+ // The Runtime Config tab reads them separately via the token-gated
94+ // `getServerRuntimeConfig`. `public`/`app` are non-secret and kept.
95+ const { runtimeConfig, ...rest } = nuxt . options
96+ return {
97+ ...rest ,
98+ runtimeConfig : {
99+ app : runtimeConfig ?. app ,
100+ public : runtimeConfig ?. public ,
101+ } ,
102+ } as unknown as NuxtOptions
91103 } ,
92104 async getServerDebugContext ( ) {
93105 if ( ! nuxt . _debug )
@@ -124,7 +136,10 @@ export function setupGeneralRPC({
124136 ) ,
125137 }
126138 } ,
127- getServerRuntimeConfig ( ) : Record < string , any > {
139+ async getServerRuntimeConfig ( token : string ) : Promise < Record < string , any > > {
140+ // Exposes runtimeConfig merged with env vars, which can hold secrets, so
141+ // require the dev auth token.
142+ await ensureDevAuthToken ( token )
128143 // Ported from https://github.com/unjs/nitro/blob/88e79fcdb2a024c96a3d1fd272d0acbff0405013/src/runtime/config.ts#L31
129144 // Since this operation happends on the Nitro runtime
130145 const ENV_PREFIX = 'NITRO_'
@@ -239,13 +254,17 @@ export function setupGeneralRPC({
239254 logger . info ( 'Restarting Nuxt...' )
240255 return nuxt . callHook ( 'restart' , { hard } )
241256 } ,
242- async requestForAuth ( info , origin ? ) {
257+ async requestForAuth ( info ) {
243258 if ( options . disableAuthorization )
244259 return
245260
246261 const token = await getDevAuthToken ( )
247262
248- origin ||= `${ nuxt . options . devServer . https ? 'https' : 'http' } ://${ nuxt . options . devServer . host === '::' ? 'localhost' : ( nuxt . options . devServer . host || 'localhost' ) } :${ nuxt . options . devServer . port } `
263+ // Always derive the origin from the dev server config. Never trust a
264+ // client-supplied origin here: it is printed next to the real auth token
265+ // in an "open this URL" instruction, so an attacker-controlled origin
266+ // would turn this into a token-exfiltration lure.
267+ const origin = `${ nuxt . options . devServer . https ? 'https' : 'http' } ://${ nuxt . options . devServer . host === '::' ? 'localhost' : ( nuxt . options . devServer . host || 'localhost' ) } :${ nuxt . options . devServer . port } `
249268
250269 const ROUTE_AUTH = `${ nuxt . options . app . baseURL || '/' } /__nuxt_devtools__/auth` . replace ( MULTIPLE_SLASHES_RE , '/' )
251270
0 commit comments