Gathering detailed insights and metrics for node_express_acl
Gathering detailed insights and metrics for node_express_acl
Gathering detailed insights and metrics for node_express_acl
Gathering detailed insights and metrics for node_express_acl
An implementation of ACL for NodeJS with ExpressJS. It's pure JS so there are no dependencies.
npm install node_express_acl
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
11 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jun 01, 2020
Latest Version
1.0.1
Package Id
node_express_acl@1.0.1
Unpacked Size
9.42 kB
Size
3.85 kB
File Count
4
NPM Version
6.13.4
Node Version
12.16.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Node Express ACL is a light-weight pure JS implementation of an Access Control List currently with no dependencies on other Node module. It's simple design allows you to start using ACL with your ExpressJS/NodeJS back-end very quickly. This module functions particularly well for RESTful APIs.
This module does require that your have NodeJS and ExpressJS installed.
1npm install node_express_acl
This module does depend on authenticated users and that you are storing your authenticated user object in the request object. This is a pretty specific requirement, but something that can be more flexible in future releases. In your authentication middleware, but sure you store your user object in the request object, like so:
1req.user = authenticatedUserObject;
The only property that this module uses in the user object is role
. At minimum your user object should contain:
1{ 2 "role": "user" 3}
Of course you'll have more properties in there, but that's the only required property.
The first step is to initialize the roles that you're using for your application. You can make this call pretty much
anywhere in your application, but the best places would be in your main JS file (index.js
or server.js
for
example), where you perform application config or initialization (config.js
or init.js
for example) or in your
express.js
file.
The roles is just an array of the roles you are using. Later, when adding resources, the roles you reference will be validated against these roles. Set the roles like so:
1// Import the module at the beginning of your file 2const acl = require('node_express_acl'); 3 4 5// Later in the file (could be right after the import), set the roles 6acl.setRoles(['user', 'admin', 'super']);
For every route that you want to checked for authorization, you'll create one resource. You can add all of your ACL resources in one file, even in the same file where you set the roles (as described above). I separate my routes into separate files grouped by functionality (for example, all /auth endpoints are in one files and all /user endpoints are in one file). To keep the ACL resources in context of the routes, I prefer to add resources for related endpoints in the same file. I do this so I can see what role has access to which endpoints in the same file that defines the endpoints. This is up to you though.
Resources start by defining what endpoint you'd like authenticated. Then specify the roles and the HTTP methods allowed for those roles. Here's how you add resources:
1try { 2 acl.addResource('/users',[ 3 {'role': 'super', 'methods': ['GET', 'POST']} 4 ]); 5 acl.addResource('/users/:param',[ 6 {'role': 'super', 'methods': ['GET', 'PATCH', 'DELETE']}, 7 {'role': 'admin', 'methods': ['GET', 'PATCH']}, 8 {'role': 'user', 'methods': ['GET', 'PATCH']} 9 ]); 10} catch (err) { 11 console.log('Error adding ACL resource: ' + err); 12}
First, the addResource
function validates the roles (as set by setRoles
) and the HTTP methods (must be one of:
GET
, POST
, PUT
, PATCH
, DELETE
). This is why you need to put these calls in a try/catch block. If the
validation fails, it just means that the endpoint authentication will always fail.
The addResource
function expects 2 parameters:
An endpoint can authorize multiple roles, and each role can have permission to use the configured HTTP methods. The code above demonstrates the format of the JSON permissions parameter.
The last step is to add in the ACL authorization to the routes that you'd like to use your configured ACL resources. Like so:
1 app.route('/users') 2 .get(acl.authorize, controller.getAll) 3 .post(acl.authorize, controller.insert); 4 app.route('/users/:userId') 5 .get(acl.authorize, controller.getOne) 6 .patch(acl.authorize, controller.patch) 7 .delete(acl.authorize, controller.remove);
Be sure to import the node_express_acl
module in your route file. Then add in the ACL authorization call as the first
parameter to your routes (the way PassportJS does it).
That pretty much does the trick. This is currently used in the node-restful-api-skeleton project, so please take a look at the code in that project to see this module in action.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
Reason
Found 0/11 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More