From 4bdeac6e8db353c37caea95605fe52f2a4457b65 Mon Sep 17 00:00:00 2001
From: conico974 <nicodorseuil@yahoo.fr>
Date: Wed, 2 Apr 2025 20:50:19 +0200
Subject: [PATCH 1/4] backport vulnerability fix (#811)

---
 packages/open-next/package.json                       | 4 ++--
 packages/open-next/src/adapters/routing/middleware.ts | 9 +++++++--
 packages/open-next/src/adapters/types/next-types.ts   | 3 +++
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index af0a741a9..ee0fed89c 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "2.3.9",
+  "version": "2.3.10",
   "bin": {
     "open-next": "./dist/index.js"
   },
@@ -58,4 +58,4 @@
     "type": "git",
     "url": "git+https://github.com/sst/open-next.git"
   }
-}
+}
\ No newline at end of file
diff --git a/packages/open-next/src/adapters/routing/middleware.ts b/packages/open-next/src/adapters/routing/middleware.ts
index 85eb02b3b..0e342b917 100644
--- a/packages/open-next/src/adapters/routing/middleware.ts
+++ b/packages/open-next/src/adapters/routing/middleware.ts
@@ -1,6 +1,6 @@
 import path from "node:path";
 
-import { NEXT_DIR, NextConfig } from "../config/index.js";
+import { NEXT_DIR, NextConfig, PrerenderManifest } from "../config/index.js";
 import { InternalEvent, InternalResult } from "../event-mapper.js";
 import { IncomingMessage } from "../http/request.js";
 import { ServerlessResponse } from "../http/response.js";
@@ -46,7 +46,12 @@ export async function handleMiddleware(
   const hasMatch = middleMatch.some((r) => r.test(rawPath));
   if (!hasMatch) return internalEvent;
   // We bypass the middleware if the request is internal
-  if (internalEvent.headers["x-isr"]) return internalEvent;
+  if (
+    internalEvent.headers["x-isr"] &&
+    internalEvent.headers["x-prerender-revalidate"] ===
+      PrerenderManifest.preview.previewModeId
+  )
+    return internalEvent;
 
   const req = new IncomingMessage(internalEvent);
   const res = new ServerlessResponse({
diff --git a/packages/open-next/src/adapters/types/next-types.ts b/packages/open-next/src/adapters/types/next-types.ts
index 99312216f..a6191fbcc 100644
--- a/packages/open-next/src/adapters/types/next-types.ts
+++ b/packages/open-next/src/adapters/types/next-types.ts
@@ -142,6 +142,9 @@ export interface PrerenderManifest {
       dataRouteRegex: string;
     };
   };
+  preview: {
+    previewModeId: string;
+  };
 }
 
 export type Options = {

From 5beeae54698cefb4d210151c503c7c2c0e3d35d6 Mon Sep 17 00:00:00 2001
From: Dorseuil Nicolas <nicodorseuil@yahoo.fr>
Date: Wed, 2 Apr 2025 23:07:28 +0200
Subject: [PATCH 2/4] backport workflow

---
 .changeset/release-v2            | 12 ++++++++++++
 .github/workflows/v2-release.yml | 28 ++++++++++++++++++++++++++++
 package.json                     |  8 ++++----
 3 files changed, 44 insertions(+), 4 deletions(-)
 create mode 100644 .changeset/release-v2
 create mode 100644 .github/workflows/v2-release.yml

diff --git a/.changeset/release-v2 b/.changeset/release-v2
new file mode 100644
index 000000000..d954d7350
--- /dev/null
+++ b/.changeset/release-v2
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+
+pnpm build
+sed -i.bak -e '3,6d' .changeset/config.json
+
+sed -i 's/@opennextjs\/aws/open-next/' .changeset/config.json
+#cp packages/open-next/package.json packages/open-next/dist/package.json
+cp README.md packages/open-next/README.md
+#sed -i.bak -e '2,5d' packages/open-next/dist/package.json
+pnpm changeset publish --tag=v2
+cp .changeset/config.json.bak .changeset/config.json
diff --git a/.github/workflows/v2-release.yml b/.github/workflows/v2-release.yml
new file mode 100644
index 000000000..3a3112e51
--- /dev/null
+++ b/.github/workflows/v2-release.yml
@@ -0,0 +1,28 @@
+name: v2-release
+
+on: workflow_dispatch
+
+jobs:
+  release:
+    name: Pre-release
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout Repo
+        # https://github.com/actions/checkout
+        uses: actions/checkout@v4
+
+      # Setup .npmrc file to publish to npm
+      - uses: actions/setup-node@v4
+        with:
+          registry-url: "https://registry.npmjs.org"
+
+      - uses: ./.github/actions/pnpm-setup
+
+      - name: Install dependencies
+        run: pnpm install
+
+
+      - name: Publish Pre-release to npm
+        run: pnpm release-v2
+        env:
+          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
\ No newline at end of file
diff --git a/package.json b/package.json
index dcc13a820..5a6054e3e 100644
--- a/package.json
+++ b/package.json
@@ -16,18 +16,18 @@
     "e2e:test": "turbo run e2e:test",
     "version": "./.changeset/version",
     "release": "./.changeset/release",
-    "release-snapshot": "./.changeset/snapshot"
-    
+    "release-snapshot": "./.changeset/snapshot",
+    "release-v2": "./.changeset/release-v2"
   },
   "devDependencies": {
     "@changesets/changelog-github": "^0.4.4",
     "@changesets/cli": "^2.22.0",
     "@sladg/eslint-config-base": "1.4.1",
     "eslint": "^8.47.0",
-     "turbo": "1.10.12"
+    "turbo": "1.10.12"
   },
   "engines": {
     "node": ">=16",
     "pnpm": ">=8"
   }
-}
+}
\ No newline at end of file

From d561943d6107dbda79cd949cbf01fda449280e2e Mon Sep 17 00:00:00 2001
From: Frank <frank@sst.dev>
Date: Wed, 2 Apr 2025 17:23:01 -0400
Subject: [PATCH 3/4] Sync release script

---
 .changeset/release-v2 | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 .changeset/release-v2

diff --git a/.changeset/release-v2 b/.changeset/release-v2
old mode 100644
new mode 100755

From 6affc361098d14f905f72bea5f52ec40c931abb4 Mon Sep 17 00:00:00 2001
From: Frank <wangfanjie@gmail.com>
Date: Wed, 2 Apr 2025 17:43:22 -0400
Subject: [PATCH 4/4] Update release-v2

---
 .changeset/release-v2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.changeset/release-v2 b/.changeset/release-v2
index d954d7350..339e200a7 100755
--- a/.changeset/release-v2
+++ b/.changeset/release-v2
@@ -8,5 +8,5 @@ sed -i 's/@opennextjs\/aws/open-next/' .changeset/config.json
 #cp packages/open-next/package.json packages/open-next/dist/package.json
 cp README.md packages/open-next/README.md
 #sed -i.bak -e '2,5d' packages/open-next/dist/package.json
-pnpm changeset publish --tag=v2
+pnpm changeset publish
 cp .changeset/config.json.bak .changeset/config.json
