Repository navigation
fix(msteams): require dot boundary for shared-link host suffix match - #123046
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 22, 2026, 9:40 PM ET / August 23, 2026, 01:40 UTC. ClawSweeper reviewWhat this changesThe PR makes Microsoft Teams shared-link detection require HTTPS and a DNS-label boundary before routing an attachment through authenticated Microsoft Graph downloads. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open for normal merge handling. Current main still uses the unsafe raw suffix check; the PR’s HTTPS and label-boundary predicate is the narrow compatible repair, and the prior matcher/proof blockers are addressed. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherMicrosoft Teams attachment handling classifies OneDrive and SharePoint URLs before choosing the authenticated Microsoft Graph shares endpoint or ordinary attachment handling. This predicate controls whether Graph token acquisition and Graph I/O can be reached. flowchart LR
A[Teams attachment URL] --> B[URL parsing]
B --> C[HTTPS and host-boundary check]
C -->|trusted shared link| D[Graph shares route]
C -->|not a shared link| E[Attachment policy]
D --> F[Graph token and download]
E --> G[Normal attachment result]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +4, Tests +34. Total +38 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the local parse-once predicate, merge it through normal exact-head gates, and preserve its tests for both trusted shared links and suffix-sharing look-alikes. Do we have a high-confidence way to reproduce the issue? Yes. Current main's raw suffix predicate accepts the named look-alike hosts, while the exact-head classifier and downloader tests cover their rejection before Graph routing. Is this the best way to solve the issue? Yes. The local predicate is the narrowest maintainable fix because the shared hostname helper would erase the meaningful dotted SharePoint distinction and alter apex-host behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2f3f54004586. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
|
Update: I removed the maintainer refactor after hosted review identified that it changed SharePoint apex-host routing. The branch is back to the contributor's original narrow boundary fix at |
d29aebe to
6c6a963
Compare
6c6a963 to
629ccfa
Compare
Look-alike hosts such as evil1drv.ms, notonedrive.com, or fakeonedrive.live.com satisfied the bare endsWith() check in isGraphSharedLinkUrl and were rewritten to the Graph shares endpoint. Match bare suffixes on a label boundary instead: exact host or a dot-prefixed suffix.
629ccfa to
5f6c0f0
Compare
|
Maintainer decision: declining the P2 canonical-matcher change.
|
|
Maintainer landing review complete for exact head
No live Microsoft tenant call was made because the changed deterministic boundary must reject before external I/O; the exact-head production-downloader traces cover that final effect directly. ClawSweeper now reports proof sufficient and no findings. Proceeding through the native exact-merge gates. |
|
Merged via squash.
|
…penclaw#123046) * fix(msteams): require dot boundary for shared-link host suffix match Look-alike hosts such as evil1drv.ms, notonedrive.com, or fakeonedrive.live.com satisfied the bare endsWith() check in isGraphSharedLinkUrl and were rewritten to the Graph shares endpoint. Match bare suffixes on a label boundary instead: exact host or a dot-prefixed suffix. * test(msteams): cover lookalike download routing * fix(msteams): require https for shared links --------- Co-authored-by: sallyom <[email protected]>
…) -> upstream tip
Summary
fix(msteams): require a dot boundary when matching OneDrive/SharePoint shared-link host suffixes, so look-alike hosts like
evil1drv.msornotonedrive.comare no longer rewritten to the Graph shares endpointWhat Problem This Solves
When an MSTeams attachment URL points at a OneDrive/SharePoint shared link, the downloader rewrites it to the Graph
/shares/{shareId}/driveItem/contentendpoint instead of fetching it directly. The classifier decides this by matching the URL host against a suffix list (1drv.ms,onedrive.com,onedrive.live.com,.sharepoint.com, ...).代码证据: in
extensions/msteams/src/attachments/shared.ts,isGraphSharedLinkUrlused:For the bare (non-dot-prefixed) suffixes this has no label boundary:
evil1drv.ms.endsWith(1drv.ms) andnotonedrive.com.endsWith(onedrive.com) are bothtrue.The impact is not just misclassification:
tryBuildGraphSharesUrlForSharedLinkbase64url-encodes the attacker-controlled URL into a Graph/shares/API path, so a look-alike host gets its content fetched through the Graph shares flow (with Graph credentials attached) instead of being treated as an ordinary external download.Trigger condition: any attachment URL whose host ends with the literal string
1drv.ms,onedrive.com, oronedrive.live.comwithout being those hosts or their subdomains.Root Cause
.sharepoint.com, which carry their own boundary) with bare entries (1drv.ms,onedrive.com,onedrive.live.com, which do not), and the matcher treated both forms identically.Why This Fix
host === suffix || host.endsWith(suffix). Works, but loses the exact-host matches for1drv.ms/onedrive.comapex hosts unless extra entries are added.host === suffix || host.endsWith(suffix.startsWith(".") ? suffix : "." + suffix). Bare suffixes now require a dot boundary for subdomain matches while exact matches still pass; dot-prefixed entries behave exactly as before.*.sharepoint.cometc.) is intentionally open-ended.User Impact
https://notonedrive.com/x,https://evil1drv.ms/x,https://fakeonedrive.live.com/x).https://graph.microsoft.com/v1.0/shares/u!<base64url(attacker-url)>/driveItem/content.https://1drv.ms/b/s!...,https://onedrive.live.com/view.aspx?...,https://contoso.sharepoint.com/...) are unaffected.Evidence
wt-msteams-attachment-host-boundaryon latestorigin/main, running the real exportedtryBuildGraphSharesUrlForSharedLinkfromextensions/msteams/src/attachments/shared.tsvia tsx. No mocks: this is a pure URL-classification function.Before (on main, same script, exit code 1):
Real Behavior Proof
Maintainer validation ran the real production
downloadMSTeamsAttachmentspath at exact head5f6c0f00bde747f8b459f4cdb403f294ba81da3ein fresh sanitized AWS Crabbox leases. Both used--no-hydrate; the trusted bootstrap verified no instance-role credentials, and each lease had public networking with no Tailscale. Fail-fast sentinels covered injected/global fetch, Graph request, DNS resolution, and token-provider boundaries.HTTP trusted-host rejection (run
run_8ab7c935e8e7):{"head":"5f6c0f00bde747f8b459f4cdb403f294ba81da3e","input":"http://onedrive.com/direct.pdf","networkRequests":0,"graphRequests":0,"dnsResolutions":0,"tokenRequests":0,"media":[{"kind":"document","hasPath":false}],"result":"rejected-before-io"}HTTPS look-alike rejection under the real default attachment policy, with no allowlist overrides (run
run_b2af35a5d7ab):{"head":"5f6c0f00bde747f8b459f4cdb403f294ba81da3e","policy":"default","input":"https://notonedrive.com/direct.pdf","networkRequests":0,"graphRequests":0,"dnsResolutions":0,"tokenRequests":0,"media":[{"kind":"document","hasPath":false}],"result":"rejected-before-io"}Both commands exited 0 with empty stderr, proving the forbidden inputs stop before Graph dispatch, DNS/network I/O, or token acquisition.
Tests and Validation
npx vitest run extensions/msteams/src/attachments/shared.test.ts— 56/56 passed, including new regression cases in theisGraphSharedLinkUrlmatrix:notonedrive.com,evil1drv.ms,fakeonedrive.live.com, andevilsharepoint.comall classify as non-shared-link.npx oxlint --deny=warnon both changed files — 0 warnings, 0 errors.Regression Test Plan
it.eachmatrix in the test file).extensions/msteams/src/attachments/shared.test.ts