Socket
Socket
Sign inDemoInstall

require-in-the-middle

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-in-the-middle - npm Package Compare versions

Comparing version 7.3.0 to 7.4.0

47

index.js

@@ -142,2 +142,23 @@ 'use strict'

return patchedRequire.call(this, arguments, false)
}
if (typeof process.getBuiltinModule === 'function') {
this._origGetBuiltinModule = process.getBuiltinModule
this._getBuiltinModule = process.getBuiltinModule = function (id) {
if (self._unhooked === true) {
// if the patched process.getBuiltinModule function could not be removed because
// someone else patched it after it was patched here, we just abort and pass the
// request onwards to the original process.getBuiltinModule
debug('ignoring process.getBuiltinModule call - module is soft-unhooked')
return self._origGetBuiltinModule.apply(this, arguments)
}
return patchedRequire.call(this, arguments, true)
}
}
// Preserve the original require/process.getBuiltinModule arguments in `args`
function patchedRequire (args, coreOnly) {
const id = args[0]
const core = isCore(id)

@@ -155,2 +176,8 @@ let filename // the string used for caching

}
} else if (coreOnly) {
// `coreOnly` is `true` if this was a call to `process.getBuiltinModule`, in which case
// we don't want to return anything if the requested `id` isn't a core module. Falling
// back to default behaviour, which at the time of this wrting is simply returning `undefined`
debug('call to process.getBuiltinModule with unknown built-in id')
return self._origGetBuiltinModule.apply(this, args)
} else {

@@ -169,3 +196,3 @@ try {

debug('Module._resolveFilename("%s") threw %j, calling original Module.require', id, resolveErr.message)
return self._origRequire.apply(this, arguments)
return self._origRequire.apply(this, args)
}

@@ -191,3 +218,5 @@ }

const exports = self._origRequire.apply(this, arguments)
const exports = coreOnly
? self._origGetBuiltinModule.apply(this, args)
: self._origRequire.apply(this, args)

@@ -295,8 +324,18 @@ // If it's already patched, just return it as-is.

this._unhooked = true
if (this._require === Module.prototype.require) {
Module.prototype.require = this._origRequire
debug('unhook successful')
debug('require unhook successful')
} else {
debug('unhook unsuccessful')
debug('require unhook unsuccessful')
}
if (process.getBuiltinModule !== undefined) {
if (this._getBuiltinModule === process.getBuiltinModule) {
process.getBuiltinModule = this._origGetBuiltinModule
debug('process.getBuiltinModule unhook successful')
} else {
debug('process.getBuiltinModule unhook unsuccessful')
}
}
}

@@ -303,0 +342,0 @@

6

package.json
{
"name": "require-in-the-middle",
"version": "7.3.0",
"version": "7.4.0",
"description": "Module to hook into the Node.js require function",

@@ -8,5 +8,5 @@ "main": "index.js",

"dependencies": {
"debug": "^4.1.1",
"debug": "^4.3.5",
"module-details-from-path": "^1.0.3",
"resolve": "^1.22.1"
"resolve": "^1.22.8"
},

@@ -13,0 +13,0 @@ "devDependencies": {

@@ -9,2 +9,3 @@ # require-in-the-middle

Also supports hooking into calls to `process.getBuiltinModule()`, which was introduced in Node.js v22.3.0.

@@ -76,3 +77,3 @@ ## Installation

Removes the `onrequire` callback so that it will not be triggerd by
subsequent calls to `require()`.
subsequent calls to `require()` or `process.getBuiltinModule()`.

@@ -79,0 +80,0 @@ ## License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc