Skip to content

fix(mattermost): properly resolve ambiguous target IDs and enable image recognition [AI-assisted]#22594

Closed
webclerk wants to merge 2 commits intoopenclaw:mainfrom
webclerk:fix/mattermost-target-id-resolution
Closed

fix(mattermost): properly resolve ambiguous target IDs and enable image recognition [AI-assisted]#22594
webclerk wants to merge 2 commits intoopenclaw:mainfrom
webclerk:fix/mattermost-target-id-resolution

Conversation

@webclerk
Copy link

@webclerk webclerk commented Feb 21, 2026

Summary

This PR contains two fixes for the Mattermost integration:

  1. Properly resolve ambiguous target IDs via graceful fallback - Fixes an issue where 26-character user IDs without a prefix were incorrectly assumed to be channel IDs, leading to 403 Forbidden errors.

  2. Enable image recognition with SSRF policy - Adds SSRF policy configuration to allow fetching media files from the Mattermost server hostname, enabling proper image recognition.

Changes

Target ID Resolution

  • Changed normalizeMattermostMessagingTarget to return unprefixed IDs as-is instead of auto-adding channel: prefix
  • Added kind: "unknown" target type to represent ambiguous IDs
  • Modified parseMattermostTarget to classify unprefixed IDs as "unknown" instead of "channel"
  • Implemented try-catch fallback in resolveTargetChannelId to probe channel existence before falling back to user ID resolution

Image Recognition Support

  • Added ssrfPolicy parameter with allowed hostname when fetching media files
  • Enables the monitor to properly download and recognize images from Mattermost server

Testing

  • Tested locally with Mattermost instance
  • Verified ambiguous IDs (users/channels) are correctly resolved
  • Verified image recognition now works correctly with the SSRF policy in place
  • Both fixes have been validated in a real Mattermost environment

AI-Assisted Note

  • Mark as AI-assisted
  • Fully tested
  • Code reviewed and understood by contributor
  • AI tool used: Claude Sonnet 4.6

What & Why

Target ID Resolution

The Mattermost plugin was incorrectly treating all 26-character unprefixed IDs as channel IDs. This caused 403 errors when users tried to interact with direct message channels using user IDs. The fix implements a graceful fallback pattern that probes the ID type and falls back appropriately.

Image Recognition Support

The Mattermost monitor was unable to fetch images due to missing SSRF policy. This fix adds the required ssrfPolicy configuration to allow downloading media files from the configured Mattermost server hostname, which is essential for image recognition features.

Both fixes work together to provide a complete and robust Mattermost integration experience.

@openclaw-barnacle openclaw-barnacle bot added channel: mattermost Channel integration: mattermost size: S labels Feb 21, 2026
Add ssrfPolicy configuration to allow fetching media files from the
Mattermost server hostname, enabling proper image recognition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@webclerk webclerk changed the title fix(mattermost): properly resolve ambiguous target IDs via graceful fallback fix(mattermost): properly resolve ambiguous target IDs and enable image recognition [AI-assisted] Feb 22, 2026
@tonydehnke
Copy link
Contributor

Hey @webclerk, thanks for working on this! A few observations from our work on #19957 (interactive buttons + directory adapter) which touches the same normalize.ts file:

#channel-name path is unchanged

The normalizeMattermostMessagingTarget change on line 31 fixes bare names (return trimmed instead of return channel:${trimmed}), but the #channel branch at lines 28-29 is untouched — it still returns channel:name. This means #bookmarks resolves to channel:bookmarks, which passes the looksLikeId check and gets sent directly as a channel ID → 403 Forbidden (since bookmarks is a name, not a 26-char Mattermost ID).

In #19957 we return undefined for both #channel and bare names, which triggers the core's directory adapter to resolve the name to its actual Mattermost channel ID.

Silent error swallowing

The catch (e) { // Ignored } fallback in resolveTargetChannelId will mask real errors (expired tokens, network failures, rate limits). If the channel lookup fails for a non-404 reason, it silently falls through to treating the ID as a user — which will also fail, but with a confusing error about DM creation rather than the real cause.

looksLikeMattermostTargetId still loose

The existing {8,} regex matches short strings like "password" or "username". In #19957 we tightened this to strict 26-char alnum (Mattermost's actual ID format) plus the abc123__xyz789 DM channel pattern.

SSRF policy — great idea

The ssrfPolicy: { allowedHostnames: [...] } addition for media downloads is a genuinely useful fix that's independent of the target resolution changes. We're going to add this to #19957 as well (with credit to this PR). Nice catch!


These PRs will conflict on normalize.ts if both merge. Happy to coordinate — the approaches are complementary and the SSRF fix is valuable regardless of which normalize approach lands.

tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Feb 24, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Feb 24, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Feb 26, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Feb 27, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 1, 2026
tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Mar 2, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Mar 2, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Mar 2, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
tonydehnke added a commit to tonydehnke/openclaw that referenced this pull request Mar 5, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
mukhtharcm pushed a commit to tonydehnke/openclaw that referenced this pull request Mar 5, 2026
Allow fetching attachments from the Mattermost server host, which may
be localhost or a private IP. Without this, SSRF guards block inbound
media downloads silently.

Credit: @webclerk (openclaw#22594) for identifying this gap.
@mukhtharcm mukhtharcm closed this Mar 8, 2026
@mukhtharcm
Copy link
Member

Closing this out in favor of #29925.

The SSRF/media-fetch part is already in main, and the remaining bare-ID send ambiguity is better carried by the narrower active follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost size: S stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants