Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating 2.5.1 with 2.5.0 changes #2211

Merged
Merged
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
10 changes: 9 additions & 1 deletion blocks/identity-block/components/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ const useLogin = ({
}
}, [appleCode, Identity]);

const isReferrerFromHost = () => {
if (!document?.referrer) return false;

const referrerURL = new URL(document.referrer);

return referrerURL.origin === window.location.origin;
};

useEffect(() => {
const searchParams = new URLSearchParams(window.location.search.substring(1));

Expand All @@ -63,7 +71,7 @@ const useLogin = ({
setRedirectQueryParam(validatedRedirectParam);
}

if (redirectToPreviousPage && document?.referrer) {
if (redirectToPreviousPage && document?.referrer && isReferrerFromHost()) {
const redirectUrlLocation = new URL(document.referrer);
let newRedirectUrl = redirectUrlLocation.pathname.includes('/pagebuilder/')
? redirectURL
Expand Down
2 changes: 1 addition & 1 deletion blocks/identity-block/components/login/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("useLogin()", () => {
});

it("uses document referrer", async () => {
const referrerURL = "http://referrer.com/article/1234";
const referrerURL = "http://localhost/article/1234";
Object.defineProperty(document, "referrer", {
value: referrerURL,
configurable: true,
Expand Down
4 changes: 4 additions & 0 deletions blocks/identity-block/utils/validate-redirect-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const validateURL = (url) => {
return `${window.location.origin}${url}`;
}

if (url === "/") {
return url;
}

const urlLocation = new URL(url);

if (urlLocation.origin === window.location.origin) {
Expand Down
Loading