google-auth-library-nodejs icon indicating copy to clipboard operation
google-auth-library-nodejs copied to clipboard

Why is Object.prototype mutated?

Open boostpaal opened this issue 3 years ago • 1 comments

I want to freeze the prototype on objects in my app with Object.freeze(Object.prototype), as a first defense against hacks. This is not possible when using this library. The following code will fail.

Object.freeze(Object.prototype);
const { OAuth2Client } = require('google-auth-library');

// TypeError: Cannot assign to read only property 'toString' of object '#<URL>'

Is there a remedy for this?

boostpaal avatar Jun 08 '23 10:06 boostpaal

Looks like that error is from the whatwg-url package:

Uncaught TypeError: Cannot assign to read only property 'toString' of object '#<URL>'
    at Object.<anonymous> (<redacted>/google-auth-library-nodejs/samples/node_modules/whatwg-url/lib/URL.js:50:24)
    at Module._compile (node:internal/modules/cjs/loader:1257:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
    at Module.load (node:internal/modules/cjs/loader:1115:32)
    at Module._load (node:internal/modules/cjs/loader:962:12)
    at Module.require (node:internal/modules/cjs/loader:1139:19)
    at require (node:internal/modules/helpers:121:18)

It looks like it's required by node-fetch (2.x), but is removed in 3.x. Unfortunately, we can't upgrade to 3.x until we upgrade to Node 16.

danielbankhead avatar Jul 12 '23 18:07 danielbankhead