Skip to content

Commit 7a5d2d5

Browse files
Strict check for URL params (#336)
* Strict check for URL params * Strict check for URL param - add tests * Update projects/auth0-angular/src/lib/auth.service.ts * Fix compilation Co-authored-by: Frederik Prijck <[email protected]> Co-authored-by: Frederik Prijck <[email protected]>
1 parent c648248 commit 7a5d2d5

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

projects/auth0-angular/src/lib/auth.service.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,17 @@ describe('AuthService', () => {
509509
done();
510510
});
511511
});
512+
513+
it('should not process the callback when query string is a sub string', (done) => {
514+
window.history.replaceState(null, '', '?abccode=123&xyzstate=456');
515+
516+
const localService = createService();
517+
518+
loaded(localService).subscribe(() => {
519+
expect(auth0Client.handleRedirectCallback).not.toHaveBeenCalled();
520+
done();
521+
});
522+
});
512523
});
513524

514525
it('should call `loginWithRedirect`', async () => {

projects/auth0-angular/src/lib/auth.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,14 @@ export class AuthService<TAppState extends AppState = AppState>
367367

368368
private shouldHandleCallback(): Observable<boolean> {
369369
return of(location.search).pipe(
370-
map(
371-
(search) =>
372-
(search.includes('code=') || search.includes('error=')) &&
373-
search.includes('state=') &&
370+
map((search) => {
371+
const searchParams = new URLSearchParams(search);
372+
return (
373+
(searchParams.has('code') || searchParams.has('error')) &&
374+
searchParams.has('state') &&
374375
!this.configFactory.get().skipRedirectCallback
375-
)
376+
);
377+
})
376378
);
377379
}
378380
}

0 commit comments

Comments
 (0)