Skip to content

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

Merged
Takhoffman merged 5 commits intoopenclaw:mainfrom
tumf:fix/slack-media-changes
Mar 1, 2026
Merged

fix(slack): reject HTML responses when downloading media#4665
Takhoffman merged 5 commits intoopenclaw:mainfrom
tumf:fix/slack-media-changes

Conversation

@tumf
Copy link
Contributor

@tumf tumf commented Jan 30, 2026

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

  • Unit tests added and passing
  • Tested locally with Slack channel file uploads
  • Verified warning log helps identify scope/auth issues

AI Assistance

  • AI-assisted (Claude)
  • Fully tested
  • 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 Overview

Greptile Summary

(placeholder)

Confidence Score: 4/5

  • 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)

(4/5) You can add custom instructions or style guidelines for the agent here!

@openclaw-barnacle openclaw-barnacle bot added the channel: slack Channel integration: slack label Jan 30, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da6f3e21a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@tumf tumf force-pushed the fix/slack-media-changes branch 2 times, most recently from 7503b9c to a6792cd Compare February 1, 2026 08:48
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 3, 2026

Additional Comments (1)

src/slack/monitor/media.test.ts
[P1] The new tests don’t assert the warning log side-effect. Since the PR’s goal is improved diagnosability, it’d be useful to mock ../../logger.js and assert logWarn is called when HTML is detected (and not called for genuine HTML files). This helps prevent regressions where the guard keeps working but the visibility signal disappears.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/slack/monitor/media.test.ts
Line: 1:1

Comment:
[P1] The new tests don’t assert the warning log side-effect. Since the PR’s goal is improved diagnosability, it’d be useful to mock `../../logger.js` and assert `logWarn` is called when HTML is detected (and *not* called for genuine HTML files). This helps prevent regressions where the guard keeps working but the visibility signal disappears.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 3, 2026
@tumf tumf force-pushed the fix/slack-media-changes branch from 5b43c58 to 999fa64 Compare February 11, 2026 23:38
@tumf
Copy link
Contributor Author

tumf commented Feb 11, 2026

Rebased onto main and addressed review feedback:

  • P2 Allow genuine HTML files: Fixed - now skips HTML detection for files with mimetype: text/html or .html/.htm extensions
  • P2 looksLikeHtml trim: Fixed - now only trims leading whitespace (replace(/^\s+/, "")) and removed slack-edge.com/redirecturl: checks, keeping only reliable <!doctype html and <html prefix detection
  • P1 logWarn test assertions: Added - tests now mock logWarn and assert it is called (or not called for genuine HTML files)

@mudrii

This comment was marked as spam.

@mudrii

This comment was marked as spam.

tumf and others added 5 commits March 1, 2026 10:55
Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.
@Takhoffman Takhoffman force-pushed the fix/slack-media-changes branch from edc1695 to 389d354 Compare March 1, 2026 17:20
@openclaw-barnacle openclaw-barnacle bot added size: S and removed agents Agent runtime and tooling labels Mar 1, 2026
@Takhoffman Takhoffman merged commit e057139 into openclaw:main Mar 1, 2026
11 checks passed
zooqueen added a commit to hanzoai/bot that referenced this pull request Mar 1, 2026
ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
amitmiran137 pushed a commit to amitmiran137/openclaw that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
hanqizheng pushed a commit to hanqizheng/openclaw that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
* fix(slack): reject HTML responses when downloading media

Slack sometimes returns HTML login pages instead of binary media when
authentication fails or URLs expire. This change detects HTML responses
by checking content-type header and buffer content, then skips to the
next available file URL.

* fix: format import order and add braces to continue statement

* chore: format Slack media tests

* chore: apply formatter to Slack media tests

* fix(slack): merge auth-header forwarding and html media guard

---------

Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
zooqueen added a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants