HTTP Public Key Pinning (HPKP) middleware
Clone or download
Latest commit 1c3bae0 Aug 1, 2018

HTTP Public Key Pinning (HPKP) middleware

Build Status

Looking for a changelog?

Adds Public Key Pinning headers to Express/Connect applications. To learn more about HPKP, check out the spec, the article on MDN, and this tutorial.

Be very careful when deploying this—you can easily misuse this header and cause problems. Chrome intends to drop support for HPKP citing risks of misuse.


const express = require('express')
const hpkp = require('hpkp')

const app = express()

const ninetyDaysInSeconds = 7776000
  maxAge: ninetyDaysInSeconds,
  sha256s: ['AbCdEf123=', 'ZyXwVu456='],
  includeSubDomains: true,         // optional
  reportUri: '', // optional
  reportOnly: false,               // optional

  // Set the header based on a condition.
  // This is optional.
  setIf(req, res) {

Setting reportOnly to true will change the header from Public-Key-Pins to Public-Key-Pins-Report-Only.

Don't let these get out of sync with your certs! It's also recommended to test your HPKP deployment in reportOnly mode, or alternatively, to use a very short maxAge until you're confident your deployment is correct.