Skip to content

Commit 984c1e4

Browse files
author
Michael Lehenbauer
authored
Avoid using $httpHeaders in environments that don't send an Origin header. (#2464)
There is a backend bug (b/145624756) causing $httpHeaders to be ignored if the HTTP request doesn't have an Origin header. Via #1491 we've found that several environments are running into this issue so until the backend issue is fixed we are excluding them from using $httpHeaders. This may incur an extra CORS preflight round-trip in some cases, but this is much better than having our Authorization header get ignored.
1 parent 82c5498 commit 984c1e4

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

packages/firestore/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Unreleased
2+
- [fixed] Fixed an issue where auth credentials were not respected in certain
3+
browser environments (Electron 7, IE11 in trusted zone, UWP apps). (#1491)
4+
5+
# 1.9.0
26
- [feature] Added support for storing and retrieving custom types in Firestore.
37
Added support for strongly typed collections, documents, and
48
queries. You can now use `withConverter()` to supply a custom data

packages/firestore/src/platform_browser/webchannel_connection.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
XhrIo
2626
} from '@firebase/webchannel-wrapper';
2727

28-
import { isReactNative } from '@firebase/util';
28+
import { isElectron, isIE, isReactNative, isUWP } from '@firebase/util';
2929

3030
import { Token } from '../api/credentials';
3131
import { DatabaseId, DatabaseInfo } from '../core/database_info';
@@ -264,11 +264,11 @@ export class WebChannelConnection implements Connection {
264264
// formally defined here:
265265
// https://github.com/google/closure-library/blob/b0e1815b13fb92a46d7c9b3c30de5d6a396a3245/closure/goog/net/rpc/httpcors.js#L32
266266
//
267-
// But for some unclear reason (see
268-
// https://github.com/firebase/firebase-js-sdk/issues/703), this breaks
269-
// ReactNative and so we exclude it, which just means ReactNative may be
270-
// subject to the extra network roundtrip for CORS preflight.
271-
if (!isReactNative()) {
267+
// TODO(b/145624756): There is a backend bug where $httpHeaders isn't respected if the request
268+
// doesn't have an Origin header. So we have to exclude a few browser environments that are
269+
// known to (sometimes) not include an Origin. See
270+
// https://github.com/firebase/firebase-js-sdk/issues/1491.
271+
if (!isReactNative() && !isElectron() && !isIE() && !isUWP()) {
272272
request.httpHeadersOverwriteParam = '$httpHeaders';
273273
}
274274

packages/util/src/environment.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ export function isReactNative(): boolean {
8383
);
8484
}
8585

86+
/** Detects Electron apps. */
87+
export function isElectron(): boolean {
88+
return getUA().indexOf('Electron/') >= 0;
89+
}
90+
91+
/** Detects Internet Explorer. */
92+
export function isIE(): boolean {
93+
const ua = getUA();
94+
return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
95+
}
96+
97+
/** Detects Universal Windows Platform apps. */
98+
export function isUWP(): boolean {
99+
return getUA().indexOf('MSAppHost/') >= 0;
100+
}
101+
86102
/**
87103
* Detect whether the current SDK build is the Node version.
88104
*

0 commit comments

Comments
 (0)