Skip to content

Commit 936f3f2

Browse files
committed
Append referrerPolicy for non cloudflare envs.
1 parent cc8114c commit 936f3f2

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

common/api-review/util.api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ export function isBrowser(): boolean;
264264
// @public (undocumented)
265265
export function isBrowserExtension(): boolean;
266266

267+
// Warning: (ae-missing-release-tag) "isCloudflareRunner" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
268+
//
269+
// @public
270+
export function isCloudflareRunner(): boolean;
271+
267272
// Warning: (ae-missing-release-tag) "isElectron" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
268273
//
269274
// @public

packages/auth/src/api/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseError, querystring } from '@firebase/util';
18+
import { FirebaseError, isCloudflareRunner, querystring } from '@firebase/util';
1919

2020
import { AuthErrorCode, NamedErrorParams } from '../core/errors';
2121
import {
@@ -148,13 +148,21 @@ export async function _performApiRequest<T, V>(
148148
headers[HttpHeader.X_FIREBASE_LOCALE] = auth.languageCode;
149149
}
150150

151+
var fetchArgs = {
152+
method,
153+
headers,
154+
...body
155+
};
156+
157+
if (!isCloudflareRunner()) {
158+
Object.assign(fetchArgs, {
159+
refererPolicy: 'no-referrer'
160+
});
161+
}
162+
151163
return FetchProvider.fetch()(
152164
_getFinalTarget(auth, auth.config.apiHost, path, query),
153-
{
154-
method,
155-
headers,
156-
...body
157-
}
165+
fetchArgs
158166
);
159167
});
160168
}

packages/util/src/environment.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function isNode(): boolean {
7979
}
8080

8181
/**
82-
* Detect Browser Environment
82+
* Detect Browser Environment.
8383
* Note: This will return true for certain test frameworks that are incompletely
8484
* mimicking a browser, and should not lead to assuming all browser APIs are
8585
* available.
@@ -89,7 +89,7 @@ export function isBrowser(): boolean {
8989
}
9090

9191
/**
92-
* Detect Web Worker context
92+
* Detect Web Worker context.
9393
*/
9494
export function isWebWorker(): boolean {
9595
return (
@@ -99,6 +99,16 @@ export function isWebWorker(): boolean {
9999
);
100100
}
101101

102+
/**
103+
* Detect Cloudflare Runner context.
104+
*/
105+
export function isCloudflareRunner() {
106+
return (
107+
typeof navigator !== 'undefined' &&
108+
navigator.userAgent === 'Cloudflare-Workers'
109+
);
110+
}
111+
102112
/**
103113
* Detect browser extensions (Chrome and Firefox at least).
104114
*/

0 commit comments

Comments
 (0)