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

Always send our auth token on Node, and always send an appcheck token if we have one. #5082

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/silent-seals-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/database': patch
---

On node, always send auth and appcheck tokens when they are available.
jsdt marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 10 additions & 11 deletions packages/database/src/realtime/WebSocketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,15 @@ export class WebSocketConnection implements Transport {
};

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

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

static forceDisallow_: boolean;

Expand Down