
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
rest-access
Advanced tools
npm i -S rest-access
const express = require('express')
const app = express()
const jwt = require('express-jwt')
const access = require('rest-access')
access([
['*', '/api/*', 'api:rookie', true],
[['POST', 'PUT', 'DELETE'], '/api/*', 'api:write,admin:*'],
[['POST', 'PUT', 'DELETE'], '/api/secret/*', 'normal-admin'],
['GET', '/api/*', 'api:read'],
[['GET', 'POST'], '/*', '*']
])
app.use(jwt({ secret: 'shared_secret' })) // authenticate with jwt
app.use((req, res, next) => {
// map req.user.scope (added by express-jwt) to req.permission (used by rest-access)
req.permission = req.user.scope
next()
})
app.use(access.middleware()) // restrict access according to definition above
// endpoints
let hello = 'world'
app.get('/api/hello', (req, res) => res.send(hello))
app.post('/api/hello', (req, res) => {
hello = req.body
res.send(201)
})
app.get('/hello', (req, res) => res.send('welcome to the unrestricted area'))
This function lets you define the access rules all at once:
access([
[['POST', 'PUT', 'DELETE'], '/*/glint/role/*', 'manage'],
[['POST', 'PUT', 'DELETE'], '/*/glint/config/*', 'manage'],
[['GET'], '/signup/*', 'manage'],
['*', '/signin/*', 'manage'],
['*', '/account/password', 'manage'],
['*', '/account/delete', 'manage'],
['*', '/*', 'view', true],
['*', '/upload/*', 'edit'],
['GET', '/translate/*', 'edit,manage'],
['GET', '/filemanager/*', 'edit,manage'],
[['POST', 'PUT', 'DELETE'], '/filemanager/*', 'edit,manage'],
['GET', '/ajax/*', '*'],
['POST,DELETE,PUT', '/ajax/*', 'edit,insert,delete'],
['*', '/admin/*', 'manage'],
[['GET', 'POST'], '/*', '*']
])
Use This method if you want to define a single access rules a specific place. examples:
access(['GET', 'POST'], '/*/glint/role/* ', 'admin:*')
access('POST', '/*/glint/*', 'edit:glint')
The fourth argument is optional. If the fourth argument is "truthy" (boolean:true or string), it means that this role is blocked (instead of allowed) for the given methods and path.
Therefore in the following example, the Role read:glint
is blocked to POST
the given path.
access('POST', '/*/glint/*', 'read:glint', true)
app.midleware middleware function
example usage: looks for user permission under req.permission
app.use(access.middleware({ permissionProperty: 'permission' }))
app.restrict restrict single route
example usage: looks for user permission under req.permission
app.get('/my/home', access.restrict('api:*'), (req, res) => res.send('restricted api access'))
access.middleware()
adds req.userCan
function to the express/connect Request Object.
Example call: req.userCan('admin:*')
npm test
MIT
extracted from: https://github.com/glintcms/glintcms-starter-glintcms/blob/master/local_modules/page-auth-access/access.js
FAQs
role/scope based REST access control
The npm package rest-access receives a total of 1 weekly downloads. As such, rest-access popularity was classified as not popular.
We found that rest-access demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.