From 9693ad4ffafb02ed1ea02beb3420ba864724b293 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 25 Sep 2024 14:38:32 +0100 Subject: [PATCH] fix: check origin in static build (#12070) * fix: check origin in static build * address comment --- .changeset/tame-pumpkins-swim.md | 5 +++++ packages/astro/src/core/build/generate.ts | 2 +- packages/astro/src/core/build/plugins/plugin-manifest.ts | 2 +- packages/astro/src/vite-plugin-astro-server/plugin.ts | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/tame-pumpkins-swim.md diff --git a/.changeset/tame-pumpkins-swim.md b/.changeset/tame-pumpkins-swim.md new file mode 100644 index 0000000000..64c51fdec5 --- /dev/null +++ b/.changeset/tame-pumpkins-swim.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where the check origin middleware was incorrectly injected when the build output was `"static"` diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index c5f01a7070..8b34b11c73 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -540,7 +540,7 @@ function createBuildManifest( onRequest: middleware, }; }, - checkOrigin: settings.config.security?.checkOrigin ?? false, + checkOrigin: (settings.config.security?.checkOrigin && settings.buildOutput === "server") ?? false, key, envGetSecretEnabled: false, }; diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts index df3c8c8118..d9f0d3f2bd 100644 --- a/packages/astro/src/core/build/plugins/plugin-manifest.ts +++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts @@ -270,7 +270,7 @@ function buildManifest( assets: staticFiles.map(prefixAssetPath), i18n: i18nManifest, buildFormat: settings.config.build.format, - checkOrigin: settings.config.security?.checkOrigin ?? false, + checkOrigin: (settings.config.security?.checkOrigin && settings.buildOutput === "server") ?? false, serverIslandNameMap: Array.from(settings.serverIslandNameMap), key: encodedKey, envGetSecretEnabled: diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index c69b511e48..9d5d697245 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -60,6 +60,7 @@ export default function createVitePluginAstroServer({ await createRouteManifest({ settings, fsMod }, logger), // TODO: Handle partial updates to the manifest ); warnMissingAdapter(logger, settings); + pipeline.manifest.checkOrigin = settings.config.security.checkOrigin && settings.buildOutput === "server"; pipeline.setManifestData(routeManifest); } } @@ -160,7 +161,7 @@ export function createDevelopmentManifest(settings: AstroSettings): SSRManifest componentMetadata: new Map(), inlinedScripts: new Map(), i18n: i18nManifest, - checkOrigin: settings.config.security?.checkOrigin ?? false, + checkOrigin: (settings.config.security?.checkOrigin && settings.buildOutput === "server") ?? false, envGetSecretEnabled: false, key: createKey(), middleware() {