From 253c8f7ee0c0c580c44dedbe9387646264e90a1e Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Thu, 3 Nov 2022 22:48:29 +0100 Subject: [PATCH] fix(nuxt): disallow directly rendering error page (#8673) --- packages/nuxt/src/core/runtime/nitro/renderer.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 5cfe7b4cbc..6109d6c79d 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -1,7 +1,7 @@ import { createRenderer, renderResourceHeaders } from 'vue-bundle-renderer/runtime' import type { RenderResponse } from 'nitropack' import type { Manifest } from 'vite' -import { appendHeader, getQuery, writeEarlyHints } from 'h3' +import { appendHeader, createError, getQuery, writeEarlyHints } from 'h3' import devalue from '@nuxt/devalue' import { joinURL } from 'ufo' import { renderToString as _renderToString } from 'vue/server-renderer' @@ -121,6 +121,10 @@ export default defineRenderHandler(async (event) => { const ssrError = event.req.url?.startsWith('/__nuxt_error') ? getQuery(event) as Exclude : null + if (ssrError && event.req.socket.readyState !== 'readOnly' /* direct request */) { + throw createError('Cannot directly render error page!') + } + let url = ssrError?.url as string || event.req.url! // Whether we are rendering payload route