Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
hapi-inferred-scopes
Advanced tools
Hapi out-the-box scopes are powerful, but what if we wanted to manage scopes like resources which have sub-resources and infer whether a request is permitted?
hapi-inferred-scopes
allows us to mark routes with finely grained scopes, however still permit access for credentials that infer parent scopes.
npm install --save hapi-inferred-scopes
// the following option values are the defaults
const options = {
// how scopes / sub-scopes are delimited (e.g. user:account)
scopeDelimiter: ':',
// where we can find the auth credential's scope
scopeAccessor: request => request.auth.credentials.scope
};
await server.register({
plugin: require('hapi-inferred-scopes'),
options
});
server.route({
method: 'GET',
path: '/user/email',
options: {
auth: 'session',
plugins: {
inferredScope: ['user:email'] // make this as granular as possible
},
handler: (request, h) =>
h.response(request.auth.artifacts.scopeContext).code(200)
}
});
Say within our app we identify the following scope groups:
user
user:account
We can now guard a route with the most specific scope we'd like a request auth credentials to have.
For example, a route which accesses a user's account we can guard with user:account
.
An auth credential that has scope user:account
is allowed to access this route, along with any credential that has the parent scope user
- this is inferred.
Like hapi scopes, we can still make scopes required +
or forbidden !
- however, we can take into consideration the inferring parent mechanism.
If we want to forbid a credential with scope user:account
from accessing a particular route, we simply specify: !user:account
on the route.
A credential that has scope user
however, is still able to access the route.
Scope segments can also be dynamic expressions that refer to request data (again, like hapi), regular expressions or wild card operators. At this time, dynamic expressions, regular expressions and wild card operators cannot be mixed and matched - they are exclusive.
For dynamic expressions, surround the expression in {...}
like so:
{params.username
user-{params.username}
user:{params.accountType}
(child scope is a dynamic expression)For regular expressions, surround the expression in /.../
like so:
/.*/
/user-.*/
user:/.*/
(child scope is a regular expression)A wild card operator: match all *
is supported.
This operator will match any scope or subsequent sub-scopes, including absent ones. For example, user:*
will match:
user
user:account
user:account:email
etc.In addition, a scopeContext
is created and accessible on request.auth.artifacts.scopeContext
. This is an object representing the hierarchy of grouped scopes.
scopeContext
can be inspected to make any further decisions regarding scopes during a request's life-cycle.
For example a credential with scopes: ['user:account:read', 'user:profile', 'admin']
will have the following scopeContext
:
{
user: {
account: {
read: {}
},
profile: {}
},
admin: {}
}
Note:
['user', 'user:account']
will be reduced to ['user']
(as the account
sub-scope is inferred).inferredScope: []
.FAQs
infer route access from grouped scopes
We found that hapi-inferred-scopes 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.
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.