Skip to content

Commit bebecda

Browse files
authored
Replace node-fetch dependency with undici (#7705)
Update our dependency on aging `node-fetch` `v2.6.7` to `undici` `v5.26.5`. This should fix some vulnerabilities within node-fetch as well as fix user issue #7660.
1 parent a89e05b commit bebecda

File tree

27 files changed

+147757
-195
lines changed

27 files changed

+147757
-195
lines changed

.changeset/real-dolls-type.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@firebase/auth-compat': minor
3+
'@firebase/firestore': minor
4+
'@firebase/functions': minor
5+
'@firebase/storage': minor
6+
'@firebase/auth': minor
7+
'firebase': minor
8+
---
9+
10+
Replaced node-fetch v2.6.7 dependency with the latest version of undici (v5.26.5) in Node.js SDK
11+
builds for auth, firestore, functions and storage.

.yarn/releases/yarn-1.22.11.cjs

Lines changed: 147406 additions & 0 deletions
Large diffs are not rendered by default.

integration/messaging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"express": "4.18.2",
1616
"geckodriver": "2.0.4",
1717
"mocha": "9.2.2",
18-
"node-fetch": "2.6.7",
18+
"undici": "5.26.5",
1919
"selenium-assistant": "6.1.1"
2020
}
2121
}

integration/messaging/test/utils/sendMessage.js

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

18-
const fetch = require('node-fetch');
18+
const undici = require('undici');
1919
const FCM_SEND_ENDPOINT = 'https://fcm.googleapis.com/fcm/send';
2020
// Rotatable fcm server key. It's generally a bad idea to expose server keys. The reason is to
2121
// simplify testing process (no need to implement server side decryption of git secret). The
@@ -28,7 +28,7 @@ module.exports = async payload => {
2828
'Requesting to send an FCM message with payload: ' + JSON.stringify(payload)
2929
);
3030

31-
const response = await fetch(FCM_SEND_ENDPOINT, {
31+
const response = await undici.fetch(FCM_SEND_ENDPOINT, {
3232
method: 'POST',
3333
body: JSON.stringify(payload),
3434
headers: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
"tslint": "6.1.3",
154154
"typedoc": "0.16.11",
155155
"typescript": "4.7.4",
156+
"undici": "5.26.5",
156157
"watch": "1.0.2",
157158
"webpack": "5.76.0",
158159
"yargs": "17.7.2"

packages/auth-compat/index.node.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
*/
2424
export * from './index';
2525
import { FetchProvider } from '@firebase/auth/internal';
26-
import * as fetchImpl from 'node-fetch';
26+
import {
27+
fetch as undiciFetch,
28+
Headers as undiciHeaders,
29+
Response as undiciResponse
30+
} from 'undici';
2731
import './index';
2832

2933
FetchProvider.initialize(
30-
fetchImpl.default as unknown as typeof fetch,
31-
fetchImpl.Headers as unknown as typeof Headers,
32-
fetchImpl.Response as unknown as typeof Response
34+
undiciFetch as unknown as typeof fetch,
35+
undiciHeaders as unknown as typeof Headers,
36+
undiciResponse as unknown as typeof Response
3337
);

packages/auth-compat/karma.conf.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
const karmaBase = require('../../config/karma.base');
19+
const webpackBase = require('../../config/webpack.test');
1920
const { argv } = require('yargs');
2021

2122
const files = ['src/**/*.test.ts'];
@@ -29,6 +30,17 @@ module.exports = function (config) {
2930
// frameworks to use
3031
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
3132
frameworks: ['mocha'],
33+
// undici is a fetch polyfill that test helpers call for Node tests, and browser tests should
34+
// ingore its import to avoid compilation errors in those test helpers.
35+
webpack: {
36+
...webpackBase,
37+
resolve: {
38+
...webpackBase.resolve,
39+
alias: {
40+
'undici': false
41+
}
42+
}
43+
},
3244

3345
client: Object.assign({}, karmaBase.client, getClientConfig())
3446
});

packages/auth-compat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@firebase/auth-types": "0.12.0",
5555
"@firebase/component": "0.6.4",
5656
"@firebase/util": "1.9.3",
57-
"node-fetch": "2.6.7",
57+
"undici": "5.26.5",
5858
"tslib": "^2.1.0"
5959
},
6060
"license": "Apache-2.0",

packages/auth/karma.conf.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
const karmaBase = require('../../config/karma.base');
19+
const webpackBase = require('../../config/webpack.test');
1920
const { argv } = require('yargs');
2021

2122
module.exports = function (config) {
@@ -26,7 +27,17 @@ module.exports = function (config) {
2627
// frameworks to use
2728
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
2829
frameworks: ['mocha'],
29-
30+
// undici is a fetch polyfill that test helpers call for Node tests, and browser tests should
31+
// ingore its import to avoid compilation errors in those test helpers.
32+
webpack: {
33+
...webpackBase,
34+
resolve: {
35+
...webpackBase.resolve,
36+
alias: {
37+
'undici': false
38+
}
39+
}
40+
},
3041
client: Object.assign({}, karmaBase.client, getClientConfig(argv))
3142
});
3243

packages/auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"@firebase/component": "0.6.4",
116116
"@firebase/logger": "0.4.0",
117117
"@firebase/util": "1.9.3",
118-
"node-fetch": "2.6.7",
118+
"undici": "5.26.5",
119119
"tslib": "^2.1.0"
120120
},
121121
"license": "Apache-2.0",

0 commit comments

Comments
 (0)