Skip to content

Commit

Permalink
revert(bug): Revert settings redirect in graphql to fix ios pairing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vbudhram committed Aug 28, 2023
1 parent 195ca61 commit a018d63
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
9 changes: 1 addition & 8 deletions packages/fxa-content-server/app/scripts/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,7 @@ Router = Router.extend({
const searchParams = new URLSearchParams(this.window.location.search);
const redirectUrl = searchParams.get('redirect_to');
if (redirectUrl) {
// Ignore query params when validating the redirect url
const parsedRedirectUrl = redirectUrl.split('?')[0];
if (
!this.isValidRedirect(
parsedRedirectUrl,
this.config.redirectAllowlist
)
) {
if (!this.isValidRedirect(redirectUrl, this.config.redirectAllowlist)) {
throw new Error('Invalid redirect!');
}
return this.navigateAway(redirectUrl);
Expand Down
13 changes: 6 additions & 7 deletions packages/fxa-settings/src/lib/gql.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { errorHandler } from './gql';
import { errorHandler, pagesRequiringAuthentication } from './gql';
import { ErrorResponse } from '@apollo/client/link/error';
import { Operation, NextLink, ServerError } from '@apollo/client/core';
import { GraphQLError } from 'graphql';
Expand All @@ -11,8 +11,8 @@ let errorResponse: ErrorResponse;
let mockReplace: Mock;

describe('errorHandler', () => {
const pageWhichRequiresAuthentication = 'https://accounts.firefox.com/settings';
const pageWhichDoesNotRequireAuthentication = 'https://accounts.firefox.com/signin';
const pageWhichRequiresAuthentication = pagesRequiringAuthentication[0];
const pageWhichDoesNotRequireAuthentication = 'foo';
beforeAll(() => {
mockReplace = jest.fn();
Object.defineProperty(window, 'location', {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('errorHandler', () => {
errorHandler(errorResponse);

expect(window.location.replace).toHaveBeenCalledWith(
'/signin?redirect_to=https%3A%2F%2Faccounts.firefox.com%2Fsettings'
`/signin?redirect_to=${pageWhichRequiresAuthentication}`
);
});

Expand All @@ -60,7 +60,7 @@ describe('errorHandler', () => {
errorHandler(errorResponse);

expect(window.location.replace).toHaveBeenCalledWith(
'/signin?redirect_to=https%3A%2F%2Faccounts.firefox.com%2Fsettings'
`/signin?redirect_to=${pageWhichRequiresAuthentication}`
);
});

Expand All @@ -86,8 +86,7 @@ describe('errorHandler', () => {
value: {
replace: mockReplace,
search: '',
pathname: 'signin',
href: pageWhichDoesNotRequireAuthentication,
pathname: pageWhichDoesNotRequireAuthentication,
},
});

Expand Down
6 changes: 1 addition & 5 deletions packages/fxa-settings/src/lib/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ export const errorHandler: ErrorHandler = ({ graphQLErrors, networkError }) => {
}
}
if (reauth && currentPageRequiresAuthentication) {
// When doing a redirect and going to signin, we want to ensure that original query params
// are sent as well, otw we would strip out utms and context params
const queryParams = new URLSearchParams(window.location.search);
queryParams.set('redirect_to', window.location.href);
window.location.replace(
`/signin?${queryParams.toString()}`
`/signin?redirect_to=${encodeURIComponent(window.location.pathname)}`
);
} else {
if (!reauth) {
Expand Down

0 comments on commit a018d63

Please sign in to comment.