Skip to content

Commit 5f6c0f0

Browse files
committed
fix(msteams): require https for shared links
1 parent 8eedf44 commit 5f6c0f0

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎extensions/msteams/src/attachments.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,24 @@ describe("msteams attachments", () => {
754754
expect(calledUrls.some((url) => url.startsWith(GRAPH_SHARES_URL_PREFIX))).toBe(false);
755755
expect(tokenProvider.getAccessToken).not.toHaveBeenCalled();
756756
});
757+
758+
it("rejects non-HTTPS shared-link hosts before fetch or auth fallback", async () => {
759+
const tokenProvider = createTokenProvider();
760+
const fetchMock = vi.fn(async () => createTextResponse("unauthorized", 401));
761+
762+
await downloadAttachmentsWithFetch(
763+
createPdfAttachments("http://onedrive.com/direct.pdf"),
764+
fetchMock,
765+
{
766+
tokenProvider,
767+
allowHosts: ["onedrive.com", GRAPH_HOST],
768+
authAllowHosts: [GRAPH_HOST],
769+
},
770+
{ expectFetchCalled: false },
771+
);
772+
773+
expect(tokenProvider.getAccessToken).not.toHaveBeenCalled();
774+
});
757775
});
758776

759777
describe("error logging (issue #63396)", () => {

‎extensions/msteams/src/attachments/shared.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ describe("Graph shared-link helpers", () => {
538538
["https://evil1drv.ms/x", false],
539539
["https://fakeonedrive.live.com/x", false],
540540
["https://evilsharepoint.com/x", false],
541+
["http://onedrive.com/x", false],
541542
["not-a-url", false],
542543
])("isGraphSharedLinkUrl(%s) === %s", (url, expected) => {
543544
expect(isGraphSharedLinkUrl(url)).toBe(expected);

‎extensions/msteams/src/attachments/shared.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@ const GRAPH_SHARED_LINK_HOST_SUFFIXES = [
165165
* than directly.
166166
*/
167167
function isGraphSharedLinkUrl(url: string): boolean {
168-
let host: string;
168+
let parsed: URL;
169169
try {
170-
host = normalizeLowercaseStringOrEmpty(new URL(url).hostname);
170+
parsed = new URL(url);
171171
} catch {
172172
return false;
173173
}
174-
if (!host) {
174+
const host = normalizeLowercaseStringOrEmpty(parsed.hostname);
175+
if (parsed.protocol !== "https:" || !host) {
175176
return false;
176177
}
177-
// Match on a dot boundary so look-alike hosts such as "evil1drv.ms" or
178-
// "notonedrive.com" are not treated as shared-link hosts.
178+
// Only HTTPS URLs on a DNS label boundary may select the authenticated Graph path.
179179
return GRAPH_SHARED_LINK_HOST_SUFFIXES.some(
180180
(suffix) => host === suffix || host.endsWith(suffix.startsWith(".") ? suffix : `.${suffix}`),
181181
);

0 commit comments

Comments
 (0)