csp-header-middleware

Middleware for express app for adding Content-Security-Policy header


Keywords
csp, content-security-policy, xss, sanitize, filter, html, injection, request, middleware, express
License
MIT
Install
npm install csp-header-middleware@1.0.0

Documentation

csp-header-middleware

Build Status Coverage Status

csp-header-middleware is a middleware to add CSP headers to response to prevent XSS attacks.

Installation

npm install csp-header-middleware

How to use ?

var express = require('express')
var bodyParser = require('body-parser')
//NOTE: Don't forget to import `.cspHeaders` from lib
var cspHeaders = require('csp-header-middleware').cspHeaders;

var app = express()

app.use(bodyParser.json())

// this should comes before any routes
app.use(cspHeaders())

app.post('/your-route', (req, res) => {

   // response will be added with csp header

})

Testing & Contributing

npm install
npm test

License

MIT