
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
hapi-field-auth
Advanced tools
Hapi server plugin for field-level authorization.
Tested with
npm install hapi-field-auth
This plugin provides field-level authorization (not authentication)
for Hapi routes -- particularly useful for PATCH routes.
If the request payload has fields with special constraints
in respect to the scope
of the authenticated user,
this plugin allows restricting access on field-level
and adding field validation depending on the scope
.
A prerequisite is authentication.
Use any authentication plugin, e.g., hapi-auth-basic
or hapi-auth-bearer-token
.
The authentication plugin must properly set request.auth.credentials.scope
with the authenticated user's scope for this plugin to work.
Dynamic scopes referring to the request object (query, params, payload, and credentials)
are supported, e.g., user-{params.id}
. Prefix characters !
and +
are not (yet) supported.
Register the plugin with Hapi server like this:
const Hapi = require('@hapi/hapi');
const hapiAuthBasic = require('@hapi/basic');
const hapiFieldAuth = require('hapi-field-auth');
const server = new Hapi.Server({
port: 3000,
});
const provision = async () => {
await server.register([hapiAuthBasic, hapiFieldAuth]);
// ...
await server.start();
};
provision();
Your route configuration may look like this:
server.route({
method: 'PATCH',
path: '/example',
options: {
auth: {
access: { // route-level auth -> HTTP 401/403
scope: ['write', 'write.extended'], // multiple scopes on route-level
},
},
validate: {
payload: ExampleSchema, // Joi schema validation -> HTTP 400
},
plugins: {
'hapi-field-auth': [{ // add field-level authorization -> HTTP 403
fields: ['myProtectedField'], // request payload properties
scope: ['write.extended'], // restricted scopes on field-level
}, {
fields: ['activeUntil', 'validUntil'],
scope: ['write.extended'], // restricted scopes on field-level...
validate: Joi.date().min('now').allow(null), // ...OR additional Joi schema -> HTTP 400
}],
},
},
handler: function (request, h) {
// ...
}
});
FAQs
Hapi plug-in for field-level authorization
The npm package hapi-field-auth receives a total of 13 weekly downloads. As such, hapi-field-auth popularity was classified as not popular.
We found that hapi-field-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
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.