Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
express-reaccess
Advanced tools
Express middleware to check user access based on the ressources URIs and HTTP methods.
var reaccess = require('express-reaccess');
app.use(reaccess({
rightsProp: 'user.rights',
userProp: 'user'
}));
Assumming a middleware placed before the above example and adding a property like this on the request object for a given authenticated user:
req.user = {
id: 1,
login: 'nfroidure',
organization: {
id: 1,
name: 'simplifield'
},
rights: [{
path: '/users/:login',
methods: reaccess.METHODS ^ reaccess.DELETE
},{
path: '/organisations/:organization.name',
methods: reaccess.OPTIONS | reaccess.HEAD | reaccess.GET
},{
path: 'public/(.*)',
methods: reaccess.OPTIONS | reaccess.HEAD | reaccess.GET
}]
};
Then, the user will be able to access the following URI/method couples:
Warning: Since this middleware is based on RegExp, you have to be aware of RegExp special chars. By example, the following rules:
req.user.rights = [{
path: '/blog/posts/([0-9]+)/?page=([0-9]+)',
methods: reaccess.OPTIONS | reaccess.HEAD | reaccess.GET
}]
Will allow access to 'blog/posts/1page=1' wich is probably not what you want. So, do not forget to escape special chars:
req.user.rights = [{
path: '/blog/posts/([0-9]+)/\\?page=([0-9]+)',
methods: reaccess.OPTIONS | reaccess.HEAD | reaccess.GET
}]
The best is to unit test your access rules.
Type: Object
The options of the reaccess middleware.
Type: String
Default: 'user.rights'
The property in wich the user rights will be read. This property must be filled on the request object by any other middleware.
This property must contain an Array
of object of this kind :
req.user.rights = [{
path: '/organizations/:orgId/users.json'
methods: reaccess.GET | reaccess.POST
}];
Type: String
The property in wich any templated value found in the path must be searched for.
By example, if the user rights are the following :
req.user.rights = [{
path: '/organizations/:org.id/users.json'
methods: reaccess.GET | reaccess.POST
}];
He will be able to access this URI /organizations/1/users.json if a previously
set middleware have set the req.user.org.id
to 1
and options.userProp
to
'user'
.
Type: Error
constructor
Default: Error
Allows to use your own Error contructor for reaccess access errors.
Type: String
Default: Unauthorized access!
Allows to define your own error message. Note this middleware will not throw 401 responses for you. This is your responsibility to do so in your own error handler middleware. Defining a custom access error message could help detect when to answer with a 401 status code.
Reaccess use bitwise operators to match methods. The reaccess function provides static constants to help you make cleaner code.
Type: Number
Value: 1
Type: Number
Value: 2
Type: Number
Value: 4
Type: Number
Value: 8
Type: Number
Value: 16
Type: Number
Value: 32
Type: Number
Value: 63
FAQs
Express/Connect middleware to manage API access on a RegExp basis
The npm package express-reaccess receives a total of 73 weekly downloads. As such, express-reaccess popularity was classified as not popular.
We found that express-reaccess demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.