Repository navigation
feat(embed): clickjacking-safe /embed/[slug] campaign widget & iframe snippet (Refs #335) - #342
Conversation
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
a2b4572 to
a36646d
Compare
There was a problem hiding this comment.
⏱️ Code Review completed (21 eligible files · 78,087 chars · 3 model call(s) · 3 PR unit(s))
Whole diff with bounded context at base d69a6ba / head a36646d.
✅ No verified defects
1 possible issue(s) could not be grounded in or verified against the snapshot source, so they are not published.
Context investigation was bounded to the explicitly requested snapshot paths.
|
PO acceptance: merge at db0de89 |
Refs #335
Summary
Implements the clickjacking-safe, read-only embeddable campaign widget (
/embed/[slug]) and copy-paste HTML-escaped<iframe>snippet UI inside the campaign share flow.Changes
Scoped Framing Headers (
apps/web/next.config.ts) & Proxy Isolation (apps/web/src/proxy.ts):/:path*to/((?!embed(?:/|$)).*), preservingX-Frame-Options: DENYon all non-embed routes (/,/campaigns/*,/me,/admin,/donations/*,/invites/*)./embed/:path*header rule withX-Content-Type-Options: nosniff,Content-Security-Policy: frame-ancestors *,Referrer-Policy: strict-origin-when-cross-origin, and noX-Frame-Options.embed(?:/|$)inproxy.tsconfig.matcherso cross-origin<iframe>loads never trigger OAuth token refresh orSet-Cookieheaders, and explicitly return404withX-Frame-Options: DENY+frame-ancestors 'none'for mixed-case/Embed/*paths.Chrome-Free Standalone
/embed/[slug](apps/web/src/app/embed/**,LayoutShell.tsx,layout.tsx,globals.css):LayoutShell(usePathname()) inRootLayoutso/embedand/embed/*omitSiteHeader,SiteFooter, andRingBoxScrollon both SSR and client without altering existing route paths.apps/web/src/app/embed/[slug]/page.tsx(force-dynamic,robots: { index: false, follow: false }), strictly anonymousdbAs()only (zerogetSession(), cookies,<form>, or VietQR/transfer details), enforcingSLUG_PATTERN(<= 80) andisPublicCampaignVisible().theme:light | dark | auto,compact:1 | 0,ref:sanitizeAmbassadorRef) inapps/web/src/lib/embed.ts+ explicit light/dark semantic token overrides inglobals.css(:root:has([data-embed-theme=...])).approvedwithprelaunch_publicand futurestarts_at) never queriesgetMoneyTotalsand never renders raised/goal amounts or progress bars, showing"Sắp ra mắt"+ scheduled date and"Xem chi tiết"CTA./embedroot (app/embed/page.tsx), nested/embed/[slug]/[...rest]catch-all, and compact themedEmbedNotFoundCard(app/embed/not-found.tsx).Copy-Paste Embed Snippet UI (
apps/web/src/components/EmbedWidgetDisclosure.tsx,apps/web/src/app/campaigns/[slug]/page.tsx):"Nhúng vào website / báo chí"disclosure on publicly visible campaigns (!preview && isPublicCampaignVisible(campaign)), with280px/180pxsize toggle,light/dark/autotheme selector, HTML-escaped<iframe>snippet (border-radius:6pxperDESIGN.md), optional valid?ref=forwarding, and 1-click copy withshare_clickanalytics.Verification
pnpm format:check: passedpnpm --filter @give/web exec vitest run --maxWorkers=2 --fileParallelism=false: 218 files, 2932 tests passedpnpm --filter @give/web typecheck: passedpnpm --filter @give/web lint: passedpnpm --filter @give/web build: passed (ƒ /embed,ƒ /embed/[slug],ƒ /embed/[slug]/[...rest],ƒ Proxy (Middleware))📌 TL;DR
This PR introduces a secure, read-only embeddable campaign widget (
/embed/[slug]) that allows third-party sites to display campaign progress via iframe. It implements strict security boundaries (no session/auth, no forms, CSPframe-ancestors) and provides a UI component for users to generate and copy the embed code.🎯 Type of Change
🔍 Changes Walkthrough
apps/web/next.config.ts/embed/*routes via CSPframe-ancestors *while maintainingX-Frame-Options: DENYfor all other routes.apps/web/src/app/layout.tsxLayoutShellcomponent, enabling conditional rendering of site chrome (header/footer) based on the route.apps/web/src/components/layout/LayoutShell.tsx/embedroutes (case-insensitive) and omitsSiteHeader,SiteFooter, andRingBoxScrollto provide a chrome-free iframe experience.apps/web/src/app/embed/[slug]/page.tsxgetSession, nodbService), handles pre-launch teasers (hiding financial data), and renders a compact campaign summary with a CTA link.apps/web/src/app/embed/[slug]/page.test.tsapps/web/src/app/embed/page.tsx/embedthat triggersnotFound().apps/web/src/app/embed/not-found.tsxEmbedNotFoundCard.apps/web/src/app/embed/[slug]/[...rest]/page.tsxnotFound().apps/web/src/components/EmbedWidgetDisclosure.tsxapps/web/src/components/EmbedNotFoundCard.tsx?themequery parameter.apps/web/src/app/campaigns/[slug]/page.tsxEmbedWidgetDisclosureinto the campaign sidebar for both live and pre-launch public campaigns.apps/web/src/app/globals.css[data-embed-theme]attributes.apps/web/src/lib/embed.tsparseEmbedOptions,buildEmbedIframeCode, and theme constants.apps/web/src/app/layout.test.ts/embedroutes.apps/web/src/components/layout/LayoutShell.test.tsLayoutShellroute detection and rendering logic.apps/web/src/components/EmbedWidgetDisclosure.test.tsapps/web/src/app/embed/not-found.test.ts📊 Architectural Flow
sequenceDiagram participant User as User (Campaign Page) participant Disclosure as EmbedWidgetDisclosure participant ThirdParty as Third-Party Site participant EmbedRoute as /embed/[slug] participant Supabase as Supabase (Anon) Note over User, Disclosure: 1. Generate Embed Code User->>Disclosure: Click "Nhúng vào website" Disclosure->>Disclosure: Build iframe snippet (theme, size, ref) User->>Disclosure: Click "Copy" Disclosure->>User: Copy to clipboard Note over ThirdParty, Supabase: 2. Render Embed ThirdParty->>EmbedRoute: Load iframe (/embed/slug?theme=dark) EmbedRoute->>EmbedRoute: Check route (no session/auth) EmbedRoute->>Supabase: Fetch public campaign data (anon key) Supabase-->>EmbedRoute: Return campaign + totals EmbedRoute->>EmbedRoute: Check visibility (status, prelaunch) alt Public & Live EmbedRoute-->>ThirdParty: Render widget (progress, CTA) else Pre-launch or Hidden EmbedRoute-->>ThirdParty: Render teaser or 404 end