Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(security): add AbortController timeout to Discord thread validation

psychosomat8628801a4bd2
diff --git a/.github/scripts/discord-thread-validator.mjs b/.github/scripts/discord-thread-validator.mjs
index 4def9d9f1..88ae9c7ea 100644
--- a/.github/scripts/discord-thread-validator.mjs
+++ b/.github/scripts/discord-thread-validator.mjs
@@ -7,10 +7,15 @@ export async function validateThreadChannel(threadId, prNumber, { botToken, foru
);
return false;
}
+ const VALIDATION_TIMEOUT_MS = 5_000;
try {
+ const controller = new AbortController();
+ const timeout = setTimeout(() => controller.abort(), VALIDATION_TIMEOUT_MS);
const res = await fetch(`https://discord.com/api/v10/channels/${threadId}`, {
headers: { Authorization: `Bot ${botToken}` },
+ signal: controller.signal,
});
+ clearTimeout(timeout);
if (!res.ok) {
warning(`Thread validation failed: channel ${threadId} returned ${res.status}`);
return false;
diff --git a/.github/scripts/discord-thread-validator.test.mjs b/.github/scripts/discord-thread-validator.test.mjs
index ae5d77dc6..f2c686b85 100644
--- a/.github/scripts/discord-thread-validator.test.mjs
+++ b/.github/scripts/discord-thread-validator.test.mjs
@@ -83,6 +83,25 @@ describe("validateThreadChannel", () => {
expect(result).toBe(false);
});
+ it("passes an AbortSignal with timeout to fetch", async () => {
+ vi.mocked(fetch).mockResolvedValue({
+ ok: true,
+ json: async () => ({
+ id: "777",
+ parent_id: "888888888888888888",
+ name: `PR #${number} - gated`,
+ }),
+ });
+
+ await validateThreadChannel("777", number, {
+ botToken,
+ forumChannelId: "888888888888888888",
+ });
+
+ const call = vi.mocked(fetch).mock.calls[0];
+ expect(call[1].signal).toBeInstanceOf(AbortSignal);
+ });
+
it("returns false when fetch throws", async () => {
vi.mocked(fetch).mockRejectedValue(new Error("network error"));