Coder Social home page Coder Social logo

Node 18 undici global about lab HOT 6 CLOSED

Marsup avatar Marsup commented on June 8, 2024
Node 18 undici global

from lab.

Comments (6)

kanongil avatar kanongil commented on June 8, 2024 2

@devinivy I think that is overkill.

The number is very unlikely to change during a major, and for majors we usually have to update the globals whitelist anyway.

from lab.

kanongil avatar kanongil commented on June 8, 2024

I had a look into this, since I had already encountered the rogue global.

The global was added here to fix nodejs/undici#1331 and nodejs/node#42814. Interestingly, it only appears once some code has tried to use the experimental built-in implementation of fetch().

Essentially it allows the user-space undici package to expose a setGlobalDispatcher() method, that can customise how the new fetch() method handles requests.

I guess lab just needs to whitelist Symbol.for('undici.globalDispatcher.1') to fix this.

from lab.

devinivy avatar devinivy commented on June 8, 2024

It's noted in undici that the 1 is technically a version number, and will probably change in the future: https://github.com/nodejs/node/blob/5fad0b93667ffc6e4def52996b9529ac99b26319/deps/undici/src/lib/global.js#L3-L5. Would it be too weird for our automatic safe list to attempt to use fetch() in a way that eagerly fails? E.g. this usage await fetch() will fail with ERR_INVALID_URL but still set the global. This occurs in a worker thread, so I believe it shouldn't affect the globals on the main worker thread:

lab/lib/modules/leaks.js

Lines 112 to 126 in 0542146

internals.getNodeGlobals = async () => {
const nodeGlobalsWorker = new WorkerThreads.Worker(__filename);
const [nodeGlobals] = await Events.once(nodeGlobalsWorker, 'message');
return nodeGlobals;
};
if (!WorkerThreads.isMainThread) {
// When this module is used as a worker, it posts back global property names and symbols
WorkerThreads.parentPort.postMessage({
allowed: Object.getOwnPropertyNames(globalThis),
symbols: Object.getOwnPropertySymbols(globalThis).map(String)
});
}

from lab.

kanongil avatar kanongil commented on June 8, 2024

It's curious that node wants to pollute the global js scope, when it could have been solved by exposing a virtual node:undici module.

from lab.

devinivy avatar devinivy commented on June 8, 2024

I read that they wont consider adding it until fetch() is no longer experimental.

from lab.

dominykas avatar dominykas commented on June 8, 2024

Took a stab at implementation - there's a lazy require of undici when accessing FormData (and some other globals), which avoids having to call fetch() just to get it to throw.

from lab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.