Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
rest-crud-generator
Advanced tools
Bearer
authentication to the individual routesconst Api = require('rest-crud-generator')
Bookshelf
models to the generate method to create the API calls, with: Api.generate(User)
Adding Authentication:
To enable authentication and change the allowedRole array, run: Api.addBearerAuthentication(validateFunction)
, the validateFunction looks like this:
function (token, callback) {
// correct authentication
return callback(null, true, {});
// error authenticating
return callback(null, false);
}
generates the CRUD routes for the given model
{
routes: {
findOne: {
allowedRoles: [],
isEnabled: true
},
findAll: {
allowedRoles: [],
isEnabled: true
},
create: {
allowedRoles: [],
isEnabled: true
},
delete: {
allowedRoles: [],
isEnabled: true
},
update: {
allowedRoles: [],
isEnabled: true
}
}
}
Adds the bearer authentication to the server authentication. This requires the route to have a Bearer: <token>
header that specifies if the user is allowed access to the route.
The validateFunction
specifies if this given <token>
is correct and access is allowed (boolean). You will want to check this against the UserSession table to see if the token matches an entry.
An example of a fully fledged authentication function:
exports.validateFunction = function (token, callback) {
UserSessionModel
.where({ token: token })
.fetch()
.then(function (userSession) {
if (!userSession) {
return Promise.reject(Boom.badRequest('INVALID_TOKEN'));
}
return UserModel.where({ id: userSession.get('user_id') })
.fetch();
})
.then(function (user) {
if (!user) {
return Promise.reject(Boom.badRequest('INVALID_TOKEN'));
}
var userObj = user;
userObj.scope = [ user.get('scope') ];
return callback(null, true, userObj);
})
.catch(function (err) {
return callback(err);
});
};
Routes are generated on the plural name of the base model separated by _ on the capital letters.
Example: User becomes /user Example: BaseUnit becomes /base_units
CarEngine
, CarModel
, CarBody
, ... that we combine in the Car Facade
which has a method: `assembleCar``FAQs
REST API Generator for Bookshelf.js
We found that rest-crud-generator 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.