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(() => {