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:
adilallo committed 2026-11-21 11:46:16 -07:00
1 parent 0fe2624002
commit 75649a9a42
18 files changed
+249 -19

No files matched your search

+25
View File
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
const isDatabaseConfiguredMock = vi.fn();
const findUniqueMock = vi.fn();
const rateLimitKeyMock = vi.fn();
const findManyMock = vi.fn();
const stakeholderFindManyMock = vi.fn();
const browserHoldsClaimForHashMock = vi.fn();
@@ -12,6 +13,10 @@ vi.mock("../../lib/server/env", () => ({
isDatabaseConfigured: () => isDatabaseConfiguredMock(),
}));
vi.mock("../../lib/server/rateLimit", () => ({
rateLimitKey: (...args: unknown[]) => rateLimitKeyMock(...args),
}));
vi.mock("../../lib/server/db", () => ({
prisma: {
publishedRule: {
@@ -71,9 +76,11 @@ beforeEach(() => {
browserHoldsClaimForHashMock.mockReset();
isRuleAdminEmailMock.mockReset();
logAdminRuleReadMock.mockReset();
rateLimitKeyMock.mockReset();
browserHoldsClaimForHashMock.mockResolvedValue(false);
isRuleAdminEmailMock.mockReturnValue(false);
logAdminRuleReadMock.mockResolvedValue(undefined);
rateLimitKeyMock.mockReturnValue({ ok: true });
});
describe("getReadablePublishedRule", () => {
@@ -220,6 +227,24 @@ describe("getReadablePublishedRule", () => {
}),
);
});
it("rate limits failed share-slug lookups", async () => {
isDatabaseConfiguredMock.mockReturnValue(true);
findUniqueMock.mockResolvedValueOnce(null);
expect(
await getReadablePublishedRule({
idOrSlug: "k7f2-9qxm",
user: null,
viaShareSlug: true,
requestPath: "/r/k7f2-9qxm",
failedLookupKey: "203.0.113.8",
}),
).toBeNull();
expect(rateLimitKeyMock).toHaveBeenCalledWith(
"share-lookup-miss:203.0.113.8",
1_000,
);
});
});
describe("listListedPublishedRules", () => {