Skip to content

Commit

Permalink
Merge branch 'dev' into feat/vcst-2454
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Orlov committed Dec 20, 2024
2 parents 0ce8ae2 + 7f0ff08 commit 7236800
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions client-app/core/utilities/common/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ describe("getReturnUrlValue", () => {
const result = getReturnUrlValue();
expect(result).toBeNull();
});

it("should return null when returnUrl points to a different hostname", () => {
Object.defineProperty(window, "location", {
configurable: true,
value: {
href: "http://example.com?returnUrl=http://malicious.com/home",
},
});

const result = getReturnUrlValue();
expect(result).toBeNull();
});
});

describe("extractHostname", () => {
Expand Down
12 changes: 10 additions & 2 deletions client-app/core/utilities/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export function getBaseUrl(supportedLocales: string[]): string {
}

export function getReturnUrlValue(): string | null {
const { searchParams } = new URL(location.href);
return searchParams.get("returnUrl") || searchParams.get("ReturnUrl");
const { searchParams, origin, hostname } = new URL(location.href);
const returnUrl = searchParams.get("returnUrl") || searchParams.get("ReturnUrl");

if (returnUrl) {
const returnUrlObj = new URL(returnUrl, origin);
if (returnUrlObj.hostname === hostname) {
return returnUrl;
}
}
return null;
}

export function extractHostname(url: string) {
Expand Down

0 comments on commit 7236800

Please sign in to comment.