Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): reject Slack login HTML from file fetches (#1841)

vercel-gh-bot-4[bot]e1080e0b0b97
diff --git a/.changeset/slack-file-fetch-reject-html.md b/.changeset/slack-file-fetch-reject-html.md
new file mode 100644
index 000000000..ee11b6afe
--- /dev/null
+++ b/.changeset/slack-file-fetch-reject-html.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Reject HTML sign-in pages returned by Slack private file downloads and explain how to restore attachment access.
diff --git a/docs/channels/slack.mdx b/docs/channels/slack.mdx
index 31e357d71..7d65f7add 100644
--- a/docs/channels/slack.mdx
+++ b/docs/channels/slack.mdx
@@ -309,6 +309,8 @@ Start a session without an inbound message through `ctx.to(slack, target).send(m
Inbound files behind authenticated Slack URLs are staged with `fetchFile`. See [File uploads](./custom#file-uploads) for the `fetchFile` contract.
+Private file downloads require the Slack bot token's `files:read` scope. Add the scope and reinstall the Slack app before sending attachments. If Slack returns an HTML sign-in page instead of file bytes, eve rejects the response with this remediation instead of staging the page as an attachment.
+
## What to read next
- [Channels overview](./overview): the channel contract and every built-in channel
diff --git a/packages/eve/src/public/channels/slack/attachments.test.ts b/packages/eve/src/public/channels/slack/attachments.test.ts
index 66f6a9645..763222824 100644
--- a/packages/eve/src/public/channels/slack/attachments.test.ts
+++ b/packages/eve/src/public/channels/slack/attachments.test.ts
@@ -232,6 +232,21 @@ describe("createSlackFetchFile", () => {
await expect(fetchFile("https://files.slack.com/locked.csv")).rejects.toThrow("HTTP 403");
});
+
+ it("rejects HTML returned for a private Slack file", async () => {
+ vi.spyOn(globalThis, "fetch").mockResolvedValue(
+ new Response("<!DOCTYPE html><html><body>Slack sign in</body></html>", {
+ status: 200,
+ headers: { "content-type": "text/html; charset=utf-8" },
+ }),
+ );
+
+ const fetchFile = createSlackFetchFile({ botToken: "xoxb-test-token" });
+
+ await expect(fetchFile("https://files.slack.com/locked.png")).rejects.toThrow(
+ /files:read.*reinstall/is,
+ );
+ });
});
describe("collectInboundFileParts", () => {
diff --git a/packages/eve/src/public/channels/slack/attachments.ts b/packages/eve/src/public/channels/slack/attachments.ts
index f2c5e9a74..2c571e754 100644
--- a/packages/eve/src/public/channels/slack/attachments.ts
+++ b/packages/eve/src/public/channels/slack/attachments.ts
@@ -179,9 +179,17 @@ export function createSlackFetchFile(input: {
if (!response.ok) {
throw new Error(`Slack file fetch returned HTTP ${response.status} for ${url}.`);
}
+ const mediaType = response.headers.get("content-type") ?? undefined;
+ const normalizedMediaType = mediaType?.split(";", 1)[0]?.trim().toLowerCase();
+ if (normalizedMediaType === "text/html") {
+ throw new Error(
+ `Slack file fetch returned an HTML sign-in page instead of file bytes for ${url}. ` +
+ "The bot token may be missing the files:read scope. Add the scope, reinstall the Slack app, and retry.",
+ );
+ }
return {
bytes: Buffer.from(await response.arrayBuffer()),
- mediaType: response.headers.get("content-type") ?? undefined,
+ mediaType,
};
};
}