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