Skip to content

Commit 99414a5

Browse files
Always send our auth token on Node, and always send an appcheck token if we have one. (#5082)
* Always send our auth token on Node, and always send an appcheck token if we have one. * Add changeset * Update .changeset/silent-seals-approve.md Co-authored-by: Sebastian Schmidt <[email protected]> Co-authored-by: Sebastian Schmidt <[email protected]>
1 parent f4c106e commit 99414a5

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

.changeset/silent-seals-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/database': patch
3+
---
4+
5+
On Node, always send Auth and AppCheck tokens when they are available.

packages/database/src/realtime/WebSocketConnection.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,15 @@ export class WebSocketConnection implements Transport {
167167
};
168168

169169
// If using Node with admin creds, AppCheck-related checks are unnecessary.
170-
// It will send the authorization token.
171-
if (this.nodeAdmin) {
172-
options.headers['Authorization'] = this.authToken || '';
173-
} else {
174-
// If using Node without admin creds (which includes all uses of the
175-
// client-side Node SDK), it will send an AppCheck token if available.
176-
// Any other auth credentials will eventually be sent after the connection
177-
// is established, but aren't needed here as they don't effect the initial
178-
// request to establish a connection.
179-
options.headers['X-Firebase-AppCheck'] = this.appCheckToken || '';
170+
// Note that we send the credentials here even if they aren't admin credentials, which is
171+
// not a problem.
172+
// Note that this header is just used to bypass appcheck, and the token should still be sent
173+
// through the websocket connection once it is established.
174+
if (this.authToken) {
175+
options.headers['Authorization'] = this.authToken;
176+
}
177+
if (this.appCheckToken) {
178+
options.headers['X-Firebase-AppCheck'] = this.appCheckToken;
180179
}
181180

182181
// Plumb appropriate http_proxy environment variable into faye-websocket if it exists.
@@ -239,7 +238,7 @@ export class WebSocketConnection implements Transport {
239238
/**
240239
* No-op for websockets, we don't need to do anything once the connection is confirmed as open
241240
*/
242-
start() {}
241+
start() { }
243242

244243
static forceDisallow_: boolean;
245244

0 commit comments

Comments
 (0)