Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): fail closed on rate-limit check errors in send-download-link

Richie McIlroy99f8ece6a316
diff --git a/apps/web/__tests__/unit/send-download-link.test.ts b/apps/web/__tests__/unit/send-download-link.test.ts
index a23722d63..185008341 100644
--- a/apps/web/__tests__/unit/send-download-link.test.ts
+++ b/apps/web/__tests__/unit/send-download-link.test.ts
@@ -53,7 +53,7 @@ describe("sendDownloadLink", () => {
expect(sendEmailMock).not.toHaveBeenCalled();
});
- it("fails open when the rate limit check throws", async () => {
+ it("fails closed without sending email when the rate limit check throws", async () => {
checkRateLimitMock.mockRejectedValueOnce(
new Error("Unexpected response 494"),
);
@@ -65,8 +65,11 @@ describe("sendDownloadLink", () => {
const result = await sendDownloadLink("[email protected]");
- expect(result).toEqual({ success: true });
- expect(sendEmailMock).toHaveBeenCalledTimes(1);
+ expect(result).toEqual({
+ success: false,
+ error: "You've sent too many requests. Please try again later.",
+ });
+ expect(sendEmailMock).not.toHaveBeenCalled();
expect(consoleErrorSpy).toHaveBeenCalledWith(
'Rate limit check failed for "rl_send_download_link":',
expect.any(Error),
diff --git a/apps/web/actions/send-download-link.ts b/apps/web/actions/send-download-link.ts
index 402c1d500..15b1be66f 100644
--- a/apps/web/actions/send-download-link.ts
+++ b/apps/web/actions/send-download-link.ts
@@ -45,7 +45,10 @@ export async function sendDownloadLink(email: string) {
});
rateLimited = result.rateLimited;
} catch (error) {
- // Fail open: a firewall/edge outage must never block download emails.
+ // Fail closed: this action is unauthenticated and the rate limit is its
+ // only outbound-email guard, and a caller can force checkRateLimit to
+ // throw with oversized headers (494).
+ rateLimited = true;
console.error(
'Rate limit check failed for "rl_send_download_link":',
error,