@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.
- package/dist/api.js +3 -0
- package/dist/channel-D7hdreTh.js +984 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BC1ruIfN.js +573 -0
- package/dist/config-schema-B8QezH6t.js +15 -0
- package/dist/contract-api.js +2 -0
- package/dist/graph-users-9uQJepqr.js +1354 -0
- package/dist/index.js +22 -0
- package/dist/oauth-BWJyilR1.js +114 -0
- package/dist/oauth.token-xxpoLWy5.js +115 -0
- package/dist/policy-DTnU2GR7.js +142 -0
- package/dist/probe-D_H8yFps.js +2194 -0
- package/dist/resolve-allowlist-D41JSziq.js +219 -0
- package/dist/runtime-api-DV1iVMn1.js +28 -0
- package/dist/runtime-api.js +2 -0
- package/dist/secret-contract-BuoEXmPS.js +35 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-plugin-api.js +64 -0
- package/dist/setup-surface-BLkFQYIQ.js +313 -0
- package/dist/src-CFp1QpFd.js +4064 -0
- package/dist/test-api.js +2 -0
- package/package.json +14 -6
- 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 -73
- 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 -461
- package/src/attachments/bot-framework.ts +0 -362
- package/src/attachments/download.ts +0 -311
- package/src/attachments/graph.test.ts +0 -416
- package/src/attachments/graph.ts +0 -484
- package/src/attachments/html.ts +0 -122
- package/src/attachments/payload.ts +0 -14
- package/src/attachments/remote-media.test.ts +0 -137
- package/src/attachments/remote-media.ts +0 -112
- package/src/attachments/shared.test.ts +0 -530
- package/src/attachments/shared.ts +0 -626
- package/src/attachments/types.ts +0 -47
- package/src/attachments.graph.test.ts +0 -342
- package/src/attachments.helpers.test.ts +0 -246
- package/src/attachments.test-helpers.ts +0 -17
- package/src/attachments.test.ts +0 -687
- 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 -742
- package/src/channel.directory.test.ts +0 -200
- package/src/channel.runtime.ts +0 -56
- package/src/channel.setup.ts +0 -77
- package/src/channel.test.ts +0 -128
- package/src/channel.ts +0 -1136
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -12
- package/src/conversation-store-fs.test.ts +0 -74
- 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 -225
- 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 -133
- package/src/errors.ts +0 -246
- package/src/feedback-reflection-prompt.ts +0 -117
- package/src/feedback-reflection-store.ts +0 -114
- package/src/feedback-reflection.test.ts +0 -237
- package/src/feedback-reflection.ts +0 -283
- package/src/file-consent-helpers.test.ts +0 -326
- package/src/file-consent-helpers.ts +0 -126
- package/src/file-consent-invoke.ts +0 -150
- package/src/file-consent.test.ts +0 -363
- package/src/file-consent.ts +0 -287
- package/src/graph-chat.ts +0 -55
- package/src/graph-group-management.test.ts +0 -318
- 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 -243
- package/src/graph-messages.read.test.ts +0 -391
- package/src/graph-messages.search.test.ts +0 -213
- package/src/graph-messages.test-helpers.ts +0 -50
- package/src/graph-messages.ts +0 -534
- package/src/graph-teams.test.ts +0 -215
- package/src/graph-teams.ts +0 -114
- package/src/graph-thread.test.ts +0 -246
- package/src/graph-thread.ts +0 -146
- package/src/graph-upload.test.ts +0 -258
- package/src/graph-upload.ts +0 -531
- package/src/graph-users.ts +0 -29
- package/src/graph.test.ts +0 -516
- package/src/graph.ts +0 -293
- 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 -202
- package/src/media-helpers.ts +0 -105
- package/src/mentions.test.ts +0 -244
- package/src/mentions.ts +0 -114
- package/src/messenger.test.ts +0 -865
- package/src/messenger.ts +0 -605
- package/src/monitor-handler/access.ts +0 -125
- package/src/monitor-handler/inbound-media.test.ts +0 -289
- 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 -669
- package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
- package/src/monitor-handler/message-handler.test-support.ts +0 -100
- package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
- package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
- package/src/monitor-handler/message-handler.ts +0 -1000
- package/src/monitor-handler/reaction-handler.test.ts +0 -267
- package/src/monitor-handler/reaction-handler.ts +0 -210
- package/src/monitor-handler/thread-session.ts +0 -17
- package/src/monitor-handler.adaptive-card.test.ts +0 -162
- package/src/monitor-handler.feedback-authz.test.ts +0 -314
- package/src/monitor-handler.file-consent.test.ts +0 -423
- package/src/monitor-handler.sso.test.ts +0 -563
- package/src/monitor-handler.test-helpers.ts +0 -180
- package/src/monitor-handler.ts +0 -534
- package/src/monitor-handler.types.ts +0 -27
- package/src/monitor-types.ts +0 -6
- package/src/monitor.lifecycle.test.ts +0 -278
- package/src/monitor.test.ts +0 -119
- package/src/monitor.ts +0 -442
- package/src/oauth.flow.ts +0 -77
- package/src/oauth.shared.ts +0 -37
- package/src/oauth.test.ts +0 -305
- package/src/oauth.token.ts +0 -158
- package/src/oauth.ts +0 -130
- package/src/outbound.test.ts +0 -130
- package/src/outbound.ts +0 -71
- package/src/pending-uploads-fs.test.ts +0 -246
- package/src/pending-uploads-fs.ts +0 -235
- package/src/pending-uploads.test.ts +0 -173
- package/src/pending-uploads.ts +0 -121
- package/src/policy.test.ts +0 -240
- package/src/policy.ts +0 -262
- package/src/polls-store-memory.ts +0 -32
- package/src/polls.test.ts +0 -160
- package/src/polls.ts +0 -323
- package/src/presentation.ts +0 -68
- package/src/probe.test.ts +0 -77
- package/src/probe.ts +0 -132
- package/src/reply-dispatcher.test.ts +0 -437
- package/src/reply-dispatcher.ts +0 -346
- package/src/reply-stream-controller.test.ts +0 -235
- package/src/reply-stream-controller.ts +0 -147
- package/src/resolve-allowlist.test.ts +0 -250
- package/src/resolve-allowlist.ts +0 -309
- package/src/revoked-context.ts +0 -17
- package/src/runtime.ts +0 -9
- package/src/sdk-types.ts +0 -59
- package/src/sdk.test.ts +0 -666
- package/src/sdk.ts +0 -884
- package/src/secret-contract.ts +0 -49
- package/src/secret-input.ts +0 -7
- package/src/send-context.ts +0 -231
- package/src/send.test.ts +0 -493
- package/src/send.ts +0 -637
- package/src/sent-message-cache.test.ts +0 -15
- package/src/sent-message-cache.ts +0 -56
- package/src/session-route.ts +0 -40
- package/src/setup-core.ts +0 -160
- package/src/setup-surface.test.ts +0 -202
- package/src/setup-surface.ts +0 -320
- package/src/sso-token-store.test.ts +0 -72
- 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 -44
- package/src/streaming-message.test.ts +0 -262
- package/src/streaming-message.ts +0 -297
- 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 -259
- package/src/token.ts +0 -195
- package/src/user-agent.test.ts +0 -86
- package/src/user-agent.ts +0 -53
- package/src/webhook-timeouts.ts +0 -27
- package/src/welcome-card.test.ts +0 -81
- package/src/welcome-card.ts +0 -57
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
|
@@ -1,530 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
applyAuthorizationHeaderForUrl,
|
|
4
|
-
encodeGraphShareId,
|
|
5
|
-
extractInlineImageCandidates,
|
|
6
|
-
isGraphSharedLinkUrl,
|
|
7
|
-
isPrivateOrReservedIP,
|
|
8
|
-
isUrlAllowed,
|
|
9
|
-
resolveAndValidateIP,
|
|
10
|
-
resolveAttachmentFetchPolicy,
|
|
11
|
-
resolveAllowedHosts,
|
|
12
|
-
resolveAuthAllowedHosts,
|
|
13
|
-
resolveMediaSsrfPolicy,
|
|
14
|
-
safeFetch,
|
|
15
|
-
safeFetchWithPolicy,
|
|
16
|
-
tryBuildGraphSharesUrlForSharedLink,
|
|
17
|
-
} from "./shared.js";
|
|
18
|
-
|
|
19
|
-
const publicResolve = async () => ({ address: "13.107.136.10" });
|
|
20
|
-
const privateResolve = (ip: string) => async () => ({ address: ip });
|
|
21
|
-
const failingResolve = async () => {
|
|
22
|
-
throw new Error("DNS failure");
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function mockFetchWithRedirect(redirectMap: Record<string, string>, finalBody = "ok") {
|
|
26
|
-
return vi.fn(async (url: string, init?: RequestInit) => {
|
|
27
|
-
const target = redirectMap[url];
|
|
28
|
-
if (target && init?.redirect === "manual") {
|
|
29
|
-
return new Response(null, {
|
|
30
|
-
status: 302,
|
|
31
|
-
headers: { location: target },
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return new Response(finalBody, { status: 200 });
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function expectSafeFetchStatus(params: {
|
|
39
|
-
fetchMock: ReturnType<typeof vi.fn>;
|
|
40
|
-
url: string;
|
|
41
|
-
allowHosts: string[];
|
|
42
|
-
expectedStatus: number;
|
|
43
|
-
resolveFn?: typeof publicResolve;
|
|
44
|
-
}) {
|
|
45
|
-
const res = await safeFetch({
|
|
46
|
-
url: params.url,
|
|
47
|
-
allowHosts: params.allowHosts,
|
|
48
|
-
fetchFn: params.fetchMock as unknown as typeof fetch,
|
|
49
|
-
resolveFn: params.resolveFn ?? publicResolve,
|
|
50
|
-
});
|
|
51
|
-
expect(res.status).toBe(params.expectedStatus);
|
|
52
|
-
return res;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
describe("msteams attachment allowlists", () => {
|
|
56
|
-
it("normalizes wildcard host lists", () => {
|
|
57
|
-
expect(resolveAllowedHosts(["*", "graph.microsoft.com"])).toEqual(["*"]);
|
|
58
|
-
expect(resolveAuthAllowedHosts(["*", "graph.microsoft.com"])).toEqual(["*"]);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("resolves a normalized attachment fetch policy", () => {
|
|
62
|
-
expect(
|
|
63
|
-
resolveAttachmentFetchPolicy({
|
|
64
|
-
allowHosts: ["sharepoint.com"],
|
|
65
|
-
authAllowHosts: ["graph.microsoft.com"],
|
|
66
|
-
}),
|
|
67
|
-
).toEqual({
|
|
68
|
-
allowHosts: ["sharepoint.com"],
|
|
69
|
-
authAllowHosts: ["graph.microsoft.com"],
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("requires https and host suffix match", () => {
|
|
74
|
-
const allowHosts = resolveAllowedHosts(["sharepoint.com"]);
|
|
75
|
-
expect(isUrlAllowed("https://contoso.sharepoint.com/file.png", allowHosts)).toBe(true);
|
|
76
|
-
expect(isUrlAllowed("http://contoso.sharepoint.com/file.png", allowHosts)).toBe(false);
|
|
77
|
-
expect(isUrlAllowed("https://evil.example.com/file.png", allowHosts)).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("builds shared SSRF policy from suffix allowlist", () => {
|
|
81
|
-
expect(resolveMediaSsrfPolicy(["sharepoint.com"])).toEqual({
|
|
82
|
-
hostnameAllowlist: ["sharepoint.com", "*.sharepoint.com"],
|
|
83
|
-
});
|
|
84
|
-
expect(resolveMediaSsrfPolicy(["*"])).toBeUndefined();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it.each([
|
|
88
|
-
["999.999.999.999", true],
|
|
89
|
-
["256.0.0.1", true],
|
|
90
|
-
["10.0.0.256", true],
|
|
91
|
-
["-1.0.0.1", false],
|
|
92
|
-
["1.2.3.4.5", false],
|
|
93
|
-
["0:0:0:0:0:0:0:1", true],
|
|
94
|
-
] as const)("malformed/expanded %s → %s (SDK fails closed)", (ip, expected) => {
|
|
95
|
-
expect(isPrivateOrReservedIP(ip)).toBe(expected);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// ─── resolveAndValidateIP ────────────────────────────────────────────────────
|
|
100
|
-
|
|
101
|
-
describe("resolveAndValidateIP", () => {
|
|
102
|
-
it("accepts a hostname resolving to a public IP", async () => {
|
|
103
|
-
const ip = await resolveAndValidateIP("teams.sharepoint.com", publicResolve);
|
|
104
|
-
expect(ip).toBe("13.107.136.10");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("rejects a hostname resolving to 10.x.x.x", async () => {
|
|
108
|
-
await expect(resolveAndValidateIP("evil.test", privateResolve("10.0.0.1"))).rejects.toThrow(
|
|
109
|
-
"private/reserved IP",
|
|
110
|
-
);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("rejects a hostname resolving to 169.254.169.254", async () => {
|
|
114
|
-
await expect(
|
|
115
|
-
resolveAndValidateIP("evil.test", privateResolve("169.254.169.254")),
|
|
116
|
-
).rejects.toThrow("private/reserved IP");
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("rejects a hostname resolving to loopback", async () => {
|
|
120
|
-
await expect(resolveAndValidateIP("evil.test", privateResolve("127.0.0.1"))).rejects.toThrow(
|
|
121
|
-
"private/reserved IP",
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("rejects a hostname resolving to IPv6 loopback", async () => {
|
|
126
|
-
await expect(resolveAndValidateIP("evil.test", privateResolve("::1"))).rejects.toThrow(
|
|
127
|
-
"private/reserved IP",
|
|
128
|
-
);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("throws on DNS resolution failure", async () => {
|
|
132
|
-
await expect(resolveAndValidateIP("nonexistent.test", failingResolve)).rejects.toThrow(
|
|
133
|
-
"DNS resolution failed",
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// ─── safeFetch ───────────────────────────────────────────────────────────────
|
|
139
|
-
|
|
140
|
-
describe("safeFetch", () => {
|
|
141
|
-
it("fetches a URL directly when no redirect occurs", async () => {
|
|
142
|
-
const fetchMock = vi.fn(async (_url: string, _init?: RequestInit) => {
|
|
143
|
-
return new Response("ok", { status: 200 });
|
|
144
|
-
});
|
|
145
|
-
await expectSafeFetchStatus({
|
|
146
|
-
fetchMock,
|
|
147
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
148
|
-
allowHosts: ["sharepoint.com"],
|
|
149
|
-
expectedStatus: 200,
|
|
150
|
-
});
|
|
151
|
-
expect(fetchMock).toHaveBeenCalledOnce();
|
|
152
|
-
// Should have used redirect: "manual"
|
|
153
|
-
expect(fetchMock.mock.calls[0][1]).toHaveProperty("redirect", "manual");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("follows a redirect to an allowlisted host with public IP", async () => {
|
|
157
|
-
const fetchMock = mockFetchWithRedirect({
|
|
158
|
-
"https://teams.sharepoint.com/file.pdf": "https://cdn.sharepoint.com/storage/file.pdf",
|
|
159
|
-
});
|
|
160
|
-
await expectSafeFetchStatus({
|
|
161
|
-
fetchMock,
|
|
162
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
163
|
-
allowHosts: ["sharepoint.com"],
|
|
164
|
-
expectedStatus: 200,
|
|
165
|
-
});
|
|
166
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("returns the redirect response when dispatcher is provided by an outer guard", async () => {
|
|
170
|
-
const redirectedTo = "https://cdn.sharepoint.com/storage/file.pdf";
|
|
171
|
-
const fetchMock = mockFetchWithRedirect({
|
|
172
|
-
"https://teams.sharepoint.com/file.pdf": redirectedTo,
|
|
173
|
-
});
|
|
174
|
-
const res = await safeFetch({
|
|
175
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
176
|
-
allowHosts: ["sharepoint.com"],
|
|
177
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
178
|
-
requestInit: { dispatcher: {} } as RequestInit,
|
|
179
|
-
resolveFn: publicResolve,
|
|
180
|
-
});
|
|
181
|
-
expect(res.status).toBe(302);
|
|
182
|
-
expect(res.headers.get("location")).toBe(redirectedTo);
|
|
183
|
-
expect(fetchMock).toHaveBeenCalledOnce();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("still enforces allowlist checks before returning dispatcher-mode redirects", async () => {
|
|
187
|
-
const fetchMock = mockFetchWithRedirect({
|
|
188
|
-
"https://teams.sharepoint.com/file.pdf": "https://evil.example.com/steal",
|
|
189
|
-
});
|
|
190
|
-
await expect(
|
|
191
|
-
safeFetch({
|
|
192
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
193
|
-
allowHosts: ["sharepoint.com"],
|
|
194
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
195
|
-
requestInit: { dispatcher: {} } as RequestInit,
|
|
196
|
-
resolveFn: publicResolve,
|
|
197
|
-
}),
|
|
198
|
-
).rejects.toThrow("blocked by allowlist");
|
|
199
|
-
expect(fetchMock).toHaveBeenCalledOnce();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("blocks a redirect to a non-allowlisted host", async () => {
|
|
203
|
-
const fetchMock = mockFetchWithRedirect({
|
|
204
|
-
"https://teams.sharepoint.com/file.pdf": "https://evil.example.com/steal",
|
|
205
|
-
});
|
|
206
|
-
await expect(
|
|
207
|
-
safeFetch({
|
|
208
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
209
|
-
allowHosts: ["sharepoint.com"],
|
|
210
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
211
|
-
resolveFn: publicResolve,
|
|
212
|
-
}),
|
|
213
|
-
).rejects.toThrow("blocked by allowlist");
|
|
214
|
-
// Should not have fetched the evil URL
|
|
215
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("blocks a redirect to an allowlisted host that resolves to a private IP (DNS rebinding)", async () => {
|
|
219
|
-
let callCount = 0;
|
|
220
|
-
const rebindingResolve = async () => {
|
|
221
|
-
callCount++;
|
|
222
|
-
// First call (initial URL) resolves to public IP
|
|
223
|
-
if (callCount === 1) {
|
|
224
|
-
return { address: "13.107.136.10" };
|
|
225
|
-
}
|
|
226
|
-
// Second call (redirect target) resolves to private IP
|
|
227
|
-
return { address: "169.254.169.254" };
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const fetchMock = mockFetchWithRedirect({
|
|
231
|
-
"https://teams.sharepoint.com/file.pdf": "https://evil.trafficmanager.net/metadata",
|
|
232
|
-
});
|
|
233
|
-
await expect(
|
|
234
|
-
safeFetch({
|
|
235
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
236
|
-
allowHosts: ["sharepoint.com", "trafficmanager.net"],
|
|
237
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
238
|
-
resolveFn: rebindingResolve,
|
|
239
|
-
}),
|
|
240
|
-
).rejects.toThrow("private/reserved IP");
|
|
241
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("blocks when the initial URL resolves to a private IP", async () => {
|
|
245
|
-
const fetchMock = vi.fn();
|
|
246
|
-
await expect(
|
|
247
|
-
safeFetch({
|
|
248
|
-
url: "https://evil.sharepoint.com/file.pdf",
|
|
249
|
-
allowHosts: ["sharepoint.com"],
|
|
250
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
251
|
-
resolveFn: privateResolve("10.0.0.1"),
|
|
252
|
-
}),
|
|
253
|
-
).rejects.toThrow("Initial download URL blocked");
|
|
254
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("blocks private hosts with the default resolver", async () => {
|
|
258
|
-
const fetchMock = vi.fn();
|
|
259
|
-
await expect(
|
|
260
|
-
safeFetch({
|
|
261
|
-
url: "https://localhost/file.pdf",
|
|
262
|
-
allowHosts: ["localhost"],
|
|
263
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
264
|
-
}),
|
|
265
|
-
).rejects.toThrow("Initial download URL blocked");
|
|
266
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("blocks when initial URL DNS resolution fails", async () => {
|
|
270
|
-
const fetchMock = vi.fn();
|
|
271
|
-
await expect(
|
|
272
|
-
safeFetch({
|
|
273
|
-
url: "https://nonexistent.sharepoint.com/file.pdf",
|
|
274
|
-
allowHosts: ["sharepoint.com"],
|
|
275
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
276
|
-
resolveFn: failingResolve,
|
|
277
|
-
}),
|
|
278
|
-
).rejects.toThrow("Initial download URL blocked");
|
|
279
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("follows multiple redirects when all are valid", async () => {
|
|
283
|
-
const fetchMock = vi.fn(async (url: string, init?: RequestInit) => {
|
|
284
|
-
if (url === "https://a.sharepoint.com/1" && init?.redirect === "manual") {
|
|
285
|
-
return new Response(null, {
|
|
286
|
-
status: 302,
|
|
287
|
-
headers: { location: "https://b.sharepoint.com/2" },
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
if (url === "https://b.sharepoint.com/2" && init?.redirect === "manual") {
|
|
291
|
-
return new Response(null, {
|
|
292
|
-
status: 302,
|
|
293
|
-
headers: { location: "https://c.sharepoint.com/3" },
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
return new Response("final", { status: 200 });
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
const res = await safeFetch({
|
|
300
|
-
url: "https://a.sharepoint.com/1",
|
|
301
|
-
allowHosts: ["sharepoint.com"],
|
|
302
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
303
|
-
resolveFn: publicResolve,
|
|
304
|
-
});
|
|
305
|
-
expect(res.status).toBe(200);
|
|
306
|
-
expect(fetchMock).toHaveBeenCalledTimes(3);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it("throws on too many redirects", async () => {
|
|
310
|
-
let counter = 0;
|
|
311
|
-
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {
|
|
312
|
-
if (init?.redirect === "manual") {
|
|
313
|
-
counter++;
|
|
314
|
-
return new Response(null, {
|
|
315
|
-
status: 302,
|
|
316
|
-
headers: { location: `https://loop${counter}.sharepoint.com/x` },
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
return new Response("ok", { status: 200 });
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
await expect(
|
|
323
|
-
safeFetch({
|
|
324
|
-
url: "https://start.sharepoint.com/x",
|
|
325
|
-
allowHosts: ["sharepoint.com"],
|
|
326
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
327
|
-
resolveFn: publicResolve,
|
|
328
|
-
}),
|
|
329
|
-
).rejects.toThrow("Too many redirects");
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it("blocks redirect to HTTP (non-HTTPS)", async () => {
|
|
333
|
-
const fetchMock = mockFetchWithRedirect({
|
|
334
|
-
"https://teams.sharepoint.com/file": "http://internal.sharepoint.com/file",
|
|
335
|
-
});
|
|
336
|
-
await expect(
|
|
337
|
-
safeFetch({
|
|
338
|
-
url: "https://teams.sharepoint.com/file",
|
|
339
|
-
allowHosts: ["sharepoint.com"],
|
|
340
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
341
|
-
resolveFn: publicResolve,
|
|
342
|
-
}),
|
|
343
|
-
).rejects.toThrow("blocked by allowlist");
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it("strips authorization across redirects outside auth allowlist", async () => {
|
|
347
|
-
const seenAuth: string[] = [];
|
|
348
|
-
const fetchMock = vi.fn(async (url: string, init?: RequestInit) => {
|
|
349
|
-
const auth = new Headers(init?.headers).get("authorization") ?? "";
|
|
350
|
-
seenAuth.push(`${url}|${auth}`);
|
|
351
|
-
if (url === "https://teams.sharepoint.com/file.pdf") {
|
|
352
|
-
return new Response(null, {
|
|
353
|
-
status: 302,
|
|
354
|
-
headers: { location: "https://cdn.sharepoint.com/storage/file.pdf" },
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
return new Response("ok", { status: 200 });
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
const headers = new Headers({ Authorization: "Bearer secret" });
|
|
361
|
-
const res = await safeFetch({
|
|
362
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
363
|
-
allowHosts: ["sharepoint.com"],
|
|
364
|
-
authorizationAllowHosts: ["graph.microsoft.com"],
|
|
365
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
366
|
-
requestInit: { headers },
|
|
367
|
-
resolveFn: publicResolve,
|
|
368
|
-
});
|
|
369
|
-
expect(res.status).toBe(200);
|
|
370
|
-
expect(seenAuth[0]).toContain("Bearer secret");
|
|
371
|
-
expect(seenAuth[1]).toMatch(/\|$/);
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
describe("attachment fetch auth helpers", () => {
|
|
376
|
-
it("sets and clears authorization header by auth allowlist", () => {
|
|
377
|
-
const headers = new Headers();
|
|
378
|
-
applyAuthorizationHeaderForUrl({
|
|
379
|
-
headers,
|
|
380
|
-
url: "https://graph.microsoft.com/v1.0/me",
|
|
381
|
-
authAllowHosts: ["graph.microsoft.com"],
|
|
382
|
-
bearerToken: "token-1",
|
|
383
|
-
});
|
|
384
|
-
expect(headers.get("authorization")).toBe("Bearer token-1");
|
|
385
|
-
|
|
386
|
-
applyAuthorizationHeaderForUrl({
|
|
387
|
-
headers,
|
|
388
|
-
url: "https://evil.example.com/collect",
|
|
389
|
-
authAllowHosts: ["graph.microsoft.com"],
|
|
390
|
-
bearerToken: "token-1",
|
|
391
|
-
});
|
|
392
|
-
expect(headers.get("authorization")).toBeNull();
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it("safeFetchWithPolicy forwards policy allowlists", async () => {
|
|
396
|
-
const fetchMock = vi.fn(async (_url: string, _init?: RequestInit) => {
|
|
397
|
-
return new Response("ok", { status: 200 });
|
|
398
|
-
});
|
|
399
|
-
const res = await safeFetchWithPolicy({
|
|
400
|
-
url: "https://teams.sharepoint.com/file.pdf",
|
|
401
|
-
policy: resolveAttachmentFetchPolicy({
|
|
402
|
-
allowHosts: ["sharepoint.com"],
|
|
403
|
-
authAllowHosts: ["graph.microsoft.com"],
|
|
404
|
-
}),
|
|
405
|
-
fetchFn: fetchMock as unknown as typeof fetch,
|
|
406
|
-
resolveFn: publicResolve,
|
|
407
|
-
});
|
|
408
|
-
expect(res.status).toBe(200);
|
|
409
|
-
expect(fetchMock).toHaveBeenCalledOnce();
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
describe("Graph shared-link helpers", () => {
|
|
414
|
-
it.each([
|
|
415
|
-
["https://contoso.sharepoint.com/personal/user/Documents/report.pdf", true],
|
|
416
|
-
["https://contoso.sharepoint.us/sites/team/file.docx", true],
|
|
417
|
-
["https://contoso.sharepoint.cn/file", true],
|
|
418
|
-
["https://tenant-my.sharepoint.com/:b:/g/personal/file", true],
|
|
419
|
-
["https://1drv.ms/b/s!AkxYabc", true],
|
|
420
|
-
["https://onedrive.live.com/view.aspx?resid=ABC", true],
|
|
421
|
-
["https://onedrive.com/share/abc", true],
|
|
422
|
-
["https://graph.microsoft.com/v1.0/me", false],
|
|
423
|
-
["https://smba.trafficmanager.net/amer/v3", false],
|
|
424
|
-
["https://example.com/file.pdf", false],
|
|
425
|
-
["not-a-url", false],
|
|
426
|
-
])("isGraphSharedLinkUrl(%s) === %s", (url, expected) => {
|
|
427
|
-
expect(isGraphSharedLinkUrl(url)).toBe(expected);
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it("encodeGraphShareId uses u! + base64url without padding", () => {
|
|
431
|
-
// Graph docs example: encoding "https://onedrive.live.com/redir?resid=..."
|
|
432
|
-
// should yield u!aHR0cHM6... (base64url, no '+', '/', or trailing '=').
|
|
433
|
-
const url = "https://contoso.sharepoint.com/sites/a/Shared Documents/file.pdf";
|
|
434
|
-
const shareId = encodeGraphShareId(url);
|
|
435
|
-
expect(shareId.startsWith("u!")).toBe(true);
|
|
436
|
-
const encoded = shareId.slice(2);
|
|
437
|
-
// base64url alphabet is A-Z, a-z, 0-9, '-', '_' (no padding).
|
|
438
|
-
expect(encoded).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
439
|
-
// Round-trip check: decoding yields the original URL.
|
|
440
|
-
const decoded = Buffer.from(encoded, "base64url").toString("utf8");
|
|
441
|
-
expect(decoded).toBe(url);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it("encodeGraphShareId swaps '+' and '/' for '-' and '_'", () => {
|
|
445
|
-
// A URL whose standard base64 contains '+' and '/' chars.
|
|
446
|
-
// Choose an input that base64 encodes with those characters.
|
|
447
|
-
const url = "https://host.sharepoint.com/sites/path?x=???";
|
|
448
|
-
const shareId = encodeGraphShareId(url);
|
|
449
|
-
const encoded = shareId.slice(2);
|
|
450
|
-
expect(encoded).not.toContain("+");
|
|
451
|
-
expect(encoded).not.toContain("/");
|
|
452
|
-
expect(encoded).not.toContain("=");
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
it("tryBuildGraphSharesUrlForSharedLink rewrites SharePoint URLs", () => {
|
|
456
|
-
const url = "https://contoso.sharepoint.com/personal/user/Documents/report.pdf";
|
|
457
|
-
const result = tryBuildGraphSharesUrlForSharedLink(url);
|
|
458
|
-
expect(result).toBeDefined();
|
|
459
|
-
expect(result).toMatch(
|
|
460
|
-
/^https:\/\/graph\.microsoft\.com\/v1\.0\/shares\/u![A-Za-z0-9_-]+\/driveItem\/content$/,
|
|
461
|
-
);
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it("tryBuildGraphSharesUrlForSharedLink rewrites OneDrive URLs", () => {
|
|
465
|
-
const url = "https://1drv.ms/b/s!AkxYabcdefg";
|
|
466
|
-
const result = tryBuildGraphSharesUrlForSharedLink(url);
|
|
467
|
-
expect(result).toBeDefined();
|
|
468
|
-
expect(result).toMatch(
|
|
469
|
-
/^https:\/\/graph\.microsoft\.com\/v1\.0\/shares\/u![A-Za-z0-9_-]+\/driveItem\/content$/,
|
|
470
|
-
);
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it("tryBuildGraphSharesUrlForSharedLink returns undefined for non-shared URLs", () => {
|
|
474
|
-
expect(
|
|
475
|
-
tryBuildGraphSharesUrlForSharedLink("https://graph.microsoft.com/v1.0/me"),
|
|
476
|
-
).toBeUndefined();
|
|
477
|
-
expect(tryBuildGraphSharesUrlForSharedLink("https://example.com/file.pdf")).toBeUndefined();
|
|
478
|
-
expect(tryBuildGraphSharesUrlForSharedLink("not-a-url")).toBeUndefined();
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
describe("msteams inline image limits", () => {
|
|
483
|
-
const smallPngDataUrl = "data:image/png;base64,aGVsbG8="; // "hello" (5 bytes)
|
|
484
|
-
|
|
485
|
-
it("rejects inline data images above per-image limit", () => {
|
|
486
|
-
const attachments = [
|
|
487
|
-
{
|
|
488
|
-
contentType: "text/html",
|
|
489
|
-
content: `<img src="${smallPngDataUrl}" />`,
|
|
490
|
-
},
|
|
491
|
-
];
|
|
492
|
-
const out = extractInlineImageCandidates(attachments, { maxInlineBytes: 4 });
|
|
493
|
-
expect(out).toEqual([]);
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
it("accepts inline data images within limit", () => {
|
|
497
|
-
const attachments = [
|
|
498
|
-
{
|
|
499
|
-
contentType: "text/html",
|
|
500
|
-
content: `<img src="${smallPngDataUrl}" />`,
|
|
501
|
-
},
|
|
502
|
-
];
|
|
503
|
-
const out = extractInlineImageCandidates(attachments, { maxInlineBytes: 10 });
|
|
504
|
-
expect(out.length).toBe(1);
|
|
505
|
-
expect(out[0]?.kind).toBe("data");
|
|
506
|
-
if (out[0]?.kind === "data") {
|
|
507
|
-
expect(out[0].data.byteLength).toBeGreaterThan(0);
|
|
508
|
-
expect(out[0].contentType).toBe("image/png");
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
it("enforces cumulative inline size limit across attachments", () => {
|
|
513
|
-
const attachments = [
|
|
514
|
-
{
|
|
515
|
-
contentType: "text/html",
|
|
516
|
-
content: `<img src="${smallPngDataUrl}" />`,
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
contentType: "text/html",
|
|
520
|
-
content: `<img src="${smallPngDataUrl}" />`,
|
|
521
|
-
},
|
|
522
|
-
];
|
|
523
|
-
const out = extractInlineImageCandidates(attachments, {
|
|
524
|
-
maxInlineBytes: 10,
|
|
525
|
-
maxInlineTotalBytes: 6,
|
|
526
|
-
});
|
|
527
|
-
expect(out.length).toBe(1);
|
|
528
|
-
expect(out[0]?.kind).toBe("data");
|
|
529
|
-
});
|
|
530
|
-
});
|