Sắp ra mắt
diff --git a/apps/web/src/app/embed/not-found.test.ts b/apps/web/src/app/embed/not-found.test.ts
new file mode 100644
index 00000000..a53e0df2
--- /dev/null
+++ b/apps/web/src/app/embed/not-found.test.ts
@@ -0,0 +1,78 @@
+// @vitest-environment happy-dom
+import { Window } from "happy-dom"
+import { act, createElement } from "react"
+import { createRoot, type Root } from "react-dom/client"
+import { renderToStaticMarkup } from "react-dom/server"
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
+
+const state = vi.hoisted(() => ({
+ theme: null as string | null,
+}))
+
+vi.mock("next/navigation", () => ({
+ useSearchParams: () => new URLSearchParams(state.theme ? `theme=${state.theme}` : ""),
+ notFound: vi.fn((): never => {
+ throw new Error("NEXT_NOT_FOUND")
+ }),
+}))
+
+const { default: EmbedNotFound } = await import("./not-found")
+const { default: EmbedRootPage } = await import("./page")
+const { default: EmbedNestedNotFoundPage } = await import("./[slug]/[...rest]/page")
+const { EmbedNotFoundCard } = await import("@/components/EmbedNotFoundCard")
+
+declare global {
+ var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
+}
+
+const parser = new new Window().DOMParser()
+let container: HTMLDivElement
+let root: Root
+
+beforeEach(() => {
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true
+ state.theme = null
+ vi.stubEnv("NEXT_PUBLIC_SITE_URL", "https://give.vn")
+ container = document.createElement("div")
+ document.body.append(container)
+ root = createRoot(container)
+})
+
+afterEach(() => {
+ act(() => root.unmount())
+ container.remove()
+ vi.unstubAllEnvs()
+})
+
+describe("/embed fallback routes and EmbedNotFound (DOS/Give#335)", () => {
+ it("calls notFound() on /embed root and /embed/[slug]/[...rest] nested paths", () => {
+ expect(() => EmbedRootPage()).toThrow("NEXT_NOT_FOUND")
+ expect(() => EmbedNestedNotFoundPage()).toThrow("NEXT_NOT_FOUND")
+ })
+
+ it("renders compact chrome-free not-found card linking out in a new tab and honors ?theme=", () => {
+ const html = renderToStaticMarkup(createElement(EmbedNotFound))
+ const doc = parser.parseFromString(html, "text/html")
+
+ expect(doc.querySelector("h1")?.textContent.trim()).toBe("Không tìm thấy chiến dịch")
+ const card = doc.querySelector("[data-embed-theme]")!
+ expect(card.className).toContain("rounded-md")
+ const link = doc.querySelector('a[href="https://give.vn/campaigns"]')!
+ expect(link).toBeTruthy()
+ expect(link.getAttribute("target")).toBe("_blank")
+ expect(link.getAttribute("rel")).toBe("noopener noreferrer")
+ expect(doc.querySelectorAll("form")).toHaveLength(0)
+
+ state.theme = "dark"
+ act(() => {
+ root.render(createElement(EmbedNotFoundCard, { campaignsUrl: "https://give.vn/campaigns" }))
+ })
+ expect(container.querySelector("[data-embed-theme]")?.getAttribute("data-embed-theme")).toBe("dark")
+
+ state.theme = "invalid"
+ act(() => {
+ root.render(createElement(EmbedNotFoundCard, { campaignsUrl: "https://give.vn/campaigns" }))
+ })
+ expect(container.querySelector("[data-embed-theme]")?.getAttribute("data-embed-theme")).toBe("light")
+ })
+})
diff --git a/apps/web/src/app/embed/not-found.tsx b/apps/web/src/app/embed/not-found.tsx
new file mode 100644
index 00000000..1d182e55
--- /dev/null
+++ b/apps/web/src/app/embed/not-found.tsx
@@ -0,0 +1,7 @@
+import { EmbedNotFoundCard } from "@/components/EmbedNotFoundCard"
+import { siteOrigin } from "@/lib/auth/origin"
+
+export default function EmbedNotFound() {
+ const origin = siteOrigin()
+ return
+}
diff --git a/apps/web/src/app/embed/page.tsx b/apps/web/src/app/embed/page.tsx
new file mode 100644
index 00000000..c9645376
--- /dev/null
+++ b/apps/web/src/app/embed/page.tsx
@@ -0,0 +1,7 @@
+import { notFound } from "next/navigation"
+
+export const dynamic = "force-dynamic"
+
+export default function EmbedRootPage(): never {
+ notFound()
+}
diff --git a/apps/web/src/app/layout.test.ts b/apps/web/src/app/layout.test.ts
index 3033a06d..5e588346 100644
--- a/apps/web/src/app/layout.test.ts
+++ b/apps/web/src/app/layout.test.ts
@@ -3,7 +3,6 @@ import { renderToStaticMarkup } from "react-dom/server"
import { beforeEach, describe, expect, it, vi } from "vitest"
const state = vi.hoisted(() => ({
- headers: new Headers(),
pathname: "/",
session: null as { user: { id: string; email: string | null; name: string | null }; accessToken: string } | null,
}))
@@ -12,10 +11,6 @@ vi.mock("next/font/google", () => ({
Be_Vietnam_Pro: () => ({ variable: "--font-be-vietnam-pro" }),
}))
-vi.mock("next/headers", () => ({
- headers: vi.fn(async () => state.headers),
-}))
-
vi.mock("next/navigation", () => ({
usePathname: () => state.pathname,
}))
@@ -50,9 +45,8 @@ vi.mock("@/components/layout/RingBoxScroll", () => ({
const { default: RootLayout } = await import("./layout")
-describe("RootLayout chrome & session isolation (DOS/Give#335)", () => {
+describe("RootLayout chrome isolation (DOS/Give#335)", () => {
beforeEach(() => {
- state.headers = new Headers()
state.pathname = "/"
state.session = {
user: { id: "user-1", email: "user@dos.me", name: "Nguyễn An" },
@@ -62,27 +56,28 @@ describe("RootLayout chrome & session isolation (DOS/Give#335)", () => {
countUnreadNoticesMock.mockClear()
})
- it("renders SiteHeader, SiteFooter, and RingBoxScroll with session on normal routes", async () => {
- const html = renderToStaticMarkup(await RootLayout({ children: createElement("div", null, "Page") as ReactNode }))
- expect(getSessionMock).toHaveBeenCalledTimes(1)
- expect(countUnreadNoticesMock).toHaveBeenCalledTimes(1)
- expect(html).toContain("SignedIn(3)")
- expect(html).toContain("SiteFooter")
- expect(html).toContain("ring-box-scroll")
- expect(html).toContain("Page")
+ it("renders SiteHeader, SiteFooter, and RingBoxScroll on normal routes", async () => {
+ for (const path of ["/", "/campaigns/xay-truong", "/embedded"]) {
+ state.pathname = path
+ const html = renderToStaticMarkup(await RootLayout({ children: createElement("div", null, "Page") as ReactNode }))
+ expect(html).toContain("SignedIn(3)")
+ expect(html).toContain("SiteFooter")
+ expect(html).toContain("ring-box-scroll")
+ expect(html).toContain("Page")
+ }
})
- it("skips getSession() and omits chrome completely when x-give-embed is 1", async () => {
- state.headers = new Headers({ "x-give-embed": "1" })
- state.pathname = "/embed/xay-truong"
-
- const html = renderToStaticMarkup(await RootLayout({ children: createElement("div", null, "Embed") as ReactNode }))
- expect(getSessionMock).not.toHaveBeenCalled()
- expect(countUnreadNoticesMock).not.toHaveBeenCalled()
- expect(html).not.toContain("SignedIn")
- expect(html).not.toContain("SignedOut")
- expect(html).not.toContain("SiteFooter")
- expect(html).not.toContain("ring-box-scroll")
- expect(html).toContain("Embed")
+ it("omits SiteHeader, SiteFooter, and RingBoxScroll on /embed and /embed/*", async () => {
+ for (const path of ["/embed", "/embed/xay-truong", "/Embed/xay-truong"]) {
+ state.pathname = path
+ const html = renderToStaticMarkup(
+ await RootLayout({ children: createElement("div", null, "Embed") as ReactNode })
+ )
+ expect(html).not.toContain("SignedIn")
+ expect(html).not.toContain("SignedOut")
+ expect(html).not.toContain("SiteFooter")
+ expect(html).not.toContain("ring-box-scroll")
+ expect(html).toContain("Embed")
+ }
})
})
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
index 65361e7b..e23da9ee 100644
--- a/apps/web/src/app/layout.tsx
+++ b/apps/web/src/app/layout.tsx
@@ -1,6 +1,5 @@
import type { Metadata } from "next"
import { Be_Vietnam_Pro } from "next/font/google"
-import { headers } from "next/headers"
import type { ReactNode } from "react"
import { LayoutShell } from "@/components/layout/LayoutShell"
@@ -40,18 +39,13 @@ async function unreadNotices(session: Session): Promise {
}
export default async function RootLayout({ children }: { children: ReactNode }) {
- // Embed widget requests set x-give-embed in proxy.ts and stay strictly anonymous (DOS/Give#335).
- const isEmbed = (await headers()).get("x-give-embed") === "1"
- const session = isEmbed ? null : await getSession()
+ const session = await getSession()
const unread = session ? await unreadNotices(session) : null
return (
- }
- footer={isEmbed ? null : }
- >
+ } footer={}>
{children}
diff --git a/apps/web/src/components/EmbedNotFoundCard.tsx b/apps/web/src/components/EmbedNotFoundCard.tsx
new file mode 100644
index 00000000..36cbd856
--- /dev/null
+++ b/apps/web/src/components/EmbedNotFoundCard.tsx
@@ -0,0 +1,51 @@
+"use client"
+
+import { useSearchParams } from "next/navigation"
+import { Suspense } from "react"
+
+import { buttonClass } from "@/components/ui/Button"
+import { parseEmbedOptions, type EmbedTheme } from "@/lib/embed"
+
+function EmbedNotFoundCardBody({ campaignsUrl, theme }: { campaignsUrl: string; theme: EmbedTheme }) {
+ return (
+
+
+
Give
+
Không tìm thấy chiến dịch
+
Chiến dịch không tồn tại, chưa công khai hoặc đang tạm dừng.
+
+
+
+ )
+}
+
+function EmbedNotFoundWithSearch({ campaignsUrl }: { campaignsUrl: string }) {
+ const searchParams = useSearchParams()
+ const { theme } = parseEmbedOptions({ theme: searchParams.get("theme") ?? undefined })
+ return
+}
+
+/**
+ * Compact chrome-free not-found card sized for `/embed/*` iframes (including
+ * 180px compact embeds) and honoring `?theme=light|dark|auto` (DOS/Give#335).
+ */
+export function EmbedNotFoundCard({ campaignsUrl = "/campaigns" }: { campaignsUrl?: string }) {
+ return (
+ }>
+
+
+ )
+}
diff --git a/apps/web/src/components/EmbedWidgetDisclosure.test.ts b/apps/web/src/components/EmbedWidgetDisclosure.test.ts
index 8c3a18c6..17dd858f 100644
--- a/apps/web/src/components/EmbedWidgetDisclosure.test.ts
+++ b/apps/web/src/components/EmbedWidgetDisclosure.test.ts
@@ -83,7 +83,7 @@ describe("EmbedWidgetDisclosure (DOS/Give#335)", () => {
const textarea = container.querySelector("textarea")!
expect(textarea.value).toBe(
- ''
+ ''
)
const compactBtn = [...container.querySelectorAll("button")].find((b) => b.textContent?.includes("Thu gọn"))!
diff --git a/apps/web/src/components/EmbedWidgetDisclosure.tsx b/apps/web/src/components/EmbedWidgetDisclosure.tsx
index 60f5bf62..59dbb4da 100644
--- a/apps/web/src/components/EmbedWidgetDisclosure.tsx
+++ b/apps/web/src/components/EmbedWidgetDisclosure.tsx
@@ -126,7 +126,7 @@ export function EmbedWidgetDisclosure({
}}
className={clsx(
"min-h-9 rounded px-2 text-sm font-semibold transition-colors duration-150 focus-visible:-outline-offset-2",
- active ? "border border-border bg-raised text-fg" : "text-muted hover:text-fg"
+ active ? "bg-raised text-fg ring-1 ring-border ring-inset" : "text-muted hover:text-fg"
)}
>
{option.label}
@@ -152,7 +152,7 @@ export function EmbedWidgetDisclosure({
}}
className={clsx(
"min-h-9 rounded px-2 text-sm font-semibold transition-colors duration-150 focus-visible:-outline-offset-2",
- active ? "border border-border bg-raised text-fg" : "text-muted hover:text-fg"
+ active ? "bg-raised text-fg ring-1 ring-border ring-inset" : "text-muted hover:text-fg"
)}
>
{EMBED_THEME_LABELS[option]}
diff --git a/apps/web/src/components/layout/LayoutShell.test.ts b/apps/web/src/components/layout/LayoutShell.test.ts
index 0a0ca75e..0f6a59f5 100644
--- a/apps/web/src/components/layout/LayoutShell.test.ts
+++ b/apps/web/src/components/layout/LayoutShell.test.ts
@@ -39,9 +39,11 @@ afterEach(() => {
})
describe("LayoutShell (DOS/Give#335)", () => {
- it("recognizes /embed and /embed/* without matching /embedded", () => {
+ it("recognizes /embed and /embed/* case-insensitively without matching /embedded", () => {
expect(isEmbedRoute("/embed")).toBe(true)
expect(isEmbedRoute("/embed/xay-truong")).toBe(true)
+ expect(isEmbedRoute("/Embed/xay-truong")).toBe(true)
+ expect(isEmbedRoute("/EMBED")).toBe(true)
expect(isEmbedRoute("/embedded")).toBe(false)
expect(isEmbedRoute("/campaigns/xay-truong")).toBe(false)
expect(isEmbedRoute(null)).toBe(false)
diff --git a/apps/web/src/components/layout/LayoutShell.tsx b/apps/web/src/components/layout/LayoutShell.tsx
index 2ae87a00..81928387 100644
--- a/apps/web/src/components/layout/LayoutShell.tsx
+++ b/apps/web/src/components/layout/LayoutShell.tsx
@@ -6,7 +6,8 @@ import type { ReactNode } from "react"
import { RingBoxScroll } from "@/components/layout/RingBoxScroll"
export function isEmbedRoute(pathname: string | null): boolean {
- return pathname === "/embed" || Boolean(pathname?.startsWith("/embed/"))
+ const normalized = pathname?.toLowerCase() ?? ""
+ return normalized === "/embed" || normalized.startsWith("/embed/")
}
/**
diff --git a/apps/web/src/lib/embed.test.ts b/apps/web/src/lib/embed.test.ts
index b01ddc0e..8de0fe1d 100644
--- a/apps/web/src/lib/embed.test.ts
+++ b/apps/web/src/lib/embed.test.ts
@@ -71,7 +71,7 @@ describe("embed helpers (DOS/Give#335)", () => {
origin: "https://give.vn",
})
expect(defaultSnippet).toBe(
- ''
+ ''
)
expect(defaultSnippet).toContain(`height="${EMBED_HEIGHT_DEFAULT}"`)
diff --git a/apps/web/src/lib/embed.ts b/apps/web/src/lib/embed.ts
index 7540ad25..38aafa35 100644
--- a/apps/web/src/lib/embed.ts
+++ b/apps/web/src/lib/embed.ts
@@ -110,5 +110,5 @@ export function buildEmbedIframeCode({
const cleanTitle = title.replace(/\s+/g, " ").trim()
const iframeTitle = cleanTitle ? `${cleanTitle} · Give` : "Chiến dịch Give"
- return ``
+ return ``
}
diff --git a/apps/web/src/proxy.test.ts b/apps/web/src/proxy.test.ts
index f71602b1..e71e5622 100644
--- a/apps/web/src/proxy.test.ts
+++ b/apps/web/src/proxy.test.ts
@@ -2,7 +2,7 @@ import { AsyncLocalStorage } from "node:async_hooks"
import { NextRequest } from "next/server"
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
-import { config, proxy } from "./proxy"
+import { config, EMBED_HEADER, proxy } from "./proxy"
const ISSUER = "https://issuer.example/auth/v1"
@@ -194,30 +194,62 @@ describe("proxy session refresh", () => {
expect(loggedText()).not.toContain("rt-1")
})
- it("skips cookie refresh and marks x-give-embed on /embed and /embed/*, while stripping spoofed headers elsewhere (DOS/Give#335)", async () => {
- for (const path of ["/embed", "/embed/xay-truong-ban-may"]) {
+ it("marks lowercase /embed* with x-give-embed without refreshing cookies, strips spoofed headers elsewhere, and blocks mixed-case /Embed* with 404 DENY (DOS/Give#335)", async () => {
+ for (const path of ["/embed", "/embed/test-slug"]) {
const response = await proxy(
new NextRequest(`https://give.example${path}`, { headers: { cookie: "__Host-give_rt=rt-1" } })
)
expect(fetchMock).not.toHaveBeenCalled()
expectCookiesKept(response)
+ expect(response.status).toBe(200)
expect(response.headers.get("x-middleware-request-x-give-embed")).toBe("1")
}
- const spoofed = await proxy(
- new NextRequest("https://give.example/campaigns/xay-truong", {
- headers: { "x-give-embed": "1" },
+ // Spoofed x-give-embed without token refresh is dropped cleanly.
+ const spoofedNoRefresh = await proxy(
+ new NextRequest("https://give.example/campaigns", {
+ headers: { [EMBED_HEADER]: "1", host: "give.example" },
})
)
expect(fetchMock).not.toHaveBeenCalled()
- expect(spoofed.headers.get("x-middleware-request-x-give-embed")).toBeNull()
+ expect(spoofedNoRefresh.headers.get("x-middleware-request-x-give-embed")).toBeNull()
+ expect(
+ (spoofedNoRefresh.headers.get("x-middleware-override-headers") ?? "")
+ .split(",")
+ .map((h) => h.trim().toLowerCase())
+ ).not.toContain(EMBED_HEADER)
- const spoofedEmbedded = await proxy(
- new NextRequest("https://give.example/embedded", {
- headers: { "x-give-embed": "1" },
+ // Spoofed x-give-embed with token refresh is ALSO dropped cleanly while refreshing cookies.
+ fetchMock.mockResolvedValueOnce(
+ Response.json({ access_token: "at-2", refresh_token: "rt-2", expires_in: 3600, token_type: "bearer" })
+ )
+ const spoofedWithRefresh = await proxy(
+ new NextRequest("https://give.example/campaigns", {
+ headers: { cookie: "__Host-give_rt=rt-1", [EMBED_HEADER]: "1", host: "give.example" },
})
)
- expect(spoofedEmbedded.headers.get("x-middleware-request-x-give-embed")).toBeNull()
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(spoofedWithRefresh.cookies.get("__Host-give_at")?.value).toBe("at-2")
+ expect(spoofedWithRefresh.headers.get("x-middleware-request-x-give-embed")).toBeNull()
+ expect(
+ (spoofedWithRefresh.headers.get("x-middleware-override-headers") ?? "")
+ .split(",")
+ .map((h) => h.trim().toLowerCase())
+ ).not.toContain(EMBED_HEADER)
+
+ // Mixed-case /Embed* returns 404 with DENY & frame-ancestors 'none' without refreshing cookies.
+ for (const mixedCasePath of ["/EMBED", "/Embed/test-slug"]) {
+ const response = await proxy(
+ new NextRequest(`https://give.example${mixedCasePath}`, { headers: { cookie: "__Host-give_rt=rt-1" } })
+ )
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expectCookiesKept(response)
+ expect(response.status).toBe(404)
+ expect(response.headers.get("x-frame-options")).toBe("DENY")
+ expect(response.headers.get("content-security-policy")).toBe("frame-ancestors 'none'")
+ expect(response.headers.get("x-robots-tag")).toBe("noindex, nofollow")
+ expect(response.headers.get("x-content-type-options")).toBe("nosniff")
+ }
})
})
@@ -305,5 +337,11 @@ describe("proxy matcher exclusions", () => {
url: "https://give.example/admin",
})
).toBe(true)
+ expect(
+ unstable_doesMiddlewareMatch({
+ config,
+ url: "https://give.example/embed/test-slug",
+ })
+ ).toBe(true)
})
})
diff --git a/apps/web/src/proxy.ts b/apps/web/src/proxy.ts
index 9b04338e..09f8f415 100644
--- a/apps/web/src/proxy.ts
+++ b/apps/web/src/proxy.ts
@@ -5,11 +5,10 @@ import { isDeadRefreshToken, loadOidcConfig, refreshTokens, tokenFailureLog } fr
import { appOrigin } from "@/lib/auth/origin"
import { needsRefresh } from "@/lib/auth/token"
-const EMBED_HEADER = "x-give-embed"
+export const EMBED_HEADER = "x-give-embed"
-export function isEmbedPath(pathname: string): boolean {
- return pathname === "/embed" || pathname.startsWith("/embed/")
-}
+const EXACT_EMBED_RE = /^\/embed(?:\/|$)/
+const ANY_CASE_EMBED_RE = /^\/embed(?:\/|$)/i
/**
* Keeps the session's access token fresh. When it is missing or about to
@@ -18,19 +17,33 @@ export function isEmbedPath(pathname: string): boolean {
* refresh call gives up after TOKEN_TIMEOUT_MS (set in oidc.ts) and never
* follows a redirect.
*
- * Embed widget routes (`/embed`, `/embed/*`) are strictly anonymous and
- * read-only (DOS/Give#335): they never read/refresh session cookies, and carry
- * a proxy-controlled `x-give-embed` header so `RootLayout` can skip `getSession()`.
+ * Embed widget routes (`/embed`, `/embed/*`) stay strictly anonymous: `proxy()`
+ * marks them with a trusted internal `x-give-embed` request header and returns
+ * before touching cookies or OIDC refresh, while stripping any client-supplied
+ * `x-give-embed` on every other route and rejecting mixed-case `/Embed*` paths
+ * with 404 + `X-Frame-Options: DENY` (DOS/Give#335).
*/
export async function proxy(request: NextRequest) {
- if (isEmbedPath(request.nextUrl.pathname)) {
- const requestHeaders = new Headers(request.headers)
- requestHeaders.set(EMBED_HEADER, "1")
- return NextResponse.next({ request: { headers: requestHeaders } })
+ const { pathname } = request.nextUrl
+ if (ANY_CASE_EMBED_RE.test(pathname) && !EXACT_EMBED_RE.test(pathname)) {
+ return new NextResponse("Not Found", {
+ status: 404,
+ headers: {
+ "X-Content-Type-Options": "nosniff",
+ "X-Frame-Options": "DENY",
+ "Content-Security-Policy": "frame-ancestors 'none'",
+ "X-Robots-Tag": "noindex, nofollow",
+ },
+ })
+ }
+ if (EXACT_EMBED_RE.test(pathname)) {
+ const embedHeaders = new Headers(request.headers)
+ embedHeaders.set(EMBED_HEADER, "1")
+ return NextResponse.next({ request: { headers: embedHeaders } })
}
- const hadSpoofedEmbedHeader = request.headers.has(EMBED_HEADER)
- if (hadSpoofedEmbedHeader) request.headers.delete(EMBED_HEADER)
+ const hadSpoofedEmbed = request.headers.has(EMBED_HEADER)
+ if (hadSpoofedEmbed) request.headers.delete(EMBED_HEADER)
const { hostname } = request.nextUrl
const accessName = cookieName(SESSION_ACCESS, hostname)
@@ -39,7 +52,7 @@ export async function proxy(request: NextRequest) {
const refresh = request.cookies.get(refreshName)?.value
if (!refresh || !needsRefresh(access)) {
- return hadSpoofedEmbedHeader ? NextResponse.next({ request }) : NextResponse.next()
+ return hadSpoofedEmbed ? NextResponse.next({ request: { headers: new Headers(request.headers) } }) : NextResponse.next()
}
try {
@@ -58,7 +71,9 @@ export async function proxy(request: NextRequest) {
// config mistake fails loudly instead of signing everyone out.
if (!isDeadRefreshToken(error)) {
console.warn("auth.refresh.failed", tokenFailureLog(error))
- return hadSpoofedEmbedHeader ? NextResponse.next({ request }) : NextResponse.next()
+ return hadSpoofedEmbed
+ ? NextResponse.next({ request: { headers: new Headers(request.headers) } })
+ : NextResponse.next()
}
request.cookies.delete(accessName)
const response = NextResponse.next({ request })
diff --git a/apps/web/src/test/next-config.test.ts b/apps/web/src/test/next-config.test.ts
index eb2c9d86..7a54973d 100644
--- a/apps/web/src/test/next-config.test.ts
+++ b/apps/web/src/test/next-config.test.ts
@@ -53,7 +53,16 @@ describe("response headers", () => {
expect(globalIdx).toBeGreaterThanOrEqual(0)
expect(embedIdx).toBeGreaterThan(globalIdx)
- for (const path of ["/", "/campaigns/abc", "/me", "/admin", "/donations/GV123", "/invites/tok123", "/embedded"]) {
+ for (const path of [
+ "/",
+ "/campaigns/abc",
+ "/campaigns/embed",
+ "/me",
+ "/admin",
+ "/donations/GV123",
+ "/invites/tok123",
+ "/embedded",
+ ]) {
const headers = await resolveHeadersForPath(path)
expect(headers.get("x-frame-options"), path).toBe("DENY")
expect(headers.get("x-content-type-options"), path).toBe("nosniff")
@@ -67,6 +76,13 @@ describe("response headers", () => {
expect(headers.get("x-content-type-options"), embedPath).toBe("nosniff")
expect(headers.get("referrer-policy"), embedPath).toBe("strict-origin-when-cross-origin")
}
+
+ // Next.js pathToRegexp defaults to case-insensitive matching; proxy.ts explicitly
+ // rejects mixed-case /Embed/* and /EMBED with 404 + X-Frame-Options: DENY.
+ for (const mixedCaseEmbed of ["/Embed/abc", "/EMBED"]) {
+ const headers = await resolveHeadersForPath(mixedCaseEmbed)
+ expect(headers.get("x-frame-options"), mixedCaseEmbed).toBeUndefined()
+ }
})
it("strips Referer and disables caching on /donations/* after the site-wide defaults (DOS/Give#50)", async () => {
From 313d1eb8560c3c6dd9d9eca91bc19169a41e9e78 Mon Sep 17 00:00:00 2001
From: JOY <5027251+JOY@users.noreply.github.com>
Date: Mon, 23 Nov 2026 19:51:58 +0700
Subject: [PATCH 3/5] fix(embed): polish compact badges, goal deduplication,
and not-found clamp (Refs #335)
---
apps/web/src/app/embed/[slug]/page.test.ts | 1 +
apps/web/src/app/embed/[slug]/page.tsx | 11 ++++++++---
apps/web/src/components/EmbedNotFoundCard.tsx | 4 +++-
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/apps/web/src/app/embed/[slug]/page.test.ts b/apps/web/src/app/embed/[slug]/page.test.ts
index 90ffb2bf..6d4b4a53 100644
--- a/apps/web/src/app/embed/[slug]/page.test.ts
+++ b/apps/web/src/app/embed/[slug]/page.test.ts
@@ -321,6 +321,7 @@ describe("/embed/[slug] page (DOS/Give#335)", () => {
)
expect(noTotalsDoc.querySelector('[role="progressbar"]')).toBeNull()
expect(noTotalsDoc.body.textContent).not.toContain("đã nhận")
+ expect(noTotalsDoc.body.textContent?.match(/Mục tiêu/g)).toHaveLength(1)
expect(noTotalsDoc.body.textContent).toContain("Mục tiêu 100.000.000")
// 2. Expired live campaign shows "Đã hết hạn" and "Xem chi tiết" instead of "Ủng hộ ngay"
diff --git a/apps/web/src/app/embed/[slug]/page.tsx b/apps/web/src/app/embed/[slug]/page.tsx
index 2925d1c8..c8673087 100644
--- a/apps/web/src/app/embed/[slug]/page.tsx
+++ b/apps/web/src/app/embed/[slug]/page.tsx
@@ -55,7 +55,7 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
* third-party `