Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
babel-plugin-shim-nodejs
Advanced tools
Transform server side code to use Node.js shims for the browser.
In
var console = require('console');
console.info('Hello from '+__filename);
Out
var __filename = 'index.js';
var console = require('liferay-node-console');
console.info('Hello from '+__filename);
npm install --save-dev babel-plugin-shim-nodejs
Add the following to your .babelrc
file:
Without options:
{
"plugins": ["shim-nodejs"]
}
With options:
{
"plugins": [
["shim-nodejs", {
"nodeShimsVersion": "1.5.0",
"globals": {
"process": "var process = {env: {NODE_ENV: 'production'}}};"
},
"modules": {
}
}]
]
}
This plugins transforms as much as possible Node.js server code to make it work in the browser by using shims.
It assumes that you have deployed frontend-js-node-shims OSGi bundle to your Portal (the bundle is shipped with standard installations by default).
Failure to deploy such bundle will result in Javascript errors due to missing modules.
The plugin supports rewriting of all Node.js v8 globals and builtin modules to make them use the shims. This does not necessarily mean that all server code will work, just that it will try to use the shims, but the shims may not be deployed or may be incomplete.
Consider, for example, that there's no way to fully shim Node.js's
child_process
module in a browser (in a standard way) so that all npm packages
using it may work correctly in the browser.
The usual way to shim globals is to look for their appearance as lone identifiers and prepend a variable declaration for the global on top of the module.
On the other hand, the usual way to shim modules is to rewrite the require()
calls to prepend the liferay-node-
prefix to the module name so that the
deployed shim is loaded instead of failing with a missing module exception.
Of course, if liferay-node-*
modules are required after transformation, the
transformed package's package.json
file must be patched to inject a dependency
to the liferay-node-*
packages. This is also automatically done by the plugin.
This plugin has several configuration options that can be tweaked to support more globals and/or modules:
1.0.0
, it specifies the version to
use when patching package.json
files.liferay-node
(see modules.js for a more detailed description).FAQs
A Babel plugin to shim Node.js global objects and modules.
The npm package babel-plugin-shim-nodejs receives a total of 4 weekly downloads. As such, babel-plugin-shim-nodejs popularity was classified as not popular.
We found that babel-plugin-shim-nodejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.