Skip to content

Commit be5223e

Browse files
Merge pull request #14289 from mozilla/243-uplift-3
243.3 uplift
2 parents 5ee0143 + cca1f14 commit be5223e

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

packages/fxa-content-server/app/scripts/views/mixins/third-party-auth-mixin.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,25 @@ export default {
167167
// To finish the oauth flow, we will need to stash away the response from
168168
// Google (contains state and code) and redirect back to the original FxA login page.
169169
const searchParams = Url.searchParams(this.window.location.search);
170-
Storage.factory('localStorage', this.window).set(
171-
'fxa_third_party_params',
172-
searchParams
173-
);
174-
175170
const redirectUrl = decodeURIComponent(searchParams.state);
176-
this.navigateAway(redirectUrl);
171+
172+
try {
173+
const url = new URL(redirectUrl);
174+
175+
if (url.origin === this.window.location.origin) {
176+
Storage.factory('localStorage', this.window).set(
177+
'fxa_third_party_params',
178+
searchParams
179+
);
180+
181+
this.navigateAway(redirectUrl);
182+
return;
183+
}
184+
} catch (e) {
185+
// noop. navigate to home below.
186+
}
187+
188+
this.navigateAway('/');
177189
},
178190

179191
async completeSignIn() {
@@ -190,7 +202,7 @@ export default {
190202
this.clearStoredParams();
191203

192204
this.logFlowEvent(`${provider}.signin-complete`);
193-
205+
194206
this.metrics.flush();
195207

196208
return this.signIn(updatedAccount);

packages/fxa-content-server/app/tests/spec/views/mixins/third-party-auth-mixin.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,31 @@ describe('views/mixins/third-party-auth-mixin', function () {
211211
assert.isTrue(mockForm.submit.calledOnce);
212212
});
213213

214-
it('handleOauthResponse', () => {
215-
windowMock.location.search = '?state=localhost';
216-
sinon.stub(view, 'navigateAway');
214+
describe('handleOauthResponse', () => {
215+
it('navigates away', () => {
216+
const redirectUrl = encodeURIComponent(
217+
`${windowMock.location.origin}/go/there`
218+
);
219+
windowMock.location.search = `?state=${redirectUrl}`;
220+
sinon.stub(view, 'navigateAway');
221+
222+
view.handleOauthResponse();
217223

218-
view.handleOauthResponse();
224+
assert.isTrue(
225+
view.navigateAway.calledOnceWith(
226+
`${windowMock.location.origin}/go/there`
227+
)
228+
);
229+
});
219230

220-
assert.isTrue(view.navigateAway.calledOnceWith('localhost'));
231+
it('navigates home', () => {
232+
windowMock.location.search = '?state=quux';
233+
sinon.stub(view, 'navigateAway');
234+
235+
view.handleOauthResponse();
236+
237+
assert.isTrue(view.navigateAway.calledOnceWith('/'));
238+
});
221239
});
222240

223241
it('completeSignIn', async () => {

0 commit comments

Comments
 (0)