
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
hapi-auth-header
Advanced tools
Robust Authorization Header Auth Scheme for Hapi, with custom error reporting schema.
hapi Authorization header authentication scheme
Version 3.x of this plugin is compatible with Hapi 17 and higher only.
For Hapi 16, please continue to use version 2.x of this plugin.
Special thanks to @johnbrett for hapi-auth-bearer-token plugin, which this plugin used as scaffolding.
You might find that the hapi-auth-bearer-token plugin is all you need, which also allows for Bearer supplied as a query param (this module does not). This plugin exists to handle the whole Authorization header, which allows comma delimited Authorization sources. This is useful if you need to validate more than one Authorization header field. For example, the API that this plugin was originally built for was gated by an API management proxy, which forwards traffic along with an "FD" Authorization header, added along with the "Bearer" header like so: Authorization: FD AF6C74D1-BBB2-4171-8EE3-7BE9356EB018, Bearer 12345678
This plugin is identical to hapi-auth-bearer-token plugin except that it will return tokens as an object back to your callback rather than token as the Bearer field value (e.g. Authorization: FD AF6C74D1-BBB2-4171-8EE3-7BE9356EB018, Bearer 12345678 would result in your validate function being called with tokens set to
{
Bearer: 12345678,
FD: AF6C74D1-BBB2-4171-8EE3-7BE9356EB018
}
Authentication requires validating tokens passed by Authentication header. You can customize any arbitrary number of names for the Authorization header fields that you want to validate.
Bearer authentication requires validating a token passed in by either the bearer authorization header, or by an access_token query parameter. The 'auth-header' scheme takes the following options:
validateFunc - (required) An async validation function with the signature function(tokens) where:
tokens - an object containing each of the Authorization header keys.isValid - true if both the username was found and the password matched, otherwise false.credentials - a credentials object passed back to the application in request.auth.credentials. Typically, credentials are only
included when isValid is true, but there are cases when the application needs to know who tried to authenticate even when it fails
(e.g. with authentication mode 'try').options - (optional) - there are currently no configuration options :)const Hapi = require('hapi');
const defaultHandler = (request, h) => {
return h.response('success');
};
const server = new Hapi.Server({
port: 3117,
host: 'localhost'
});
server.register(require('hapi-auth-header'), async (err) => {
server.auth.strategy('header', 'auth-header', {
validate: function( tokens ) {
// Use a real strategy here,
// e.g. send the token to an oauth validation API
if(tokens.Bearer === "1234" && tokens.oauth === "4321" ){
return [true, { token: tokens.bearer }]
} else {
return [false, { token: tokens.bearer }]
}
}
});
server.route({ method: 'GET', path: '/', handler: defaultHandler, options: { auth: 'header' } });
await server.start();
console.log('Server started at: ' + server.info);
});
FAQs
Robust Authorization Header Auth Scheme for Hapi, with custom error reporting schema.
We found that hapi-auth-header 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
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.