GitHub - nlf/blankie: a hapi CSP plugin (original) (raw)

blankie

A CSP plugin for hapi.

Usage

This plugin depends on scooter to function.

To use it:

'use strict';

const Hapi = require('@hapi/hapi'); const Blankie = require('blankie'); const Scooter = require('@hapi/scooter');

const internals = {};

const server = Hapi.server();

internals.init = async () => {

await server.register([Scooter, {
    plugin: Blankie,
    options: {} // specify options here
}]);

await server.start();

};

internals.init().catch((err) => {

throw err;

});

Options may also be set on a per-route basis:

'use strict';

const Hapi = require('@hapi/hapi'); const Blankie = require('blankie'); const Scooter = require('@hapi/scooter');

const server = Hapi.server();

server.route({ method: 'GET', path: '/something', config: { handler: (request, h) => {

        return 'these settings are changed';
    },
    plugins: {
        blankie: {
            scriptSrc: 'self'
        }
    }
}

});

Note that this setting will NOT be merged with your server-wide settings.

You may also set config.plugins.blankie equal to false on a route to disable CSP headers completely for that route.

Options