Skip to content

refactor(msteams): simplify attachment size and redirect handling - #130595

Merged
steipete merged 1 commit into
mainfrom
codex/cleanup20k-teams-attachment-owner-20260826
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cleanup20k-teams-attachment-owner-20260826

Conversation

@steipete

@steipete steipete commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Maintainer-requested cleanup of redundant Microsoft Teams attachment handling. The attachment owner repeats base64 size accounting after validation and retains a redirect loop whose later iterations cannot run, making the actual guard ownership harder to follow.

Why This Change Was Made

Use the already-imported Buffer.byteLength only after the unchanged inline-base64 validator, and express the injected-dispatcher path as its existing single request. Keep initial DNS and hostname checks, redirect validation, authorization handling, response identity, and the normal SDK-owned five-redirect limit unchanged. No new dependency, SDK surface, configuration, or network policy.

The existing auth-redirect test also injected a dispatcher through a downloader mock that is no longer called. Remove that ineffective setup and assert the actual guarded-fetch request sequence instead; strengthen the real dispatcher and inline-size boundary tests.

User Impact

No intended user-visible change. Existing attachment acceptance, limits, authorization, errors, and redirect behavior remain the same. Production LOC: +41/-93 (net -52); tests: +136/-77 (net +59), using standard Git diff.

Evidence

  • Baseline: 43be187b6727a47030dbbba4256eaad89937bded. The three affected files were unchanged on freshly checked main 18c801daa1165f0bb7f30576b52f6642ff023233; related open Teams PRs did not supersede this cleanup.
  • Node 24.19.0 differential proof: 401,442 raw base64 inputs, 159,424 accepted canonical payloads with identical estimated and decoded lengths, plus 96 per-image threshold comparisons. Direct inspection of Node's Buffer implementation and string-size limit confirms the arithmetic is equivalent without overflow. The Node Buffer contract requires valid input; the unchanged Teams validator supplies that precondition.
  • Additional differential owner proof: 2,307 fetch control-flow traces and 816 inline-image boundary cases matched before/after. These use controlled fetch/DNS doubles, not live Teams or external-network proof.
  • Focused existing suite: baseline 110 tests passed; final reviewed candidate 128 tests passed across four files. Local runtime Node 24.19.0, Vitest 4.1.10 and Undici 8.9.0; these local dependency versions are older than the pinned Vitest 4.1.11/Undici 8.10.0, so local results are supplemental to exact-head CI.
  • The misleading test's injected mock was independently confirmed unused: an explicit invocation assertion failed with zero calls before the test correction. The corrected test verifies the real three-request auth/redirect order and guarded dispatch.
  • Fresh independent pre-commit Codex review passed with no findings, covering the complete diff and 28 complete source inputs, including the Node 24 Buffer implementation. This is static review, not test or live execution.
  • Formatting, git diff --check, and the changed-code gate's initial/static/dead-export guards passed. The full local changed-code gate failed at extension type checking on stale or missing installed dependencies, with no Teams diagnostic: for example, installed CUA 0.19.3 versus pinned 0.20.0, pi-tui 0.82.1 versus 0.84.2, markdown-it 14.3.0 versus 15.0.0, and missing IMAP/geolocation packages. The shared dependency installation was left untouched. This is a recorded local gate failure, not a passing full gate; ordinary exact-head CI must supply the pinned type/lint proof before landing.
  • Ordinary exact-head CI passed on aed33f24fb9636994e3b56daa1657bb08db26141, including production/test types, lint, guards, build artifacts and the full Teams test configuration: 96 files and 1,530 tests passed under Node 24 with Vitest 4.1.11. The hosted job used the frozen-lockfile setup and exercised all four focused attachment test files. This closes the pinned hosted validation gap without altering the local shared install.
  • A separate published-head Codex review passed with no findings across the complete patch and 30 complete source/proof inputs. The exact head, tree, raw patch and source bytes were verified unchanged after the reviewer exited.
  • Latest ClawSweeper check before native preparation was its active review-started placeholder on this head; no completed findings or rank-up moves had been posted. There is no skipped actionable move to apply at this checkpoint.

Focused command:

node scripts/run-vitest.mjs extensions/msteams/src/attachments/shared.test.ts extensions/msteams/src/attachments.test.ts extensions/msteams/src/attachments.helpers.test.ts extensions/msteams/src/attachments/remote-media.test.ts

No separate full build was needed for this internal refactor: imports, lazy loading, package boundaries, and published surfaces are unchanged; ordinary CI's build-artifacts job passed. No live Teams tenant was exercised; no external API behavior is changed or claimed proven by these tests. Native preparation and merge verification remain required before landing.

AI-assisted; implementation and source contracts inspected.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: msteams Channel integration: msteams size: M maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 02:15
@steipete steipete self-assigned this Aug 27, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 26, 2026, 10:23 PM ET / August 27, 2026, 02:23 UTC.

ClawSweeper review

What this changes

This PR replaces Microsoft Teams’ local inline-base64 size estimator with Node’s byte-length calculation, simplifies dispatcher-mode redirect handling, and expands attachment tests.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: the refactor has one blocking test assertion that contradicts the configured authorization allowlist. The production redirect delegation is appropriately owned by the shared SSRF guard, but the focused test must be corrected before merge.

Priority: P3
Reviewed head: aed33f24fb9636994e3b56daa1657bb08db26141

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The cleanup has a sound owner-boundary direction, but its newly expanded focused test contains a deterministic contract mismatch.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: this is a maintainer-authored PR, so the external-contributor proof gate does not apply; the supplied focused tests remain supplemental validation.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: this is a maintainer-authored PR, so the external-contributor proof gate does not apply; the supplied focused tests remain supplemental validation.
Evidence reviewed 7 items Blocking test contradiction: The new dispatcher-mode case supplies an authorization allowlist containing the exact initial hostname, but asserts that the outbound request has no Authorization header.
Allowlist contract: Exact hostname entries are accepted by the suffix allowlist, and HTTPS URLs return that match result; teams.sharepoint.com therefore authorizes the header in the test setup.
Request behavior: The attachment owner removes Authorization only when the initial URL is outside the authorization allowlist, then sends the retained headers in dispatcher mode.
Findings 1 actionable finding [P2] Correct the dispatcher-mode authorization expectation
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

$ node scripts/run-node.mjs --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 77.89 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.5s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 10.9s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 3219ms (slowest: built plugin control-plane loads 2645ms)

OpenClaw 2026.8.1 (aed33f2) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console (silent|fatal|error|warn|info|debug|trace)
  --no-color           Disable ANSI colors
  --profile ‹name›     Use a named profile (isol
… output truncated …

Assertions:

  • PASS expect_output: Usage: openclaw

How this fits together

The Microsoft Teams plugin turns incoming attachment references into bounded local media. Its attachment fetch path applies Teams authorization rules, then delegates redirect and DNS-pinning enforcement to OpenClaw’s shared SSRF guard before saving media.

flowchart LR
  A[Teams attachment] --> B[Attachment downloader]
  B --> C[Teams auth fallback]
  C --> D[Attachment fetch policy]
  D --> E[Shared SSRF guard]
  E --> F[Redirect and DNS checks]
  F --> G[Saved media]
Loading

Before merge

  • Correct the dispatcher-mode authorization expectation (P2) - teams.sharepoint.com is explicitly in authorizationAllowHosts, so safeFetch retains the bearer token for this initial HTTPS request. The assertion for a null sent Authorization header therefore fails against the changed code; expect Bearer fixture-token instead.
  • Resolve merge risk (P1) - Direct Node Buffer contract inspection was unavailable locally because the checkout has no Node declaration source and network resolution failed; exact-head CI should remain the final validation after the test correction.

Findings

  • [P2] Correct the dispatcher-mode authorization expectation — extensions/msteams/src/attachments/shared.test.ts:222
Agent review details

Security

None.

PR surface

Source -52, Tests +59. Total +7 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 41 93 -52
Tests 2 136 77 +59
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 177 170 +7

Review metrics

Metric Value Why it matters
Production versus test delta production +41/-93 (net -52); tests +136/-77 (net +59) The production cleanup is net-negative; the test expansion is useful, but one newly added assertion currently conflicts with the authorization contract.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Update the dispatcher-mode test to expect the allowed bearer token, retain the production refactor, and rerun the focused attachment suite plus exact-head CI.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Update the dispatcher-mode test to expect the allowed bearer token, retain the production refactor, and rerun the focused attachment suite plus exact-head CI.

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

Yes—source inspection establishes that the focused dispatcher-mode test will observe the retained bearer token, contrary to its null-header assertion. The focused Vitest command in the PR body is the direct confirmation path, but was not run in this read-only review.

Is this the best way to solve the issue?

No: the test expectation is not the best validation because it asserts forbidden behavior for an allowlisted initial host. Expecting the configured bearer token preserves the intended authorization and redirect contract.

Full review comments:

  • [P2] Correct the dispatcher-mode authorization expectation — extensions/msteams/src/attachments/shared.test.ts:222
    teams.sharepoint.com is explicitly in authorizationAllowHosts, so safeFetch retains the bearer token for this initial HTTPS request. The assertion for a null sent Authorization header therefore fails against the changed code; expect Bearer fixture-token instead.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded internal cleanup with no intended user-visible behavior change; its blocker is a focused test correction.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable: this is a maintainer-authored PR, so the external-contributor proof gate does not apply; the supplied focused tests remain supplemental validation.

Label justifications:

  • P3: This is a bounded internal cleanup with no intended user-visible behavior change; its blocker is a focused test correction.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable: this is a maintainer-authored PR, so the external-contributor proof gate does not apply; the supplied focused tests remain supplemental validation.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/msteams/src/attachments/shared.test.ts extensions/msteams/src/attachments.test.ts.
  • [P1] Exact-head GitHub Actions CI.

What I checked:

Likely related people:

  • steipete: Recent main history includes multiple Microsoft Teams attachment refactors, and current-main blame attributes the surrounding dispatcher path to this contributor. (role: recent area contributor; confidence: high; commits: aed33f24fb96, a154b4faea41, 9497629c1e89; files: extensions/msteams/src/attachments/shared.ts, extensions/msteams/src/attachments/download.ts)
  • bmendonca3: History identifies this contributor as author of the dispatcher-redirect and authorization-scoping hardening that the refactor preserves. (role: introduced guarded redirect behavior; confidence: high; commits: c582a54554bd, cceecc8bd407, 4a414c5e5342; files: extensions/msteams/src/attachments/shared.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Change the dispatcher-mode expected Authorization value to the configured bearer token.
  • Run the focused attachment suite and wait for exact-head CI after the correction.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

@steipete
steipete merged commit 7408f96 into main Aug 27, 2026
180 checks passed
@steipete
steipete deleted the codex/cleanup20k-teams-attachment-owner-20260826 branch August 27, 2026 02:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

channel: msteams Channel integration: msteams maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant