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
@@ -52,6 +52,7 @@ function row() {
|
||||
},
|
||||
createdAt: new Date("2026-11-08T00:00:00.000Z"),
|
||||
userId: "user-1",
|
||||
exportTokenVersion: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ describe("GET /api/rules/[id]/export/[format]", () => {
|
||||
});
|
||||
|
||||
it("returns a PDF attachment when the export token matches", async () => {
|
||||
const token = ruleExportToken("rule-1", PEPPER);
|
||||
const token = ruleExportToken("rule-1", PEPPER, 0);
|
||||
const res = await GET(
|
||||
new NextRequest(
|
||||
`https://x.test/api/rules/rule-1/export/pdf?t=${token}`,
|
||||
@@ -117,4 +118,19 @@ describe("GET /api/rules/[id]/export/[format]", () => {
|
||||
expect(text).toContain("# Garden Norms");
|
||||
expect(text).toContain("## Shared terms");
|
||||
});
|
||||
|
||||
it("rejects a mailed token after the share link is turned off", async () => {
|
||||
const token = ruleExportToken("rule-1", PEPPER, 0);
|
||||
findUniqueMock.mockResolvedValueOnce({
|
||||
...row(),
|
||||
exportTokenVersion: 1,
|
||||
});
|
||||
const res = await GET(
|
||||
new NextRequest(
|
||||
`https://x.test/api/rules/rule-1/export/pdf?t=${token}`,
|
||||
),
|
||||
makeContext("rule-1", "pdf"),
|
||||
);
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user