#4665: fix(slack): reject HTML responses when downloading media
channel: slack
agents
Cluster:
Slack Media Handling Fixes
## 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
#14847: fix(slack): preserve auth across Slack-hosted file redirects
by natashache · 2026-02-12
83.8%
#18763: fix(slack): add auth header when downloading forwarded attachment i...
by amabito · 2026-02-17
79.3%
#20479: fix(slack): keep replies flowing for oversized file uploads
by olyashok · 2026-02-19
79.0%
#22942: fix(slack): parse generic attachment text for inbound events
by danielalkurdi · 2026-02-21
78.1%
#15095: fix(slack): process all file attachments instead of only the first
by Lar000ki · 2026-02-13
77.0%
#8684: fix(slack): add title param and channel resolution for file upload
by shuans · 2026-02-04
76.5%
#8024: fix(slack): resolve channel names via directory for cross-account m...
by emma-digital-assistant · 2026-02-03
74.4%
#17558: fix(slack): replace files.uploadV2 with 3-step upload flow to fix m...
by fif911 · 2026-02-15
73.7%
#20480: feat(slack): extract and surface attachment notes in messages
by olyashok · 2026-02-19
73.6%
#11443: LINE: fix buffer guards in detectContentType + add tests
by MdRahmatUllah · 2026-02-07
73.3%