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-transform-safely
Advanced tools
This babel plugin will transform expressions that use a safely
keyword/call to produce safe property access and modification.
$ npm install babel-plugin-transform-safely
The basic format of using the transform is to write object-checked, safe expressions (existential property access) in the form:
safely(expression)
We can then access properties on variables that may be set to null or undefined, and they won't error out. For example:
safely(object.subObject.subProperty) // will check for each object's existence before accessing property
Will be rewritten to:
var _object
(_object = object == null ? void 0 : object.subObject) == null ? void 0 : _object.subProperty
So if object
or subObject
is not an object, the entire expression will return undefined
(without an error).
And we can assign properties to objects thay may not exist yet, and they will be created:
safely(object.subObject.subProperty = 4) // will create the any missing objects in order to assign property
If object
or subObject
are not objects, they will be assigned an object.
And we can make function or method calls on functions may or may not exist as well:
safely(object.method(args)) // will only call if method exists
Again, this will return undefined
if the method doesn't exist.
If you use a numeric index or the push
or unshift
method, the code will be transformed to create an array as necessary (rather than just doing an existence check). For example:
object.arrayProperty.push('hi')
If arrayProperty
is not defined, an array will be created (and push
called on it).
And of course you can combine any permutation of the above (with any other valid expression or operator):
safely(empty.b.c = object[a]() || object[b](something.c.d))
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-safely"]
}
$ babel --plugins transform-safely
require("babel-core").transform("code", {
plugins: ["transform-safely"]
});
FAQs
Transform code for safe property access and modification
The npm package babel-plugin-transform-safely receives a total of 1 weekly downloads. As such, babel-plugin-transform-safely popularity was classified as not popular.
We found that babel-plugin-transform-safely 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.