Skip to content

fix: reject unsafe Mattermost API path segments - #98390

Merged
steipete merged 3 commits into
openclaw:mainfrom
ooiuuii:fix/mattermost-api-path-guard
Jul 17, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
ooiuuii:fix/mattermost-api-path-guard

Conversation

@ooiuuii

@ooiuuii ooiuuii commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #98389

What Problem This Solves

Fixes an issue where Mattermost plugin REST calls could reach a different bearer-token endpoint when a dynamic path component contained relative, URL-normalized, or malformed percent-encoded segments.

The affected workflow is Mattermost channel operation through the plugin REST client. Operators expect post, user, and channel ids to select the intended Mattermost endpoint; unsafe path-shaped values should fail before the client attaches the bot token and calls fetch.

Why This Change Was Made

The Mattermost client now rejects unsafe API path segments at one shared URL-builder boundary before preparing authorization headers. The direct authenticated media-file download path reuses the same builder. The guard handles raw . / .., encoded dot segments, backslash separator normalization, URL parser TAB/CR/LF normalization, and malformed percent encoding.

Normal Mattermost paths and request bodies are unchanged. This PR does not alter token storage, account resolution, or Mattermost response handling.

User Impact

Mattermost users and operators get safer fail-closed behavior for malformed or unexpected REST path inputs. Legitimate Mattermost plugin requests continue to use the same /api/v4 endpoints.

Evidence

Before/source proof:

  • On current main, buildMattermostApiUrl appended the requested suffix to /api/v4 without rejecting dot segments first.
  • WHATWG URL parsing normalizes examples like http://localhost:8065/api/v4/posts/../users/me to /api/v4/users/me, so a path-shaped id can change the endpoint selected under the Mattermost bot token.

After-fix proof on this branch:

  • node scripts/run-vitest.mjs extensions/mattermost/src/mattermost/client.test.ts extensions/mattermost/src/mattermost/monitor-resources.test.ts — 44 tests passed.
  • The media regression supplies raw, encoded, backslash, URL-control, and malformed paths and proves saveRemoteMedia receives no request.
  • Type-aware targeted oxlint passed for the four touched files.
  • git diff --check passed.
  • Fresh uncommitted and full-branch autoreview passes reported no accepted/actionable findings.

No live Mattermost credentials were used. The requested mocked transport proof exercises the production shared URL builder before either authenticated transport boundary.

@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: S labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 6:33 AM ET / 10:33 UTC.

Summary
The PR adds shared validation for unsafe Mattermost REST path segments and routes authenticated media downloads through the validated URL builder.

PR surface: Source +13, Tests +72. Total +85 across 4 files.

Reproducibility: yes. at source level: current main concatenates the unvalidated suffix, and WHATWG URL normalization provides a concrete path-changing example. I did not establish a live failing Mattermost request during this read-only review.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #98389
Summary: This PR is the focused candidate fix for the linked Mattermost bearer-authenticated path-normalization issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted controlled HTTP or live Mattermost evidence showing unsafe paths make no authenticated request and a normal path still succeeds.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only mocked pre-transport tests are supplied; add redacted controlled HTTP or live Mattermost terminal/log output, update the PR body to trigger review, or ask a maintainer to comment @clawsweeper re-review if it does not rerun. Redact tokens, private endpoints, IP addresses, phone numbers, and other private data.

Risk before merge

  • [P1] The security-sensitive guarantee is demonstrated only through mocks; there is no controlled HTTP or live Mattermost output confirming malformed input is rejected before any bearer-authenticated network request.

Maintainer options:

  1. Prove the authenticated boundary (recommended)
    Obtain controlled HTTP output showing unsafe paths fail before network transmission and ordinary API paths remain functional.
  2. Explicitly own the proof exception
    A qualified maintainer may accept the mocked evidence and record a proof override if further runtime proof is not proportionate.

Next step before merge

  • [P1] Wait for contributor-supplied controlled HTTP proof or an explicit qualified-maintainer proof override; no narrow mechanical code repair remains.

Maintainer decision needed

  • Question: Should this security-boundary PR require controlled HTTP after-fix proof, or should a qualified maintainer explicitly override the external-contributor real-proof gate based on the source and mocked transport coverage?
  • Rationale: The implementation appears correct and has focused regression coverage, but only a human can authorize bypassing the repository's real behavior proof requirement for an external security-sensitive PR.
  • Likely owner: steipete — This person is assigned and authored the latest security-boundary refinements, making them the best available owner for the proof decision.
  • Options:
    • Require controlled HTTP proof (recommended): Ask for redacted terminal output or logs showing unsafe input produces no authenticated request while a normal Mattermost API path still reaches the intended endpoint.
    • Approve a proof override: A qualified maintainer may explicitly accept the source analysis and mocked pre-transport coverage without additional runtime evidence.

Security
Cleared: No concrete security or supply-chain regression is introduced; the patch narrows authenticated request targets and adds no dependencies, permissions, secret access, or external code execution.

Review details

Best possible solution:

Keep the shared plugin-owned validator and both guarded transport paths, then demonstrate one rejected unsafe request and one successful normal request through a controlled HTTP endpoint before merge.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main concatenates the unvalidated suffix, and WHATWG URL normalization provides a concrete path-changing example. I did not establish a live failing Mattermost request during this read-only review.

Is this the best way to solve the issue?

Yes. Validating once in the plugin-owned URL builder before authorization and reusing it for the direct media path is narrower and less drift-prone than adding checks at individual callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c3bc3a72366c.

Label changes

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded Mattermost security hardening fix with limited channel scope and no demonstrated active exploitation or core-runtime outage.
  • merge-risk: 🚨 security-boundary: The patch determines whether attacker-shaped input can alter a bearer-authenticated Mattermost request target, so runtime-boundary confidence matters before merge.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only mocked pre-transport tests are supplied; add redacted controlled HTTP or live Mattermost terminal/log output, update the PR body to trigger review, or ask a maintainer to comment @clawsweeper re-review if it does not rerun. Redact tokens, private endpoints, IP addresses, phone numbers, and other private data.
Evidence reviewed

PR surface:

Source +13, Tests +72. Total +85 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 15 2 +13
Tests 2 78 6 +72
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 93 8 +85

What I checked:

Likely related people:

  • steipete: Assigned this PR and authored the current refinements that extended the guard to direct media downloads and streamlined validation. (role: assignee and recent repair author; confidence: high; commits: ff6f37401c41, 702f0c696216; files: extensions/mattermost/src/mattermost/client.ts, extensions/mattermost/src/mattermost/monitor-resources.ts)
  • mukhtharcm: The repository contributor guide lists this person for Mattermost review routing. citeturn14search0. (role: declared Mattermost area contact; confidence: medium; files: extensions/mattermost)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-17T07:41:29.692Z sha 64ee73673a88b593d96c8e7a0246cab8f1a6db1c :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T07:53:48.829Z sha 9c80b57a3bc8f9223e746b6ae9ff516712c7d93d :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T08:21:41.457Z sha 1bc9b8120e0ee291eaaabc811da6149685e0b2d5 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T08:49:42.406Z sha fe2c946cd908486979df1fe125a4ae67a5ef9095 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T08:58:04.172Z sha 0ae1c95d730ad5677fee0322a5378e91fbe6c4b9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T09:23:42.435Z sha fd80edab0b4921307aebf81eb0477ac99badcdb0 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T09:33:05.596Z sha ace7ebccad3d5fc4b1ca6149bfff709e4b855b3e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T10:13:13.699Z sha f23a132a245b8c4f3cb2d0640daad371fbddec59 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 1, 2026
@steipete steipete self-assigned this Jul 1, 2026
@steipete
steipete force-pushed the fix/mattermost-api-path-guard branch from 56bf468 to 64ee736 Compare July 17, 2026 07:33
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 17, 2026
@steipete
steipete force-pushed the fix/mattermost-api-path-guard branch 8 times, most recently from ace7ebc to f23a132 Compare July 17, 2026 10:09
@steipete
steipete force-pushed the fix/mattermost-api-path-guard branch from f23a132 to 702f0c6 Compare July 17, 2026 10:27
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 17, 2026
@steipete
steipete merged commit 9769642 into openclaw:main Jul 17, 2026
96 of 98 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
* Harden Mattermost API paths

* fix(mattermost): guard direct media file paths

* refactor(mattermost): streamline API path validation

---------

Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
* Harden Mattermost API paths

* fix(mattermost): guard direct media file paths

* refactor(mattermost): streamline API path validation

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mattermost API client accepts unsafe relative path segments before bearer-token requests

2 participants