ardatan / whatwg-node

Helper packages to create platform agnostic applications and libraries without worrying about the lack of WHATWG support in Node.js
MIT License
158 stars 31 forks source link

Null header value results in page crash #1781

Open subhan-nadeem opened 2 weeks ago

subhan-nadeem commented 2 weeks ago

Describe the bug

In GraphQL Mesh, faced internal crashes where API responses were crashing due Access-Control-Allow-Origin header being set with nil value by response server:

 "message": "TypeError: Cannot read properties of undefined (reading 'includes')\n    at /Users/<user>/Desktop/<project>/graphqlmesh/node_modules/@whatwg-node/node-fetch/cjs/Headers.js:238:37\n    at /Users/<user>/Desktop/<project>/graphqlmesh/node_modules/@whatwg-node/node-fetch/cjs/Headers.js:149:25\n    at Array.forEach (<anonymous>)\n    at PonyfillHeaders.forEach (/Users/<user>/Desktop/<project>/graphqlmesh/node_modules/@whatwg-node/node-fetch/cjs/Headers.js:148:38)\n    at PonyfillHeaders.[nodejs.util.inspect.custom] (/Users/<user>/Desktop/<project>/graphqlmesh/node_modules/@whatwg-node/node-fetch/cjs/Headers.js:233:14)\n    at formatValue (node:internal/util/inspect:806:19)\n    at formatProperty (node:internal/util/inspect:1946:11)\n    at formatRaw (node:internal/util/inspect:1055:9)\n    at formatValue (node:internal/util/inspect:841:10)\n    at Object.inspect (node:internal/util/inspect:365:10)\nThis is caused by either a bug in Node.js or incorrect usage of Node.js internals.\nPlease open an issue with this stack trace at https://github.com/nodejs/node/issues\n",

Root cause seems to be the fact that the library does not guard against nil header values here: https://github.com/ardatan/whatwg-node/blob/master/packages/node-fetch/src/Headers.ts#L266

Should be an easy fix hopefully?

To Reproduce Steps to reproduce the behavior:

Environment:

@ardatan

ardatan commented 2 weeks ago

Could you create a reproduction on CodeSandbox? Thanks! 🙏

ardatan commented 1 week ago

I'd love to help you and learn more about your use case of GraphQL Mesh. If you give more information at least, we can try to reproduce by ourselves. Thanks!