From 115543965bdcc775b2c8e0190ed6ae59c9ea6af3 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Mon, 16 Nov 2026 06:25:19 -0400 Subject: [PATCH] fix: treat paths with https:// only in the query as relative parsePath checked for https:// anywhere in the path, so relative paths such as /sites?search=https://contoso.sharepoint.com were parsed as absolute URLs and rejected. Only treat the path as absolute when it starts with https://. --- src/GraphRequest.ts | 2 +- test/common/core/urlParsing.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/GraphRequest.ts b/src/GraphRequest.ts index da0e9821a..b79669a6d 100644 --- a/src/GraphRequest.ts +++ b/src/GraphRequest.ts @@ -131,7 +131,7 @@ export class GraphRequest { */ private parsePath = (path: string): void => { // Strips out the base of the url if they passed in - if (path.indexOf("https://") !== -1) { + if (path.startsWith("https://")) { // Use structured URL parsing to validate the URL and reject userinfo let parsedUrl: URL; try { diff --git a/test/common/core/urlParsing.ts b/test/common/core/urlParsing.ts index a50a544d3..6d3214222 100644 --- a/test/common/core/urlParsing.ts +++ b/test/common/core/urlParsing.ts @@ -62,6 +62,19 @@ describe("urlParsing.ts", () => { } }); + describe("parsePath - relative paths containing https:// in the query", () => { + const relativeCases = { + "/sites?search=https://contoso.sharepoint.com": "https://graph.microsoft.com/v1.0/sites?search=https://contoso.sharepoint.com", + "/me/drive/root/search(q='https://example')": "https://graph.microsoft.com/v1.0/me/drive/root/search(q='https://example')", + }; + for (const path in relativeCases) { + it("should treat as relative: " + path, () => { + const request = client.api(path); + assert.equal(request["buildFullUrl"](), relativeCases[path]); + }); + } + }); + describe("parsePath - userinfo rejection (security)", () => { it("should throw for URLs with userinfo (host confusion attack)", () => { assert.throws(() => {