Add a content security policy and expire mailed export links.
Responses had no CSP, the 48-hour download token never changed, and short share slugs could be guessed without a miss limit.
This commit is contained in:
1 parent
0fe2624002
commit
75649a9a42
18 files changed
+249
-19
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import type { Metadata } from "next";
|
||||
import { headers } from "next/headers";
|
||||
import { notFound } from "next/navigation";
|
||||
import messages from "../../../../messages/en/index";
|
||||
import { isShareSlug } from "../../../../lib/sharePaths";
|
||||
import { getReadablePublishedRule } from "../../../../lib/server/publishedRules";
|
||||
import { rateLimitKey } from "../../../../lib/server/rateLimit";
|
||||
import { getSessionUser } from "../../../../lib/server/session";
|
||||
import { parsePublishedDocumentForCommunityRuleDisplay } from "../../../../lib/create/publishedDocumentToDisplaySections";
|
||||
import { NO_INDEX_ROBOTS, routeMetadata } from "../../../../lib/siteMetadata";
|
||||
@@ -13,14 +15,28 @@ interface PageProps {
|
||||
params: Promise<{ shareSlug: string }>;
|
||||
}
|
||||
|
||||
async function clientIp(): Promise<string> {
|
||||
const headerStore = await headers();
|
||||
return (
|
||||
headerStore.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
headerStore.get("x-real-ip") ||
|
||||
"unknown"
|
||||
);
|
||||
}
|
||||
|
||||
async function loadSharedRule(shareSlug: string) {
|
||||
if (!isShareSlug(shareSlug)) return null;
|
||||
const ip = await clientIp();
|
||||
if (!isShareSlug(shareSlug)) {
|
||||
rateLimitKey(`share-lookup-miss:${ip}`, 1_000);
|
||||
return null;
|
||||
}
|
||||
const user = await getSessionUser();
|
||||
return getReadablePublishedRule({
|
||||
idOrSlug: shareSlug,
|
||||
user,
|
||||
viaShareSlug: true,
|
||||
requestPath: `/r/${shareSlug}`,
|
||||
failedLookupKey: ip,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user