Files
dataroom/lib/api/domains/clear-team-redirects.ts
zeekayandMarc Seitz 4304dd4ce7 fix: harden root domain redirects - validation, plan gating, cleanup
- Change redirect status from 301 to 302 (non-permanent, user-configurable)
- Remove backfill UPDATE entries from migration SQL
- Remove unnecessary sync-redirects cron endpoint
- Add URL validation: SSRF protection, edge config keyword blocklist,
  protocol check, URL sanitization via shared validateRedirectUrl helper
- Add plan gating: require Business plan or higher for redirect URLs
  (enforced on both API endpoints and UI)
- Clean up Redis redirect URLs on team deletion
- Clear redirect URLs (Postgres + Redis) on subscription cancellation
  and on plan downgrade below Business
- Split redis.ts to avoid Prisma import in edge middleware context
- Gate DomainCard redirect UI based on plan (show upgrade prompt)

Co-authored-by: Marc Seitz <[email protected]>
2026-02-22 08:24:29 +00:00

28 lines
707 B
TypeScript

import prisma from "@/lib/prisma";
import { redis } from "@/lib/redis";
import { getRedisKey } from "./redis";
/**
* Clears all redirect URLs for every domain belonging to a team,
* removing them from both Postgres and Redis.
*/
export async function clearTeamDomainRedirects(
teamId: string,
): Promise<void> {
const domains = await prisma.domain.findMany({
where: { teamId, redirectUrl: { not: null } },
select: { slug: true },
});
if (domains.length === 0) return;
await Promise.all([
prisma.domain.updateMany({
where: { teamId, redirectUrl: { not: null } },
data: { redirectUrl: null },
}),
...domains.map((d) => redis.del(getRedisKey(d.slug))),
]);
}