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.
loopback-boot-scripts
Advanced tools
Loopback Boot Scripts is collection of useful boot scripts for Loopback framework.
Each boot script can be individually enabled / disabled and also it's behavior can be configured to an extent.
npm install loopback-boot-scripts --save
OR
yarn add loopback-boot-scripts
Modify server.js
file as below. This will make the boot-scripts files run first and then boot files in the server/boot
directory.
let bootOptions = {
'appRootDir': __dirname,
'bootDirs': [
'./node_modules/loopback-boot-scripts/dist/'
]
};
...
boot(app, bootOptions, function(err) {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
Inspired from https://gist.github.com/justmoon/15511f92e5216fa2624b.
Creates Error classes for various HTTP error codes as default Node.js Error class does not capture statusCode and code.
"bootScripts": {
"customErrors": {
"errors": [
{"statusCode": 400, "code": "BAD_REQUEST"}
],
"mode": "merge"
}
}
In above example, a new class BadRequestError
will be created with default statusCode=400
and code=BAD_REQUEST
.
mode
parameter can have a truthy value merge
or anything else as falsy.
If mode = merge
i.e. truthy, errors given with config will be merged with default errors in errors.json, else default errors will be overwritten.
Simply replaces native Promise with bluebird Promise.
Accessing models within loopback can be tedious at times. This boot script simply brings all models to global scope for easy reference.
Adds findBy{Property}
and findOneBy{Property}
methods to models.
e.g.
{
"name": "Contact",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"name": {
"type": "string"
},
"mobile": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
For the above model, following new methods will be added.
Contact.findByName
Contact.findByMobile
Contact.findByEmail
Contact.findOneByName
Contact.findOneByMobile
Contact.findOneByEmail
Please note that since findById
method already exists, it won't be overwritten. In that sense, if any of the dynamic generated method already exists in model, it won't be overwritten.
In case if either find
or findOne
methods are not required, they can be disabled with following config.
"bootScripts": {
"findByProperty": {
"find": false,
"findOne": false
}
}
Adds a user instance into context accessible at ctx.args.options.[KEY]
where [KEY]
defaults to currentUser
but can also be configured.
User model is also configurable.
"bootScripts": {
"currentUser": {
"key": "user",
"model": "CustomUser"
}
}
A general use case is where token needs to expire after certain days of last access. This requires refreshing token expiry after every access.
Refreshing the token in every request is also costly, thus this boot script takes care of refreshing token onceIn
specified time frame by given ttl
.
"bootScripts": {
"tokenRefresh": {
"onceIn": 86400 * 2,
"ttl": 86400 * 7
}
}
Above config will refresh token once in 2 days and will set ttl as 7 days.
Each boot script is by default enabled. Need be, it can be disabled by either of following ways.
Let's disable Custom Errors for example.
"bootScripts": {
"customErrors": false
}
OR
"bootScripts": {
"customErrors": {
"enabled": false
}
}
FAQs
Collection of useful boot scripts for Loopback framework
We found that loopback-boot-scripts 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.