Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More complex check for authTokenSyncUrl #8076

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/green-mugs-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': patch
---

Additional protection against misuse of the authTokenSyncURL experiment
23 changes: 15 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,21 @@ 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));
// Only do the Cookie exchange in a secure context
if (
authTokenSyncPath &&
typeof isSecureContext === 'boolean' &&
isSecureContext
) {
// Don't allow urls (XSS possibility), only paths on the same domain
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
Loading