feat(security): add Redis-backed rate limiting and CSP/security headers

Public go-live hardening: Redis-backed rate limiting on the previously
invite-gated public surface (explore browsing, post/comment creation,
invite-cookie routes) plus CSP, HSTS, and standard security headers on
every response, now that the invite gate no longer filters traffic.
This commit is contained in:
admin committed 2026-08-10 07:57:56 +02:00
1 parent ec9573f33a
commit f43541a4cc
11 files changed
+162 -8

No files matched your search

+5 -2
View File
@@ -1,6 +1,6 @@
import "server-only";
import { z } from "zod";
import { router, publicProcedure } from "@/trpc/init";
import { router, publicProcedure, rateLimited } from "@/trpc/init";
import { pickLocalizedName } from "@/lib/localized-name";
const TRENDING_POSTS_WINDOW_MS = 48 * 60 * 60 * 1000; // 48 h
@@ -8,6 +8,7 @@ const TRENDING_HASHTAGS_WINDOW_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
export const exploreRouter = router({
listPets: publicProcedure
.use(rateLimited("explore.listPets", 60, 60))
.input(
z.object({
speciesId: z.string().optional(),
@@ -50,7 +51,9 @@ export const exploreRouter = router({
* getTrending — trending posts (48 h window, ranked by reaction count)
* and trending hashtags (7 day window, ranked by post count).
*/
getTrending: publicProcedure.query(async ({ ctx }) => {
getTrending: publicProcedure
.use(rateLimited("explore.getTrending", 30, 60))
.query(async ({ ctx }) => {
const now = Date.now();
const since48h = new Date(now - TRENDING_POSTS_WINDOW_MS);
const since7d = new Date(now - TRENDING_HASHTAGS_WINDOW_MS);