@openclaw/msteams 2026.5.2 → 2026.5.3-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/api.js +3 -0
  2. package/dist/channel-D7hdreTh.js +984 -0
  3. package/dist/channel-config-api.js +2 -0
  4. package/dist/channel-plugin-api.js +2 -0
  5. package/dist/channel.runtime-BC1ruIfN.js +573 -0
  6. package/dist/config-schema-B8QezH6t.js +15 -0
  7. package/dist/contract-api.js +2 -0
  8. package/dist/graph-users-9uQJepqr.js +1354 -0
  9. package/dist/index.js +22 -0
  10. package/dist/oauth-BWJyilR1.js +114 -0
  11. package/dist/oauth.token-xxpoLWy5.js +115 -0
  12. package/dist/policy-DTnU2GR7.js +142 -0
  13. package/dist/probe-D_H8yFps.js +2194 -0
  14. package/dist/resolve-allowlist-D41JSziq.js +219 -0
  15. package/dist/runtime-api-DV1iVMn1.js +28 -0
  16. package/dist/runtime-api.js +2 -0
  17. package/dist/secret-contract-BuoEXmPS.js +35 -0
  18. package/dist/secret-contract-api.js +2 -0
  19. package/dist/setup-entry.js +15 -0
  20. package/dist/setup-plugin-api.js +64 -0
  21. package/dist/setup-surface-BLkFQYIQ.js +313 -0
  22. package/dist/src-CFp1QpFd.js +4064 -0
  23. package/dist/test-api.js +2 -0
  24. package/package.json +14 -6
  25. package/api.ts +0 -3
  26. package/channel-config-api.ts +0 -1
  27. package/channel-plugin-api.ts +0 -2
  28. package/config-api.ts +0 -4
  29. package/contract-api.ts +0 -4
  30. package/index.ts +0 -20
  31. package/runtime-api.ts +0 -73
  32. package/secret-contract-api.ts +0 -5
  33. package/setup-entry.ts +0 -13
  34. package/setup-plugin-api.ts +0 -3
  35. package/src/ai-entity.ts +0 -7
  36. package/src/approval-auth.ts +0 -44
  37. package/src/attachments/bot-framework.test.ts +0 -461
  38. package/src/attachments/bot-framework.ts +0 -362
  39. package/src/attachments/download.ts +0 -311
  40. package/src/attachments/graph.test.ts +0 -416
  41. package/src/attachments/graph.ts +0 -484
  42. package/src/attachments/html.ts +0 -122
  43. package/src/attachments/payload.ts +0 -14
  44. package/src/attachments/remote-media.test.ts +0 -137
  45. package/src/attachments/remote-media.ts +0 -112
  46. package/src/attachments/shared.test.ts +0 -530
  47. package/src/attachments/shared.ts +0 -626
  48. package/src/attachments/types.ts +0 -47
  49. package/src/attachments.graph.test.ts +0 -342
  50. package/src/attachments.helpers.test.ts +0 -246
  51. package/src/attachments.test-helpers.ts +0 -17
  52. package/src/attachments.test.ts +0 -687
  53. package/src/attachments.ts +0 -18
  54. package/src/block-streaming-config.test.ts +0 -61
  55. package/src/channel-api.ts +0 -1
  56. package/src/channel.actions.test.ts +0 -742
  57. package/src/channel.directory.test.ts +0 -200
  58. package/src/channel.runtime.ts +0 -56
  59. package/src/channel.setup.ts +0 -77
  60. package/src/channel.test.ts +0 -128
  61. package/src/channel.ts +0 -1136
  62. package/src/config-schema.ts +0 -6
  63. package/src/config-ui-hints.ts +0 -12
  64. package/src/conversation-store-fs.test.ts +0 -74
  65. package/src/conversation-store-fs.ts +0 -149
  66. package/src/conversation-store-helpers.test.ts +0 -202
  67. package/src/conversation-store-helpers.ts +0 -105
  68. package/src/conversation-store-memory.ts +0 -51
  69. package/src/conversation-store.shared.test.ts +0 -225
  70. package/src/conversation-store.ts +0 -71
  71. package/src/directory-live.test.ts +0 -156
  72. package/src/directory-live.ts +0 -111
  73. package/src/doctor.ts +0 -27
  74. package/src/errors.test.ts +0 -133
  75. package/src/errors.ts +0 -246
  76. package/src/feedback-reflection-prompt.ts +0 -117
  77. package/src/feedback-reflection-store.ts +0 -114
  78. package/src/feedback-reflection.test.ts +0 -237
  79. package/src/feedback-reflection.ts +0 -283
  80. package/src/file-consent-helpers.test.ts +0 -326
  81. package/src/file-consent-helpers.ts +0 -126
  82. package/src/file-consent-invoke.ts +0 -150
  83. package/src/file-consent.test.ts +0 -363
  84. package/src/file-consent.ts +0 -287
  85. package/src/graph-chat.ts +0 -55
  86. package/src/graph-group-management.test.ts +0 -318
  87. package/src/graph-group-management.ts +0 -168
  88. package/src/graph-members.test.ts +0 -89
  89. package/src/graph-members.ts +0 -48
  90. package/src/graph-messages.actions.test.ts +0 -243
  91. package/src/graph-messages.read.test.ts +0 -391
  92. package/src/graph-messages.search.test.ts +0 -213
  93. package/src/graph-messages.test-helpers.ts +0 -50
  94. package/src/graph-messages.ts +0 -534
  95. package/src/graph-teams.test.ts +0 -215
  96. package/src/graph-teams.ts +0 -114
  97. package/src/graph-thread.test.ts +0 -246
  98. package/src/graph-thread.ts +0 -146
  99. package/src/graph-upload.test.ts +0 -258
  100. package/src/graph-upload.ts +0 -531
  101. package/src/graph-users.ts +0 -29
  102. package/src/graph.test.ts +0 -516
  103. package/src/graph.ts +0 -293
  104. package/src/inbound.test.ts +0 -221
  105. package/src/inbound.ts +0 -148
  106. package/src/index.ts +0 -4
  107. package/src/media-helpers.test.ts +0 -202
  108. package/src/media-helpers.ts +0 -105
  109. package/src/mentions.test.ts +0 -244
  110. package/src/mentions.ts +0 -114
  111. package/src/messenger.test.ts +0 -865
  112. package/src/messenger.ts +0 -605
  113. package/src/monitor-handler/access.ts +0 -125
  114. package/src/monitor-handler/inbound-media.test.ts +0 -289
  115. package/src/monitor-handler/inbound-media.ts +0 -180
  116. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  117. package/src/monitor-handler/message-handler.authz.test.ts +0 -669
  118. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  119. package/src/monitor-handler/message-handler.test-support.ts +0 -100
  120. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
  121. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
  122. package/src/monitor-handler/message-handler.ts +0 -1000
  123. package/src/monitor-handler/reaction-handler.test.ts +0 -267
  124. package/src/monitor-handler/reaction-handler.ts +0 -210
  125. package/src/monitor-handler/thread-session.ts +0 -17
  126. package/src/monitor-handler.adaptive-card.test.ts +0 -162
  127. package/src/monitor-handler.feedback-authz.test.ts +0 -314
  128. package/src/monitor-handler.file-consent.test.ts +0 -423
  129. package/src/monitor-handler.sso.test.ts +0 -563
  130. package/src/monitor-handler.test-helpers.ts +0 -180
  131. package/src/monitor-handler.ts +0 -534
  132. package/src/monitor-handler.types.ts +0 -27
  133. package/src/monitor-types.ts +0 -6
  134. package/src/monitor.lifecycle.test.ts +0 -278
  135. package/src/monitor.test.ts +0 -119
  136. package/src/monitor.ts +0 -442
  137. package/src/oauth.flow.ts +0 -77
  138. package/src/oauth.shared.ts +0 -37
  139. package/src/oauth.test.ts +0 -305
  140. package/src/oauth.token.ts +0 -158
  141. package/src/oauth.ts +0 -130
  142. package/src/outbound.test.ts +0 -130
  143. package/src/outbound.ts +0 -71
  144. package/src/pending-uploads-fs.test.ts +0 -246
  145. package/src/pending-uploads-fs.ts +0 -235
  146. package/src/pending-uploads.test.ts +0 -173
  147. package/src/pending-uploads.ts +0 -121
  148. package/src/policy.test.ts +0 -240
  149. package/src/policy.ts +0 -262
  150. package/src/polls-store-memory.ts +0 -32
  151. package/src/polls.test.ts +0 -160
  152. package/src/polls.ts +0 -323
  153. package/src/presentation.ts +0 -68
  154. package/src/probe.test.ts +0 -77
  155. package/src/probe.ts +0 -132
  156. package/src/reply-dispatcher.test.ts +0 -437
  157. package/src/reply-dispatcher.ts +0 -346
  158. package/src/reply-stream-controller.test.ts +0 -235
  159. package/src/reply-stream-controller.ts +0 -147
  160. package/src/resolve-allowlist.test.ts +0 -250
  161. package/src/resolve-allowlist.ts +0 -309
  162. package/src/revoked-context.ts +0 -17
  163. package/src/runtime.ts +0 -9
  164. package/src/sdk-types.ts +0 -59
  165. package/src/sdk.test.ts +0 -666
  166. package/src/sdk.ts +0 -884
  167. package/src/secret-contract.ts +0 -49
  168. package/src/secret-input.ts +0 -7
  169. package/src/send-context.ts +0 -231
  170. package/src/send.test.ts +0 -493
  171. package/src/send.ts +0 -637
  172. package/src/sent-message-cache.test.ts +0 -15
  173. package/src/sent-message-cache.ts +0 -56
  174. package/src/session-route.ts +0 -40
  175. package/src/setup-core.ts +0 -160
  176. package/src/setup-surface.test.ts +0 -202
  177. package/src/setup-surface.ts +0 -320
  178. package/src/sso-token-store.test.ts +0 -72
  179. package/src/sso-token-store.ts +0 -166
  180. package/src/sso.ts +0 -300
  181. package/src/storage.ts +0 -25
  182. package/src/store-fs.ts +0 -44
  183. package/src/streaming-message.test.ts +0 -262
  184. package/src/streaming-message.ts +0 -297
  185. package/src/test-runtime.ts +0 -16
  186. package/src/thread-parent-context.test.ts +0 -224
  187. package/src/thread-parent-context.ts +0 -159
  188. package/src/token-response.ts +0 -11
  189. package/src/token.test.ts +0 -259
  190. package/src/token.ts +0 -195
  191. package/src/user-agent.test.ts +0 -86
  192. package/src/user-agent.ts +0 -53
  193. package/src/webhook-timeouts.ts +0 -27
  194. package/src/welcome-card.test.ts +0 -81
  195. package/src/welcome-card.ts +0 -57
  196. package/test-api.ts +0 -1
  197. package/tsconfig.json +0 -16
@@ -1,363 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import {
3
- CONSENT_UPLOAD_HOST_ALLOWLIST,
4
- isPrivateOrReservedIP,
5
- uploadToConsentUrl,
6
- validateConsentUploadUrl,
7
- } from "./file-consent.js";
8
-
9
- // Helper: a resolveFn that returns a public IP by default
10
- const publicResolve = async () => ({ address: "13.107.136.10" });
11
- // Helper: a resolveFn that returns a private IP
12
- const privateResolve = (ip: string) => async () => ({ address: ip });
13
- // Helper: a resolveFn that returns multiple addresses
14
- const multiResolve = (ips: string[]) => async () => ips.map((address) => ({ address }));
15
- // Helper: a resolveFn that fails
16
- const failingResolve = async () => {
17
- throw new Error("DNS failure");
18
- };
19
-
20
- // ─── isPrivateOrReservedIP ───────────────────────────────────────────────────
21
-
22
- describe("isPrivateOrReservedIP", () => {
23
- it.each([
24
- ["10.0.0.1", true],
25
- ["10.255.255.255", true],
26
- ["172.16.0.1", true],
27
- ["172.31.255.255", true],
28
- ["172.15.0.1", false],
29
- ["172.32.0.1", false],
30
- ["192.168.0.1", true],
31
- ["192.168.255.255", true],
32
- ["127.0.0.1", true],
33
- ["127.255.255.255", true],
34
- ["169.254.0.1", true],
35
- ["169.254.169.254", true],
36
- ["0.0.0.0", true],
37
- ["8.8.8.8", false],
38
- ["13.107.136.10", false],
39
- ["52.96.0.1", false],
40
- ] as const)("IPv4 %s → %s", (ip, expected) => {
41
- expect(isPrivateOrReservedIP(ip)).toBe(expected);
42
- });
43
-
44
- it.each([
45
- ["::1", true],
46
- ["::", true],
47
- ["fe80::1", true],
48
- ["fe80::", true],
49
- ["fc00::1", true],
50
- ["fd12:3456::1", true],
51
- ["2001:0db8::1", false],
52
- ["2620:1ec:c11::200", false],
53
- // IPv4-mapped IPv6 addresses
54
- ["::ffff:127.0.0.1", true],
55
- ["::ffff:10.0.0.1", true],
56
- ["::ffff:192.168.1.1", true],
57
- ["::ffff:169.254.169.254", true],
58
- ["::ffff:8.8.8.8", false],
59
- ["::ffff:13.107.136.10", false],
60
- ] as const)("IPv6 %s → %s", (ip, expected) => {
61
- expect(isPrivateOrReservedIP(ip)).toBe(expected);
62
- });
63
-
64
- it.each([
65
- ["999.999.999.999", false],
66
- ["256.0.0.1", false],
67
- ["10.0.0.256", false],
68
- ["-1.0.0.1", false],
69
- ["1.2.3.4.5", false],
70
- ] as const)("malformed IPv4 %s → %s", (ip, expected) => {
71
- expect(isPrivateOrReservedIP(ip)).toBe(expected);
72
- });
73
- });
74
-
75
- // ─── validateConsentUploadUrl ────────────────────────────────────────────────
76
-
77
- describe("validateConsentUploadUrl", () => {
78
- it("accepts a valid SharePoint HTTPS URL", async () => {
79
- await expect(
80
- validateConsentUploadUrl("https://contoso.sharepoint.com/sites/uploads/file.pdf", {
81
- resolveFn: publicResolve,
82
- }),
83
- ).resolves.toBeUndefined();
84
- });
85
-
86
- it("accepts subdomains of allowlisted domains", async () => {
87
- await expect(
88
- validateConsentUploadUrl(
89
- "https://contoso-my.sharepoint.com/personal/user/Documents/file.docx",
90
- { resolveFn: publicResolve },
91
- ),
92
- ).resolves.toBeUndefined();
93
- });
94
-
95
- it("accepts graph.microsoft.com", async () => {
96
- await expect(
97
- validateConsentUploadUrl("https://graph.microsoft.com/v1.0/me/drive/items/123/content", {
98
- resolveFn: publicResolve,
99
- }),
100
- ).resolves.toBeUndefined();
101
- });
102
-
103
- it("rejects non-HTTPS URLs", async () => {
104
- await expect(
105
- validateConsentUploadUrl("http://contoso.sharepoint.com/file.pdf", {
106
- resolveFn: publicResolve,
107
- }),
108
- ).rejects.toThrow("must use HTTPS");
109
- });
110
-
111
- it("rejects invalid URLs", async () => {
112
- await expect(
113
- validateConsentUploadUrl("not a url", { resolveFn: publicResolve }),
114
- ).rejects.toThrow("not a valid URL");
115
- });
116
-
117
- it("rejects hosts not in the allowlist", async () => {
118
- await expect(
119
- validateConsentUploadUrl("https://evil.example.com/exfil", { resolveFn: publicResolve }),
120
- ).rejects.toThrow("not in the allowed domains");
121
- });
122
-
123
- it("rejects an SSRF attempt with internal metadata URL", async () => {
124
- await expect(
125
- validateConsentUploadUrl("https://169.254.169.254/latest/meta-data/", {
126
- resolveFn: publicResolve,
127
- }),
128
- ).rejects.toThrow("not in the allowed domains");
129
- });
130
-
131
- it("rejects localhost", async () => {
132
- await expect(
133
- validateConsentUploadUrl("https://localhost:8080/internal", { resolveFn: publicResolve }),
134
- ).rejects.toThrow("not in the allowed domains");
135
- });
136
-
137
- it("rejects when DNS resolves to a private IPv4 (10.x)", async () => {
138
- await expect(
139
- validateConsentUploadUrl("https://malicious.sharepoint.com/exfil", {
140
- resolveFn: privateResolve("10.0.0.1"),
141
- }),
142
- ).rejects.toThrow("private/reserved IP");
143
- });
144
-
145
- it("rejects when DNS resolves to loopback", async () => {
146
- await expect(
147
- validateConsentUploadUrl("https://evil.sharepoint.com/path", {
148
- resolveFn: privateResolve("127.0.0.1"),
149
- }),
150
- ).rejects.toThrow("private/reserved IP");
151
- });
152
-
153
- it("rejects when DNS resolves to link-local (169.254.x.x)", async () => {
154
- await expect(
155
- validateConsentUploadUrl("https://evil.sharepoint.com/path", {
156
- resolveFn: privateResolve("169.254.169.254"),
157
- }),
158
- ).rejects.toThrow("private/reserved IP");
159
- });
160
-
161
- it("rejects when DNS resolves to IPv6 loopback", async () => {
162
- await expect(
163
- validateConsentUploadUrl("https://evil.sharepoint.com/path", {
164
- resolveFn: privateResolve("::1"),
165
- }),
166
- ).rejects.toThrow("private/reserved IP");
167
- });
168
-
169
- it("rejects when DNS resolves to IPv4-mapped IPv6 private address", async () => {
170
- await expect(
171
- validateConsentUploadUrl("https://evil.sharepoint.com/path", {
172
- resolveFn: privateResolve("::ffff:10.0.0.1"),
173
- }),
174
- ).rejects.toThrow("private/reserved IP");
175
- });
176
-
177
- it("rejects when DNS resolves to IPv4-mapped IPv6 loopback", async () => {
178
- await expect(
179
- validateConsentUploadUrl("https://evil.sharepoint.com/path", {
180
- resolveFn: privateResolve("::ffff:127.0.0.1"),
181
- }),
182
- ).rejects.toThrow("private/reserved IP");
183
- });
184
-
185
- it("rejects when any DNS answer is private/reserved", async () => {
186
- await expect(
187
- validateConsentUploadUrl("https://evil.sharepoint.com/path", {
188
- resolveFn: multiResolve(["13.107.136.10", "10.0.0.1"]),
189
- }),
190
- ).rejects.toThrow("private/reserved IP");
191
- });
192
-
193
- it("accepts when all DNS answers are public", async () => {
194
- await expect(
195
- validateConsentUploadUrl("https://evil.sharepoint.com/path", {
196
- resolveFn: multiResolve(["13.107.136.10", "52.96.0.1"]),
197
- }),
198
- ).resolves.toBeUndefined();
199
- });
200
-
201
- it("rejects when DNS resolution fails", async () => {
202
- await expect(
203
- validateConsentUploadUrl("https://nonexistent.sharepoint.com/path", {
204
- resolveFn: failingResolve,
205
- }),
206
- ).rejects.toThrow("Failed to resolve");
207
- });
208
-
209
- it("accepts a custom allowlist", async () => {
210
- await expect(
211
- validateConsentUploadUrl("https://custom.example.org/file", {
212
- allowlist: ["example.org"],
213
- resolveFn: publicResolve,
214
- }),
215
- ).resolves.toBeUndefined();
216
- });
217
-
218
- it("rejects hosts that are suffix-tricked (e.g. notsharepoint.com)", async () => {
219
- await expect(
220
- validateConsentUploadUrl("https://notsharepoint.com/file", { resolveFn: publicResolve }),
221
- ).rejects.toThrow("not in the allowed domains");
222
- });
223
-
224
- it("rejects file:// protocol", async () => {
225
- await expect(
226
- validateConsentUploadUrl("file:///etc/passwd", { resolveFn: publicResolve }),
227
- ).rejects.toThrow("must use HTTPS");
228
- });
229
- });
230
-
231
- // ─── CONSENT_UPLOAD_HOST_ALLOWLIST ───────────────────────────────────────────
232
-
233
- describe("CONSENT_UPLOAD_HOST_ALLOWLIST", () => {
234
- it("contains only Microsoft/SharePoint domains", () => {
235
- for (const domain of CONSENT_UPLOAD_HOST_ALLOWLIST) {
236
- expect(
237
- domain.includes("microsoft") ||
238
- domain.includes("sharepoint") ||
239
- domain.includes("onedrive") ||
240
- domain.includes("1drv") ||
241
- domain.includes("live.com"),
242
- ).toBe(true);
243
- }
244
- });
245
-
246
- it("does not contain overly broad domains", () => {
247
- const broad = [
248
- "microsoft.com",
249
- "azure.com",
250
- "blob.core.windows.net",
251
- "azureedge.net",
252
- "trafficmanager.net",
253
- ];
254
- for (const domain of broad) {
255
- expect(CONSENT_UPLOAD_HOST_ALLOWLIST).not.toContain(domain);
256
- }
257
- });
258
- });
259
-
260
- // ─── uploadToConsentUrl (integration with validation) ────────────────────────
261
-
262
- describe("uploadToConsentUrl", () => {
263
- it("sends the OpenClaw User-Agent header with consent uploads", async () => {
264
- const fetchFn = vi.fn(async () => new Response(null, { status: 200 }));
265
-
266
- await uploadToConsentUrl({
267
- url: "https://contoso.sharepoint.com/upload",
268
- buffer: Buffer.from("hello"),
269
- fetchFn,
270
- validationOpts: { resolveFn: publicResolve },
271
- });
272
-
273
- expect(fetchFn).toHaveBeenCalledWith(
274
- "https://contoso.sharepoint.com/upload",
275
- expect.objectContaining({
276
- method: "PUT",
277
- headers: expect.objectContaining({
278
- "Content-Range": "bytes 0-4/5",
279
- "Content-Type": "application/octet-stream",
280
- "User-Agent": expect.stringMatching(/^teams\.ts\[apps\]\/.+ OpenClaw\/.+$/),
281
- }),
282
- }),
283
- );
284
- });
285
-
286
- it("blocks upload to a disallowed host", async () => {
287
- const mockFetch = vi.fn();
288
- await expect(
289
- uploadToConsentUrl({
290
- url: "https://evil.example.com/exfil",
291
- buffer: Buffer.from("secret data"),
292
- fetchFn: mockFetch,
293
- validationOpts: { resolveFn: publicResolve },
294
- }),
295
- ).rejects.toThrow("not in the allowed domains");
296
-
297
- expect(mockFetch).not.toHaveBeenCalled();
298
- });
299
-
300
- it("blocks upload to a private IP", async () => {
301
- const mockFetch = vi.fn();
302
- await expect(
303
- uploadToConsentUrl({
304
- url: "https://compromised.sharepoint.com/upload",
305
- buffer: Buffer.from("data"),
306
- fetchFn: mockFetch,
307
- validationOpts: { resolveFn: privateResolve("10.0.0.1") },
308
- }),
309
- ).rejects.toThrow("private/reserved IP");
310
-
311
- expect(mockFetch).not.toHaveBeenCalled();
312
- });
313
-
314
- it("allows upload to a valid SharePoint URL and performs PUT", async () => {
315
- const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
316
- const buffer = Buffer.from("file content");
317
-
318
- await uploadToConsentUrl({
319
- url: "https://contoso.sharepoint.com/sites/uploads/file.pdf",
320
- buffer,
321
- contentType: "application/pdf",
322
- fetchFn: mockFetch,
323
- validationOpts: { resolveFn: publicResolve },
324
- });
325
-
326
- expect(mockFetch).toHaveBeenCalledOnce();
327
- const [url, opts] = mockFetch.mock.calls[0];
328
- expect(url).toBe("https://contoso.sharepoint.com/sites/uploads/file.pdf");
329
- expect(opts.method).toBe("PUT");
330
- expect(opts.headers["Content-Type"]).toBe("application/pdf");
331
- });
332
-
333
- it("throws on non-OK response after passing validation", async () => {
334
- const mockFetch = vi.fn().mockResolvedValue({
335
- ok: false,
336
- status: 403,
337
- statusText: "Forbidden",
338
- });
339
-
340
- await expect(
341
- uploadToConsentUrl({
342
- url: "https://contoso.sharepoint.com/sites/uploads/file.pdf",
343
- buffer: Buffer.from("data"),
344
- fetchFn: mockFetch,
345
- validationOpts: { resolveFn: publicResolve },
346
- }),
347
- ).rejects.toThrow("File upload to consent URL failed: 403 Forbidden");
348
- });
349
-
350
- it("blocks HTTP (non-HTTPS) upload before fetch is called", async () => {
351
- const mockFetch = vi.fn();
352
- await expect(
353
- uploadToConsentUrl({
354
- url: "http://contoso.sharepoint.com/upload",
355
- buffer: Buffer.from("data"),
356
- fetchFn: mockFetch,
357
- validationOpts: { resolveFn: publicResolve },
358
- }),
359
- ).rejects.toThrow("must use HTTPS");
360
-
361
- expect(mockFetch).not.toHaveBeenCalled();
362
- });
363
- });
@@ -1,287 +0,0 @@
1
- /**
2
- * FileConsentCard utilities for MS Teams large file uploads (>4MB) in personal chats.
3
- *
4
- * Teams requires user consent before the bot can upload large files. This module provides
5
- * utilities for:
6
- * - Building FileConsentCard attachments (to request upload permission)
7
- * - Building FileInfoCard attachments (to confirm upload completion)
8
- * - Parsing fileConsent/invoke activities
9
- */
10
-
11
- import { lookup } from "node:dns/promises";
12
- import { buildUserAgent } from "./user-agent.js";
13
-
14
- function normalizeLowercaseStringOrEmpty(value: unknown): string {
15
- return typeof value === "string" ? value.trim().toLowerCase() : "";
16
- }
17
-
18
- /**
19
- * Allowlist of domains that are valid targets for file consent uploads.
20
- * These are the Microsoft/SharePoint domains that Teams legitimately provides
21
- * as upload destinations in the FileConsentCard flow.
22
- */
23
- export const CONSENT_UPLOAD_HOST_ALLOWLIST = [
24
- "sharepoint.com",
25
- "sharepoint.us",
26
- "sharepoint.de",
27
- "sharepoint.cn",
28
- "sharepoint-df.com",
29
- "storage.live.com",
30
- "onedrive.com",
31
- "1drv.ms",
32
- "graph.microsoft.com",
33
- "graph.microsoft.us",
34
- "graph.microsoft.de",
35
- "graph.microsoft.cn",
36
- ] as const;
37
-
38
- /**
39
- * Returns true if the given IPv4 or IPv6 address is in a private, loopback,
40
- * or link-local range that must never be reached via consent uploads.
41
- */
42
- export function isPrivateOrReservedIP(ip: string): boolean {
43
- // Handle IPv4-mapped IPv6 first (e.g., ::ffff:127.0.0.1, ::ffff:10.0.0.1)
44
- const ipv4MappedMatch = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(ip);
45
- if (ipv4MappedMatch) {
46
- return isPrivateOrReservedIP(ipv4MappedMatch[1]);
47
- }
48
-
49
- // IPv4 checks
50
- const v4Parts = ip.split(".");
51
- if (v4Parts.length === 4) {
52
- const octets = v4Parts.map(Number);
53
- // Validate all octets are integers in 0-255
54
- if (octets.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) {
55
- return false;
56
- }
57
- const [a, b] = octets;
58
- // 10.0.0.0/8
59
- if (a === 10) {
60
- return true;
61
- }
62
- // 172.16.0.0/12
63
- if (a === 172 && b >= 16 && b <= 31) {
64
- return true;
65
- }
66
- // 192.168.0.0/16
67
- if (a === 192 && b === 168) {
68
- return true;
69
- }
70
- // 127.0.0.0/8 (loopback)
71
- if (a === 127) {
72
- return true;
73
- }
74
- // 169.254.0.0/16 (link-local)
75
- if (a === 169 && b === 254) {
76
- return true;
77
- }
78
- // 0.0.0.0/8
79
- if (a === 0) {
80
- return true;
81
- }
82
- }
83
-
84
- // IPv6 checks
85
- const normalized = normalizeLowercaseStringOrEmpty(ip);
86
- // ::1 loopback
87
- if (normalized === "::1") {
88
- return true;
89
- }
90
- // fe80::/10 link-local
91
- if (normalized.startsWith("fe80:") || normalized.startsWith("fe80")) {
92
- return true;
93
- }
94
- // fc00::/7 unique-local (fc00:: and fd00::)
95
- if (normalized.startsWith("fc") || normalized.startsWith("fd")) {
96
- return true;
97
- }
98
- // :: unspecified
99
- if (normalized === "::") {
100
- return true;
101
- }
102
-
103
- return false;
104
- }
105
-
106
- /**
107
- * Validate that a consent upload URL is safe to PUT to.
108
- * Checks:
109
- * 1. Protocol is HTTPS
110
- * 2. Hostname matches the consent upload allowlist
111
- * 3. Resolved IP is not in a private/reserved range (anti-SSRF)
112
- *
113
- * @throws Error if the URL fails validation
114
- */
115
- export async function validateConsentUploadUrl(
116
- url: string,
117
- opts?: {
118
- allowlist?: readonly string[];
119
- resolveFn?: (hostname: string) => Promise<{ address: string } | { address: string }[]>;
120
- },
121
- ): Promise<void> {
122
- let parsed: URL;
123
- try {
124
- parsed = new URL(url);
125
- } catch {
126
- throw new Error("Consent upload URL is not a valid URL");
127
- }
128
-
129
- // 1. Protocol check
130
- if (parsed.protocol !== "https:") {
131
- throw new Error(`Consent upload URL must use HTTPS, got ${parsed.protocol}`);
132
- }
133
-
134
- // 2. Hostname allowlist check
135
- const hostname = normalizeLowercaseStringOrEmpty(parsed.hostname);
136
- const allowlist = opts?.allowlist ?? CONSENT_UPLOAD_HOST_ALLOWLIST;
137
- const hostAllowed = allowlist.some(
138
- (entry) => hostname === entry || hostname.endsWith(`.${entry}`),
139
- );
140
- if (!hostAllowed) {
141
- throw new Error(`Consent upload URL hostname "${hostname}" is not in the allowed domains`);
142
- }
143
-
144
- // 3. DNS resolution — reject private/reserved IPs.
145
- // Check all resolved addresses to avoid SSRF bypass via mixed public/private answers.
146
- const resolveFn = opts?.resolveFn ?? ((name: string) => lookup(name, { all: true }));
147
- let resolved: { address: string }[];
148
- try {
149
- const result = await resolveFn(hostname);
150
- resolved = Array.isArray(result) ? result : [result];
151
- } catch {
152
- throw new Error(`Failed to resolve consent upload URL hostname "${hostname}"`);
153
- }
154
-
155
- for (const entry of resolved) {
156
- if (isPrivateOrReservedIP(entry.address)) {
157
- throw new Error(`Consent upload URL resolves to a private/reserved IP (${entry.address})`);
158
- }
159
- }
160
- }
161
-
162
- interface FileConsentCardParams {
163
- filename: string;
164
- description?: string;
165
- sizeInBytes: number;
166
- /** Custom context data to include in the card (passed back in the invoke) */
167
- context?: Record<string, unknown>;
168
- }
169
-
170
- interface FileInfoCardParams {
171
- filename: string;
172
- contentUrl: string;
173
- uniqueId: string;
174
- fileType: string;
175
- }
176
-
177
- /**
178
- * Build a FileConsentCard attachment for requesting upload permission.
179
- * Use this for files >= 4MB in personal (1:1) chats.
180
- */
181
- export function buildFileConsentCard(params: FileConsentCardParams) {
182
- return {
183
- contentType: "application/vnd.microsoft.teams.card.file.consent",
184
- name: params.filename,
185
- content: {
186
- description: params.description ?? `File: ${params.filename}`,
187
- sizeInBytes: params.sizeInBytes,
188
- acceptContext: { filename: params.filename, ...params.context },
189
- declineContext: { filename: params.filename, ...params.context },
190
- },
191
- };
192
- }
193
-
194
- /**
195
- * Build a FileInfoCard attachment for confirming upload completion.
196
- * Send this after successfully uploading the file to the consent URL.
197
- */
198
- export function buildFileInfoCard(params: FileInfoCardParams) {
199
- return {
200
- contentType: "application/vnd.microsoft.teams.card.file.info",
201
- contentUrl: params.contentUrl,
202
- name: params.filename,
203
- content: {
204
- uniqueId: params.uniqueId,
205
- fileType: params.fileType,
206
- },
207
- };
208
- }
209
-
210
- interface FileConsentUploadInfo {
211
- name: string;
212
- uploadUrl: string;
213
- contentUrl: string;
214
- uniqueId: string;
215
- fileType: string;
216
- }
217
-
218
- interface FileConsentResponse {
219
- action: "accept" | "decline";
220
- uploadInfo?: FileConsentUploadInfo;
221
- context?: Record<string, unknown>;
222
- }
223
-
224
- /**
225
- * Parse a fileConsent/invoke activity.
226
- * Returns null if the activity is not a file consent invoke.
227
- */
228
- export function parseFileConsentInvoke(activity: {
229
- name?: string;
230
- value?: unknown;
231
- }): FileConsentResponse | null {
232
- if (activity.name !== "fileConsent/invoke") {
233
- return null;
234
- }
235
-
236
- const value = activity.value as {
237
- type?: string;
238
- action?: string;
239
- uploadInfo?: FileConsentUploadInfo;
240
- context?: Record<string, unknown>;
241
- };
242
-
243
- if (value?.type !== "fileUpload") {
244
- return null;
245
- }
246
-
247
- return {
248
- action: value.action === "accept" ? "accept" : "decline",
249
- uploadInfo: value.uploadInfo,
250
- context: value.context,
251
- };
252
- }
253
-
254
- /**
255
- * Upload a file to the consent URL provided by Teams.
256
- * The URL is provided in the fileConsent/invoke response after user accepts.
257
- *
258
- * @throws Error if the URL fails SSRF validation (non-HTTPS, disallowed host, private IP)
259
- */
260
- export async function uploadToConsentUrl(params: {
261
- url: string;
262
- buffer: Buffer;
263
- contentType?: string;
264
- fetchFn?: typeof fetch;
265
- /** Override for testing — custom allowlist and DNS resolver */
266
- validationOpts?: {
267
- allowlist?: readonly string[];
268
- resolveFn?: (hostname: string) => Promise<{ address: string } | { address: string }[]>;
269
- };
270
- }): Promise<void> {
271
- await validateConsentUploadUrl(params.url, params.validationOpts);
272
-
273
- const fetchFn = params.fetchFn ?? fetch;
274
- const res = await fetchFn(params.url, {
275
- method: "PUT",
276
- headers: {
277
- "User-Agent": buildUserAgent(),
278
- "Content-Type": params.contentType ?? "application/octet-stream",
279
- "Content-Range": `bytes 0-${params.buffer.length - 1}/${params.buffer.length}`,
280
- },
281
- body: new Uint8Array(params.buffer),
282
- });
283
-
284
- if (!res.ok) {
285
- throw new Error(`File upload to consent URL failed: ${res.status} ${res.statusText}`);
286
- }
287
- }
package/src/graph-chat.ts DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * Native Teams file card attachments for Bot Framework.
3
- *
4
- * The Bot Framework SDK supports `application/vnd.microsoft.teams.card.file.info`
5
- * content type which produces native Teams file cards.
6
- *
7
- * @see https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bots-filesv4
8
- */
9
-
10
- /**
11
- * Build a native Teams file card attachment for Bot Framework.
12
- *
13
- * This uses the `application/vnd.microsoft.teams.card.file.info` content type
14
- * which is supported by Bot Framework and produces native Teams file cards
15
- * (the same display as when a user manually shares a file).
16
- *
17
- * @param file - DriveItem properties from getDriveItemProperties()
18
- * @returns Attachment object for Bot Framework sendActivity()
19
- */
20
- import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
21
- import type { DriveItemProperties } from "./graph-upload.js";
22
-
23
- export function buildTeamsFileInfoCard(file: DriveItemProperties): {
24
- contentType: string;
25
- contentUrl: string;
26
- name: string;
27
- content: {
28
- uniqueId: string;
29
- fileType: string;
30
- };
31
- } {
32
- // Extract unique ID from eTag (remove quotes, braces, and version suffix)
33
- // Example eTag formats: "{GUID},version" or "\"{GUID},version\""
34
- const rawETag = file.eTag;
35
- const uniqueId =
36
- rawETag
37
- .replace(/^["']|["']$/g, "") // Remove outer quotes
38
- .replace(/[{}]/g, "") // Remove curly braces
39
- .split(",")[0] ?? rawETag; // Take the GUID part before comma
40
-
41
- // Extract file extension from filename
42
- const lastDot = file.name.lastIndexOf(".");
43
- const fileType =
44
- lastDot >= 0 ? normalizeLowercaseStringOrEmpty(file.name.slice(lastDot + 1)) : "";
45
-
46
- return {
47
- contentType: "application/vnd.microsoft.teams.card.file.info",
48
- contentUrl: file.webDavUrl,
49
- name: file.name,
50
- content: {
51
- uniqueId,
52
- fileType,
53
- },
54
- };
55
- }