
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
egg-userrole
Advanced tools
Provide dynamic roles based authorisation. Use koa-roles.
$ npm i egg-userrole --save
// {app_root}/config/plugin.js
exports.userrole = {
package: 'egg-userrole',
};
Recommend to use along with custom
userservice
plugin (which providectx.user
).see
egg-userservice
for more info.
Roles
build-in failureHandler
:
function failureHandler(ctx, action) {
const message = 'Forbidden, required role: ' + action;
if (ctx.acceptJSON) {
ctx.body = {
message: message,
stat: 'deny',
};
} else {
ctx.status = 403;
ctx.body = message;
}
};
Build-in user
role define:
app.role.use('user', ctx => !!ctx.user);
failureHandler
Define app.role.failureHandler(action)
method in config/role.js
app/extend/context.js
// {app_root}/config/role.js or {framework_root}/config/role.js
module.exports = app => {
app.role.failureHandler = function(ctx, action) {
if (ctx.acceptJSON) {
ctx.body = { target: loginURL, stat: 'deny' };
} else {
ctx.realStatus = 200;
ctx.redirect(loginURL);
}
};
}
// {app_root}/config/role.js or {framework_root}/config/role.js
module.exports = function(app) {
app.role.use('admin', ctx => {
return ctx.user && ctx.user.isAdmin;
});
app.role.use('can write', async ctx => {
const post = await ctx.service.post.fetch(ctx.request.body.id);
return ctx.user.name === post.author;
});
};
Please open an issue here.
FAQs
user role plugin for egg
The npm package egg-userrole receives a total of 129 weekly downloads. As such, egg-userrole popularity was classified as not popular.
We found that egg-userrole demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.