Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS
News: still worry about how to write the correct node-Casbin policy? Casbin online editor
is coming to help! Try it at: http://casbin.org/en/editor/
node-Casbin is a powerful and efficient open-source access control library for Node.JS projects. It provides support for enforcing authorization based on various access control models.
Casbin | jCasbin | node-Casbin | PHP-Casbin |
production-ready | production-ready | production-ready | production-ready |
PyCasbin | Casbin.NET | Casbin4D | Casbin-RS |
production-ready | production-ready | experimental | WIP |
npm install casbin --save
Initialize a new node-Casbin enforcer with a model file and a policy file:
import casbin from 'casbin';
const enforcer = await casbin.newEnforcer('path/to/model.conf', 'path/to/policy.csv');
Note: you can also initialize an enforcer with policy in DB instead of file, see Persistence section for details.
Add an enforcement hook into your code right before the access happens:
const sub = 'alice'; // the user that wants to access a resource.
const obj = 'data1'; // the resource that is going to be accessed.
const act = 'read'; // the operation that the user performs on the resource.
const res = await enforcer.enforce(sub, obj, act);
if (res) {
// permit alice to read data1
} else {
// deny the request, show an error
}
Besides the static policy file, node-Casbin also provides API for permission management at run-time. For example, You can get all the roles assigned to a user as below:
const roles = enforcer.getRolesForUser('alice');
See Policy management APIs for more usage.
Please refer to the src/test package for more usage.
Casbin provides two sets of APIs to manage permissions:
We also provide a web-based UI for model management and policy management:
https://casbin.org/docs/en/adapters
https://casbin.org/docs/en/overview
This project exists thanks to all the people who contribute.
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
This project is licensed under the Apache 2.0 license.
If you have any issues or feature requests, please contact us. PR is welcomed.
FAQs
An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS
We found that casbin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.