Skip to content

Fix for #1491: Disable use of $httpHeaders in browser extensions too. #2534

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

Merged
merged 3 commits into from
Jan 14, 2020
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
4 changes: 4 additions & 0 deletions packages/firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Unreleased
- [fixed] Fixed an issue where auth credentials were not respected in some
Firefox or Chrome extensions. (#1491)

# 1.9.2
- [fixed] Fixed an issue where auth credentials were not respected in certain
browser environments (Electron 7, IE11 in trusted zone, UWP apps). (#1491)

Expand Down
16 changes: 14 additions & 2 deletions packages/firestore/src/platform_browser/webchannel_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import {
XhrIo
} from '@firebase/webchannel-wrapper';

import { isElectron, isIE, isReactNative, isUWP } from '@firebase/util';
import {
isBrowserExtension,
isElectron,
isIE,
isReactNative,
isUWP
} from '@firebase/util';

import { Token } from '../api/credentials';
import { DatabaseId, DatabaseInfo } from '../core/database_info';
Expand Down Expand Up @@ -268,7 +274,13 @@ export class WebChannelConnection implements Connection {
// doesn't have an Origin header. So we have to exclude a few browser environments that are
// known to (sometimes) not include an Origin. See
// https://github.com/firebase/firebase-js-sdk/issues/1491.
if (!isReactNative() && !isElectron() && !isIE() && !isUWP()) {
if (
!isReactNative() &&
!isElectron() &&
!isIE() &&
!isUWP() &&
!isBrowserExtension()
) {
request.httpHeadersOverwriteParam = '$httpHeaders';
}

Expand Down
18 changes: 18 additions & 0 deletions packages/util/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ export function isBrowser(): boolean {
return typeof self === 'object' && self.self === self;
}

/**
* Detect browser extensions (Chrome and Firefox at least).
*/
interface BrowserRuntime {
id?: unknown;
}
declare const chrome: { runtime?: BrowserRuntime };
declare const browser: { runtime?: BrowserRuntime };
export function isBrowserExtension(): boolean {
const runtime =
typeof chrome === 'object'
? chrome.runtime
: typeof browser === 'object'
? browser.runtime
: undefined;
return typeof runtime === 'object' && runtime.id !== undefined;
}

/**
* Detect React Native.
*
Expand Down