Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GraphRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions test/common/core/urlParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down