Skip to content

Commit

Permalink
update PB preview query param
Browse files Browse the repository at this point in the history
  • Loading branch information
accbjt committed Mar 20, 2024
1 parent 9b72933 commit f235341
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
},
ecmaVersion: 2020,
sourceType: "module",
requireConfigFile: false,
},
plugins: ["jest", "jest-dom", "jsx-a11y", "react", "react-hooks", "testing-library"],
rules: {
Expand Down
19 changes: 15 additions & 4 deletions blocks/identity-block/components/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const useLogin = ({
if (window?.location?.search) {
const searchParams = new URLSearchParams(window.location.search.substring(1));

//redirectURL could have additional params
// redirectURL could have additional params
const params = ["paymentMethodID"];
const aditionalParams = params.map((p) => {
const aditionalParams = params.filter((p) => {
const paramExist = searchParams.has(p)
if(paramExist){
return {[p]:searchParams.get(p)}
}

return null;
})

const fullURL = searchParams.get("redirect") ? appendURLParams(searchParams.get("redirect"), aditionalParams.filter(item => item !== undefined)) : null;
Expand Down Expand Up @@ -58,18 +60,27 @@ const useLogin = ({
const checkLoggedInStatus = async () => {
const isLoggedIn = await Identity.isLoggedIn();
const validatedLoggedInPageLoc = validateURL(loggedInPageLocation);

if (isLoggedIn) {
if (isOIDC) {
loginByOIDC();
} else {
window.location = redirectQueryParam || validatedLoggedInPageLoc;
const searchParams = new URLSearchParams(window.location.search.substring(1));
const redirectUrl = redirectQueryParam || validatedLoggedInPageLoc;

// PB editor preview will redirect with the website query param.
if (searchParams.get('_website')) {
window.location = validateURL(`${redirectUrl}?_website=${searchParams.get('_website')}`);

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.
} else {
window.location = redirectQueryParam || validatedLoggedInPageLoc;

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.
}
}
}
};
if (Identity && !isAdmin) {
checkLoggedInStatus();
}
}, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin]);
}, [Identity, redirectQueryParam, loggedInPageLocation, isAdmin, loginByOIDC, isOIDC]);

return {
loginRedirect: redirectQueryParam || redirectToURL,
Expand Down
7 changes: 5 additions & 2 deletions blocks/identity-block/components/login/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ describe("useLogin()", () => {
beforeEach(() => {
Object.defineProperty(window, "location", {
writable: true,
value: {
href: 'http://localhost',
}
});
useIdentity.mockImplementation(() => ({
isInitialized: true,
Expand Down Expand Up @@ -68,14 +71,14 @@ describe("useLogin()", () => {
});

it("uses document referrer", async () => {
const referrerURL = "http://referrer.com";
const referrerURL = "http://referrer.com/article/1234";
Object.defineProperty(document, "referrer", {
value: referrerURL,
configurable: true,
});
await render(<Test />);
fireEvent.click(screen.getByRole("button"));
expect(window.location).toBe(referrerURL);
expect(window.location).toBe("/article/1234");
delete document.referrer;
});

Expand Down
2 changes: 1 addition & 1 deletion blocks/subscriptions-block/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,6 @@

@media (min-width: 320px) and (max-width: 480px) {
.b-paywall__overlay {
top: initial;
inset-block-start: initial;
}
}

0 comments on commit f235341

Please sign in to comment.