Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
express-dynacl
Advanced tools
Readme
express-dynacl is a simple ExpressJS dynamic access control list middleware, that allows to grant access to queries based on request details.
roles.js:
module.exports = {
"guest": {
can: {
"posts:list": true,
"posts:edit": false
}
},
"user": {
can: {
"posts:create": true,
"posts:edit": (req,params) => Post.findOne({_id:params.post.id}).then(post => post.owner === req.user.id)
},
inherits: ["guest"]
},
"moderator":{
can: {
"posts:edit": true
},
inherits: ["user"]
},
"admin": {
admin: true
}
}
config.js:
var acl = require("express-dynacl");
var Post = require("./models/post");
var roles = require("./roles.js");
var options = {
roles: roles,
userRoles: req => req.user ? req.user.roles : [], // get user roles
// set some of the roles as default - each request will expect that user has these roles (default is none)
defaultRole: "guest",
logString: (event) => `DynACL ${event.permission ? "OK" : "XX"} (action: ${event.action}${event.role ? ", role: " + event.role : ""}${Object.keys(event.params) > 0 ? ", params: " + JSON.stringify(event.params) : ""})`,
logConsole: true, // enable logging to console (default is false)
authorized: (req,res,next) => next(), // middleware to use when authorized (default is send to next middleware)
unauthorized: (req,res,next) => res.sendStatus(401) // middleware to use when unauthorized (default is to respond with 401
}
Use as middleware:
var express = require('express');
var app = express();
var acl = require("express-dynacl");
var aclConfig = require("./config.js");
acl.config(aclConfig);
app.get("/posts", acl("posts:list"), (req,res) => {
// list posts
});
app.post("/posts", acl("posts:create"), (req,res) => {
// create post
});
app.put("/posts/1", acl("posts:edit"), (req,res) => {
// edit post
});
Use inside request:
var express = require('express');
var app = express();
var acl = require("express-dynacl");
app.put("/posts/:id", (req,res) => {
if(acl.can("posts:edit", req, {post: {id: req.params.id}})) {
// edit post
}
});
node node_modules/express-dynacl inspect roles.js
Running this will show a tree of actions split by colon with colored names of roles
FAQs
Express dynamic access control list, that allows to grant access to queries based on request details
The npm package express-dynacl receives a total of 5 weekly downloads. As such, express-dynacl popularity was classified as not popular.
We found that express-dynacl 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.