← Back to PRs

#4665: fix(slack): reject HTML responses when downloading media

by tumf open 2026-01-30 13:47 View on GitHub →
channel: slack agents
## Summary Slack sometimes returns HTML login pages instead of binary media when authentication fails (e.g., missing `files:read` scope) or URLs expire. This change detects and rejects HTML responses, improving error visibility. ## Changes - Add `looksLikeHtml()` function to detect HTML content by checking: - `<!doctype html` or `<html` prefixes - `slack-edge.com` or `redirecturl:` patterns (Slack-specific) - Log warning when HTML is received instead of media - Skip to next file URL when HTML is detected - Add tests for HTML detection scenarios ## Testing - [x] Unit tests added and passing - [x] Tested locally with Slack channel file uploads - [x] Verified warning log helps identify scope/auth issues ## AI Assistance - [x] AI-assisted (Claude) - [x] Fully tested - [x] I understand what the code does This fix helped diagnose a real issue where `files:read` scope was missing from the Slack bot token - the warning log made it clear that HTML was being returned instead of the actual file. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> (placeholder) <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with low risk; behavior change is scoped to Slack media downloads and covered by unit tests. - Change is localized and defensive (skip HTML masquerading as media). Main risk is false positives from heuristic HTML detection, but the code exempts expected HTML files and tests cover key cases. - src/slack/monitor/media.ts (HTML detection heuristic) <!-- greptile_other_comments_section --> <sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs