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

Avoid using $httpHeaders in environments that don't send an Origin header. #2464

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 certain
browser environments (Electron 7, IE11 in trusted zone, UWP apps). (#1491)

# 1.9.0
- [feature] Added support for storing and retrieving custom types in Firestore.
Added support for strongly typed collections, documents, and
queries. You can now use `withConverter()` to supply a custom data
Expand Down
12 changes: 6 additions & 6 deletions packages/firestore/src/platform_browser/webchannel_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
XhrIo
} from '@firebase/webchannel-wrapper';

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

import { Token } from '../api/credentials';
import { DatabaseId, DatabaseInfo } from '../core/database_info';
Expand Down Expand Up @@ -264,11 +264,11 @@ export class WebChannelConnection implements Connection {
// formally defined here:
// https://github.com/google/closure-library/blob/b0e1815b13fb92a46d7c9b3c30de5d6a396a3245/closure/goog/net/rpc/httpcors.js#L32
//
// But for some unclear reason (see
// https://github.com/firebase/firebase-js-sdk/issues/703), this breaks
// ReactNative and so we exclude it, which just means ReactNative may be
// subject to the extra network roundtrip for CORS preflight.
if (!isReactNative()) {
// TODO(b/145624756): There is a backend bug where $httpHeaders isn't respected if the request
// 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()) {
request.httpHeadersOverwriteParam = '$httpHeaders';
}

Expand Down
16 changes: 16 additions & 0 deletions packages/util/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ export function isReactNative(): boolean {
);
}

/** Detects Electron apps. */
export function isElectron(): boolean {
return getUA().indexOf('Electron/') >= 0;
}

/** Detects Internet Explorer. */
export function isIE(): boolean {
const ua = getUA();
return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
}

/** Detects Universal Windows Platform apps. */
export function isUWP(): boolean {
return getUA().indexOf('MSAppHost/') >= 0;
}

/**
* Detect whether the current SDK build is the Node version.
*
Expand Down