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 2390be8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 10 additions & 1 deletion blocks/identity-block/components/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,20 @@ 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 curentUrl = new URL(window.location.href);
const redirectUrl = redirectQueryParam || validatedLoggedInPageLoc;

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

Check failure on line 71 in blocks/identity-block/components/login/index.jsx

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Expected an assignment or function call and instead saw an expression
} else {
window.location = redirectUrl;

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
.
}
}
}
};
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 2390be8

Please sign in to comment.