Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🔒️ Show a warning page instead of a 404 for a banned creator's poll (#3273)

Luke Vellad1e2ca56408b
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index fb7a8475c..e624783c0 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -641,8 +641,14 @@
"pollClosed": "Poll closed",
"pollClosedDescription": "No more responses are being accepted.",
"pollDeleted": "Poll deleted",
+ "pollDeletedDescription": "It may have been deleted by its creator or removed after a period of inactivity.",
+ "pollDeletedTitle": "This poll has been deleted",
"pollDeleteError": "Failed to delete poll",
"pollNotificationsDescription": "Get notified by email when there is activity on your polls",
+ "pollRemovedDescription": "It violated our terms of use and is no longer available.",
+ "pollRemovedTitle": "This poll has been removed",
+ "pollRemovedWarningDescription": "Treat the message that sent you here as suspicious. Do not call phone numbers, follow links, or send money or personal details in response to it.",
+ "pollRemovedWarningTitle": "Weren't expecting this link?",
"pollReopened": "Poll reopened",
"polls": "Polls",
"pollStatusCanceled": "Canceled",
diff --git a/apps/web/src/app/[locale]/invite/[urlId]/page.tsx b/apps/web/src/app/[locale]/invite/[urlId]/page.tsx
index bc2f743db..d58d1eb80 100644
--- a/apps/web/src/app/[locale]/invite/[urlId]/page.tsx
+++ b/apps/web/src/app/[locale]/invite/[urlId]/page.tsx
@@ -8,6 +8,8 @@ import { SessionRefresher } from "@/components/session-refresher";
import { loadFooterLinks } from "@/features/instance-settings/loaders";
import { PermissionProvider } from "@/features/poll/client";
import { InviteOpenRecorder } from "@/features/poll/invite/components/invite-open-recorder";
+import type { PollUnavailableReason } from "@/features/poll/invite/components/poll-unavailable";
+import { PollUnavailable } from "@/features/poll/invite/components/poll-unavailable";
import { loadParticipantIdsByToken } from "@/features/poll/loaders";
import { UserProvider } from "@/features/user/client";
import { getLocale } from "@/i18n/server/get-locale";
@@ -34,10 +36,21 @@ const getPollMetadata = cache(async (urlId: string) => {
},
});
- if (!poll || poll.deleted || poll.user?.banned) {
+ if (!poll) {
notFound();
}
- return poll;
+
+ // A poll that exists but must not be served gets its own page instead of
+ // a 404: the viewer of a banned creator's poll is usually a scam target
+ // and needs to be told so, and a deleted poll's viewer deserves better
+ // than "page not found".
+ const unavailable: PollUnavailableReason | null = poll.deleted
+ ? "deleted"
+ : poll.user?.banned
+ ? "removed"
+ : null;
+
+ return { poll, unavailable };
});
export default async function Page(props: {
@@ -49,12 +62,18 @@ export default async function Page(props: {
}) {
const params = await props.params;
- const [, trpc, searchParams] = await Promise.all([
+ const [{ unavailable }, searchParams] = await Promise.all([
getPollMetadata(params.urlId),
- createPublicSSRHelper(),
props.searchParams,
]);
+ if (unavailable) {
+ return <PollUnavailable reason={unavailable} />;
+ }
+
+ // The SSR helper reads the session; an unavailable poll never needs it.
+ const trpc = await createPublicSSRHelper();
+
// `invite` is the param older invite emails carry; both name the same
// token and the client reads them the same way. A repeated param arrives
// as an array; only a single value is a token.
@@ -112,7 +131,14 @@ export async function generateMetadata(props: {
const { urlId } = params;
- const poll = await getPollMetadata(urlId);
+ const { poll, unavailable } = await getPollMetadata(urlId);
+
+ if (unavailable) {
+ return {
+ title: "Poll unavailable",
+ robots: { index: false, follow: false },
+ };
+ }
const { title, id, user } = poll;
diff --git a/apps/web/src/components/empty-state.tsx b/apps/web/src/components/empty-state.tsx
index 5559aba5b..f2b3bdaec 100644
--- a/apps/web/src/components/empty-state.tsx
+++ b/apps/web/src/components/empty-state.tsx
@@ -31,8 +31,14 @@ export function EmptyStateIcon({ children }: { children: React.ReactNode }) {
);
}
-export function EmptyStateTitle({ children }: { children: React.ReactNode }) {
- return <p className="font-semibold text-base">{children}</p>;
+export function EmptyStateTitle({
+ as: Component = "p",
+ children,
+}: {
+ as?: "p" | "h1" | "h2";
+ children: React.ReactNode;
+}) {
+ return <Component className="font-medium text-base">{children}</Component>;
}
export function EmptyStateDescription({
diff --git a/apps/web/src/features/poll/invite/components/poll-unavailable.tsx b/apps/web/src/features/poll/invite/components/poll-unavailable.tsx
new file mode 100644
index 000000000..cceac243b
--- /dev/null
+++ b/apps/web/src/features/poll/invite/components/poll-unavailable.tsx
@@ -0,0 +1,120 @@
+import { buttonVariants } from "@rallly/ui";
+import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
+import { ShieldAlertIcon, TrashIcon } from "lucide-react";
+import { Trans } from "react-i18next/TransWithoutContext";
+import {
+ EmptyState,
+ EmptyStateDescription,
+ EmptyStateFooter,
+ EmptyStateIcon,
+ EmptyStateTitle,
+} from "@/components/empty-state";
+import { Link } from "@/components/link";
+import { DefaultLogo } from "@/features/branding/components/default-logo";
+import { getTranslation } from "@/i18n/server";
+
+export type PollUnavailableReason = "deleted" | "removed";
+
+// Shown in place of the invite page when the poll exists but must not be
+// served. "removed" means the creator was banned, which is usually a scam:
+// the viewer is the intended victim, so the copy warns them. It never names
+// the poll, its creator, or a reason more specific than the terms of use.
+export async function PollUnavailable({
+ reason,
+}: {
+ reason: PollUnavailableReason;
+}) {
+ const { t, i18n } = await getTranslation();
+
+ if (reason === "deleted") {
+ return (
+ <main id="main-content" tabIndex={-1} className="p-4 pt-10">
+ <DefaultLogo className="mx-auto" />
+ <EmptyState className="py-12">
+ <EmptyStateIcon>
+ <TrashIcon />
+ </EmptyStateIcon>
+ <EmptyStateTitle as="h1">
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="pollDeletedTitle"
+ defaults="This poll has been deleted"
+ />
+ </EmptyStateTitle>
+ <EmptyStateDescription>
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="pollDeletedDescription"
+ defaults="It may have been deleted by its creator or removed after a period of inactivity."
+ />
+ </EmptyStateDescription>
+ <EmptyStateFooter>
+ <Link href="/" className={buttonVariants()}>
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="errorBackToHome"
+ defaults="Back to home"
+ />
+ </Link>
+ </EmptyStateFooter>
+ </EmptyState>
+ </main>
+ );
+ }
+
+ return (
+ <main id="main-content" tabIndex={-1} className="p-4 pt-10">
+ <DefaultLogo className="mx-auto" />
+ <EmptyState className="py-12">
+ <EmptyStateIcon>
+ <ShieldAlertIcon />
+ </EmptyStateIcon>
+ <EmptyStateTitle as="h1">
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="pollRemovedTitle"
+ defaults="This poll has been removed"
+ />
+ </EmptyStateTitle>
+ <EmptyStateDescription>
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="pollRemovedDescription"
+ defaults="It violated our terms of use and is no longer available."
+ />
+ </EmptyStateDescription>
+ <Alert variant="warning" className="mt-6 max-w-md">
+ <ShieldAlertIcon />
+ <AlertTitle>
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="pollRemovedWarningTitle"
+ defaults="Weren't expecting this link?"
+ />
+ </AlertTitle>
+ <AlertDescription>
+ <Trans
+ t={t}
+ i18n={i18n}
+ ns="app"
+ i18nKey="pollRemovedWarningDescription"
+ defaults="Treat the message that sent you here as suspicious. Do not call phone numbers, follow links, or send money or personal details in response to it."
+ />
+ </AlertDescription>
+ </Alert>
+ </EmptyState>
+ </main>
+ );
+}
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index bf1210f98..7f7217aa4 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -806,8 +806,10 @@ export const polls = router({
});
// A deleted poll is treated as if it never existed, for everyone
- // including its owner and space managers.
- if (!res || res.deleted) {
+ // including its owner and space managers. A banned creator's poll is
+ // hidden the same way: it is usually a scam lure and the page gate is
+ // not the only way to reach this read.
+ if (!res || res.deleted || res.user?.banned) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Poll not found",
diff --git a/apps/web/src/trpc/routers/polls/comments.ts b/apps/web/src/trpc/routers/polls/comments.ts
index 8114d8764..9367c9f76 100644
--- a/apps/web/src/trpc/routers/polls/comments.ts
+++ b/apps/web/src/trpc/routers/polls/comments.ts
@@ -41,11 +41,13 @@ export const comments = router({
userId: true,
hideParticipants: true,
deleted: true,
+ user: { select: { banned: true } },
},
});
- // A deleted poll never exposes its comments.
- if (!poll || poll.deleted) {
+ // A deleted poll, or one whose creator was banned, never exposes its
+ // comments.
+ if (!poll || poll.deleted || poll.user?.banned) {
throw new TRPCError({ code: "NOT_FOUND", message: "Poll not found" });
}
@@ -105,11 +107,13 @@ export const comments = router({
select: {
disableComments: true,
deleted: true,
+ user: { select: { banned: true } },
},
});
- // A deleted poll never accepts new comments.
- if (!targetPoll || targetPoll.deleted) {
+ // A deleted poll, or one whose creator was banned, never accepts new
+ // comments.
+ if (!targetPoll || targetPoll.deleted || targetPoll.user?.banned) {
throw new TRPCError({ code: "NOT_FOUND", message: "Poll not found" });
}
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index fd0564f26..d980be173 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -153,11 +153,13 @@ export const participants = router({
select: {
hideParticipants: true,
deleted: true,
+ user: { select: { banned: true } },
},
});
- // A deleted poll never exposes its participants.
- if (!poll || poll.deleted) {
+ // A deleted poll, or one whose creator was banned, never exposes its
+ // participants.
+ if (!poll || poll.deleted || poll.user?.banned) {
throw new TRPCError({ code: "NOT_FOUND", message: "Poll not found" });
}
@@ -345,11 +347,13 @@ export const participants = router({
select: {
status: true,
deleted: true,
+ user: { select: { banned: true } },
},
});
- // A deleted poll never accepts responses.
- if (!poll || poll.deleted) {
+ // A deleted poll, or one whose creator was banned, never accepts
+ // responses.
+ if (!poll || poll.deleted || poll.user?.banned) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Poll not found",
diff --git a/apps/web/tests/unavailable-poll.spec.ts b/apps/web/tests/unavailable-poll.spec.ts
new file mode 100644
index 000000000..621034ae1
--- /dev/null
+++ b/apps/web/tests/unavailable-poll.spec.ts
@@ -0,0 +1,140 @@
+import { randomUUID } from "node:crypto";
+import { expect, test } from "@playwright/test";
+import { prisma } from "@rallly/database";
+import { createTestPoll, createUserInDb, loginWithEmail } from "./test-utils";
+
+// A poll whose creator was banned is usually a scam lure. The person who
+// clicks the link is the intended victim, so the page they land on has to
+// warn them instead of showing a generic 404, and none of the poll's content
+// may leak through the page or the public tRPC reads.
+
+const scamTitle = "Claim your unclaimed parcel refund";
+
+async function createPollForUser(suffix: string) {
+ const user = await createUserInDb({
+ email: `unavailable-${suffix}-${randomUUID()}@example.com`,
+ name: "Poll Owner",
+ });
+ const poll = await createTestPoll({
+ id: `unavail-${randomUUID().slice(0, 8)}`,
+ title: scamTitle,
+ userId: user.id,
+ updatedAt: new Date(),
+ hasFutureOptions: true,
+ });
+ return { user, poll };
+}
+
+test.describe("unavailable poll invite page", () => {
+ test("a banned creator's poll shows the removed page and a scam warning", async ({
+ page,
+ }) => {
+ const { user, poll } = await createPollForUser("banned");
+
+ const main = page.locator("#main-content");
+
+ await page.goto(`/invite/${poll.id}`);
+ await expect(main.getByText(scamTitle).first()).toBeVisible();
+
+ const optionsBeforeBan = await page.request.get(
+ `/api/trpc/polls.get?input=${encodeURIComponent(
+ JSON.stringify({ json: { urlId: poll.id } }),
+ )}`,
+ );
+ const optionId = (await optionsBeforeBan.json()).result.data.json.options[0]
+ .id;
+ expect(optionId).toBeTruthy();
+
+ await prisma.user.update({
+ where: { id: user.id },
+ data: { banned: true, bannedAt: new Date(), banReason: "scam" },
+ });
+
+ await page.goto(`/invite/${poll.id}`);
+ await expect(
+ main.getByRole("heading", { name: "This poll has been removed" }),
+ ).toBeVisible();
+ await expect(main.getByRole("alert")).toContainText("suspicious");
+ await expect(main.getByText(scamTitle)).toHaveCount(0);
+ await expect(page).not.toHaveTitle(scamTitle);
+ await expect(page.locator('meta[name="robots"]')).toHaveAttribute(
+ "content",
+ /noindex/,
+ );
+
+ const get = await page.request.get(
+ `/api/trpc/polls.get?input=${encodeURIComponent(
+ JSON.stringify({ json: { urlId: poll.id } }),
+ )}`,
+ );
+ expect(get.status()).toBe(404);
+ const participants = await page.request.get(
+ `/api/trpc/polls.participants.list?input=${encodeURIComponent(
+ JSON.stringify({ json: { pollId: poll.id } }),
+ )}`,
+ );
+ expect(participants.status()).toBe(404);
+ const comments = await page.request.get(
+ `/api/trpc/polls.comments.list?input=${encodeURIComponent(
+ JSON.stringify({ json: { pollId: poll.id } }),
+ )}`,
+ );
+ expect(comments.status()).toBe(404);
+
+ // Writes are refused too, so a signed-in caller who kept the poll's
+ // option ids from before the ban cannot keep adding responses or
+ // comments to it.
+ const voter = await createUserInDb({
+ email: `unavailable-voter-${randomUUID()}@example.com`,
+ name: "Voter",
+ });
+ await loginWithEmail(page, { email: voter.email });
+ const addParticipant = await page.request.post(
+ "/api/trpc/polls.participants.add",
+ {
+ data: {
+ json: {
+ pollId: poll.id,
+ name: "Victim",
+ votes: [{ optionId: optionId, type: "yes" }],
+ },
+ },
+ },
+ );
+ expect(addParticipant.status()).toBe(404);
+ const addComment = await page.request.post("/api/trpc/polls.comments.add", {
+ data: {
+ json: { pollId: poll.id, authorName: "Victim", content: "Hello" },
+ },
+ });
+ expect(addComment.status()).toBe(404);
+ });
+
+ test("a deleted poll shows the deleted page without the scam warning", async ({
+ page,
+ }) => {
+ const { poll } = await createPollForUser("deleted");
+
+ await prisma.poll.update({
+ where: { id: poll.id },
+ data: { deleted: true, deletedAt: new Date() },
+ });
+
+ const main = page.locator("#main-content");
+
+ await page.goto(`/invite/${poll.id}`);
+ await expect(
+ main.getByRole("heading", { name: "This poll has been deleted" }),
+ ).toBeVisible();
+ await expect(main.getByRole("alert")).toHaveCount(0);
+ await expect(main.getByText(scamTitle)).toHaveCount(0);
+ await expect(page).not.toHaveTitle(scamTitle);
+ });
+
+ test("a missing poll is still a 404", async ({ page }) => {
+ await page.goto("/invite/does-not-exist");
+ await expect(
+ page.getByRole("heading", { name: "Page not found" }),
+ ).toBeVisible();
+ });
+});