Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
First.
  • Loading branch information
jamesdaniels committed Mar 14, 2024
commit 3735214f21524d84faf5162993b5666b6b65c9d0
21 changes: 13 additions & 8 deletions packages/auth/src/platform_browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ export function getAuth(app: FirebaseApp = getApp()): Auth {
});

const authTokenSyncPath = getExperimentalSetting('authTokenSyncURL');
// Don't allow urls (XSS possibility), only paths on the same domain
// (starting with a single '/')
if (authTokenSyncPath && authTokenSyncPath.match(/^\/[^\/].*/)) {
const mintCookie = mintCookieFactory(authTokenSyncPath);
beforeAuthStateChanged(auth, mintCookie, () =>
mintCookie(auth.currentUser)
);
onIdTokenChanged(auth, user => mintCookie(user));
if (authTokenSyncPath) {
// Reduce the chances of an XSS attack by only allowing secure contexts or the same origin.
const isLocalHost = ['localhost', '127.0.0.1', '0.0.0.0'].includes(location.hostname);
if (isSecureContext || isLocalHost) {
const authTokenSyncUrl = new URL(authTokenSyncPath, location.origin);
if (location.origin === authTokenSyncUrl.origin) {
const mintCookie = mintCookieFactory(authTokenSyncUrl.toString());
beforeAuthStateChanged(auth, mintCookie, () =>
mintCookie(auth.currentUser)
);
onIdTokenChanged(auth, user => mintCookie(user));
}
}
}

const authEmulatorHost = getDefaultEmulatorHost('auth');
Expand Down
⌂ 换网址